Skip to content

Commit

Permalink
Merge pull request #1134 from Eykam/main
Browse files Browse the repository at this point in the history
replaced docs
  • Loading branch information
Eykam committed Mar 15, 2024
2 parents 2412471 + 7f59a23 commit 08ba7b6
Show file tree
Hide file tree
Showing 3,363 changed files with 162,556 additions and 67,373 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
77 changes: 77 additions & 0 deletions (docs)/ar/docs/additional/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
export const metadata = {
sidebar_position: 3000,
title: "🛸 Additional Resources",
};

# 🛸 Additional Resources

## Interactive Tutorials

- [agents.blue](https://www.agents.blue/) - A free, guided tutorial on prompt engineering.

## Resources

- [Article on leaking Notion's prompts](https://lspace.swyx.io/p/reverse-prompt-eng)
- [A great article on applications](https://huyenchip.com/2023/04/11/llm-engineering.html)
<br />
- [A fantastic PE intro video](https://youtube.com/watch?v=dOxUroR57xs&feature=shares)
<br />
- [A very nice, short prompt engineering guide](https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api)
<br />
- [A great prompt engineering intro](https://humanloop.com/blog/prompt-engineering-101)
<br />
- [A nice collection of prompt engineering papers](https://github.com/dair-ai/Prompt-Engineering-Guide)
<br />
- [Many more prompt engineering papers](https://github.com/thunlp/PromptPapers)
<br />
- [CMU class on prompt engineering](https://youtu.be/5ef83Wljm-M)
<br />
- [How Copilot works](https://thakkarparth007.github.io/copilot-explorer/posts/copilot-internals.html)
<br />
- [A Beginners Guide to Prompt Writing by Zapier](https://zapier.com/blog/gpt-3-prompt/)
<br />
- [Awesome A-Z Prompt-Engineering Resources list](https://github.com/promptslab/Awesome-Prompt-Engineering)
<br />
- [500 ChatGPT prompt templates](https://www.notion.so/500-ChatGPT-Prompt-Templates-d9541e901b2b4e8f800e819bdc0256da)
<br />
- [Prompt base](https://promptbase.com/)
<br />
- [Prompt vibes](https://www.promptvibes.com/)
<br />
- [Prompt Hero](https://prompthero.com/)
- [Midjourney community showcase with prompts](https://www.midjourney.com/showcase/recent/)
<br />
- [Data Science Prompts](https://github.com/travistangvh/ChatGPT-Data-Science-Prompts.git)
- [ALL styles and references for midjourney](https://github.com/willwulfken/MidJourney-Styles-and-Keywords-Reference)
<br />
- [Advanced Prompt Engineering](https://jamesbachini.com/advanced-midjourney-prompt-engineering/#midjourney-flags)
- [Ordinary people prompts](https://www.ordinarypeopleprompts.com/)

### GPT-3 Prompt Examples/Ideas

https://sharegpt.com<br />
https://www.learngpt.com<br />
https://chatgpt.getlaunchlist.com<br />
https://prompts.chat

## Facts

GPT-3 is _NOT_ deterministic: https://twitter.com/BorisMPower/status/1608522707372740609

## People to follow

I source significant content from these people.

[@chillzaza\_](https://mobile.twitter.com/chillzaza_) Prompt engineering, tools, toolbot<br />
[@mathemagic1an](https://mobile.twitter.com/mathemagic1an) Various prompting, PE,
GPT3 info<br />
[@goodside](https://twitter.com/goodside/status/1588247865503010816) Prompt Injection,
PE tooling<br />
[@hwchase17](https://twitter.com/hwchase17) Core dev of langchain<br />
[@omarsar0](https://twitter.com/omarsar0) DAIR AI lead

Also check accounts that I follow: https://twitter.com/learnprompting/following

## Even More

Check [open issues](https://github.com/trigaten/Learn_Prompting/issues) and [PRs](https://github.com/trigaten/Learn_Prompting/pulls) :)
1 change: 1 addition & 0 deletions (docs)/ar/docs/advanced_applications/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"label":"🚀 المستوى المتقدم","position":20,"link":{"type":"generated-index","description":"بعض التطبيقات القوية جدًا ، ولكنها أكثر تقدمًا للهندسة الذكاء الاصطناعي."}}
152 changes: 152 additions & 0 deletions (docs)/ar/docs/advanced_applications/mrkl/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
export const metadata = { sidebar_position: 2, title: "🟡 LLMs Using Tools" };

# 🟡 LLMs Using Tools

MRKL Systems(@karpas2022mrkl) (Modular Reasoning, Knowledge and Language, pronounced "miracle")
are a **neuro-symbolic architecture** that combine LLMs (neural computation) and external
tools like calculators (symbolic computation), to solve complex problems.

A MRKL system is composed of a set of modules (e.g. a calculator, weather API, database, etc.) and a router that decides how to 'route' incoming natural language queries to the appropriate module.

A simple example of a MRKL system is a LLM that can
use a calculator app. This is a single module system, where the LLM is the router.
When asked, `What is 100*100?`, the LLM can choose to
extract the numbers from the prompt, and then tell the MRKL System to use a calculator
app to compute the result. This might look like the following:

<pre>
<p>What is 100*100?</p>

<span className="bluegreen-highlight">CALCULATOR[100*100]</span>
</pre>

The MRKL system would see the word `CALCULATOR` and plug `100*100` into the calculator app.
This simple idea can easily be expanded to various symbolic computing tools.

Consider the following additional examples of applications:

- A chatbot that is able to respond to questions about a financial database by
extracting information to form a SQL query from a users' text.

<pre>
<p>What is the price of Apple stock right now?</p>

<span className="bluegreen-highlight">
The current price is DATABASE[SELECT price FROM stock WHERE company =
"Apple" AND time = "now"].
</span>
</pre>

- A chatbot that is able to respond to questions about the weather by extracting
information from the prompt and using a weather API to retrieve the information.

<pre>
<p>What is the weather like in New York?</p>

<span className="bluegreen-highlight">
The weather is WEATHER_API[New York].
</span>
</pre>

- Or even much more complex tasks that depend on multiple datasources, such as the
following:

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl_task.webp"
width={1600}
height={1331}
style={{ width: "500px", margin: "auto" }}
/>
</div>

<div style={{ textAlign: "center" }}>Example MRKL System (AI21)</div>

## An Example

I have reproduced an example MRKL System from the original paper, using Dust.tt,
linked [here](https://dust.tt/w/ddebdfcdde/a/98bdd65cb7).
The system reads a math problem (e.g. `What is 20 times 5^6?`), extracts the numbers and the operations,
and reformats them for a calculator app (e.g. `20*5^6`). It then sends the reformatted equation
to Google's calculator app, and returns the result. Note that the original paper performs prompt tuning on the router (the LLM), but I do not in this example. Let's walk through how this works:

First, I made a simple dataset in the Dust `Datasets` tab.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/dataset.webp"
width={2818}
height={820}
style={{ width: "750px", margin: "0" }}
/>
</div>

Then, I switched to the `Specification` tab and loaded the dataset using an `input` block.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/load_dataset.webp"
width={2790}
height={508}
style={{ width: "750px", margin: "0" }}
/>
</div>

Next, I created a `llm` block that extracts the numbers and operations. Notice how
in the prompt I told it we would be using Google's calculator. The model I use (GPT-3)
likely has some knowledge of Google's calculator from pretraining.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/model.webp"
width={2790}
height={960}
style={{ width: "750px", margin: "0" }}
/>
</div>

Then, I made a `code` block, which runs some simple javascript code to remove
spaces from the completion.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/extract.webp"
width={2790}
height={532}
style={{ width: "750px", margin: "0" }}
/>
</div>

Finally, I made a `search` block that sends the reformatted equation to Google's calculator.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/search.webp"
width={2790}
height={1310}
style={{ width: "750px", margin: "0" }}
/>
</div>

Below we can see the final results, which are all correct!

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/mrkl/final.webp"
width={2784}
height={494}
style={{ width: "750px", margin: "0" }}
/>
</div>

Feel free to clone and experiment with this playground [here](https://dust.tt/w/ddebdfcdde/a/98bdd65cb7).

## Notes

MRKL was developed by [AI21](https://www.ai21.com/) and originally used their
J-1 (Jurassic 1)(@lieberjurassic) LLM.

## More

See [this example](https://python.langchain.com/docs/modules/agents/how_to/mrkl) of a MRKL System
built with LangChain.
8 changes: 8 additions & 0 deletions (docs)/ar/docs/advanced_applications/overview/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const metadata = { sidebar_position: 1, title: "🟢 Introduction" };

# 🟢 Introduction

We have seen a number of prompting/prompt engineering methods thus far.
Now we will cover some advanced applications of prompting that can solve
complex reasoning tasks by performing searches for information via the internet,
or other external sources.
132 changes: 132 additions & 0 deletions (docs)/ar/docs/advanced_applications/pal/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
export const metadata = { sidebar_position: 4, title: "🟡 Code as Reasoning" };

# 🟡 Code as Reasoning

[Program-aided Language Models (PAL)](https://reasonwithpal.com)(@gao2022pal) are another example of a MRKL system.
When given a question, PALs are able to **write code** that solves this question. They send the
code to a programmatic runtime to get the result. PAL works in contrast to CoT; PAL's intermediate
reasoning is code, while CoT's is natural language.

<div style={{ textAlign: "center" }}>
<Image
src="/docs/assets/advanced/pal.webp"
width={1380}
height={1240}
style={{ width: "500px", margin: "auto" }}
/>
</div>

<div style={{ textAlign: "center" }}>PAL Example (Gao et al.)</div>

One important thing to note it that PAL actually interleaves natural language (NL) and code.
In the above image, in blue are natural language reasoning that PAL generates. Although it
is not shown in the image, PAL actually generates '\#' before each line of NL reasoning, so
that they are interpreted as comments by the programmatic runtime.

## Example

Let's look at an example of PAL solving a math question. I use a 3-shot prompt,
which is a simplified version of [this one](https://github.com/reasoning-machines/pal/blob/main/pal/prompt/math_prompts.py)(@gao2022pal).

I will use langchain, a Python package for chaining LLM functionality for this. First, a few installations are needed:

```python
!pip install langchain==0.0.26
!pip install openai
from langchain.llms import OpenAI
import os
os.environ["OPENAI_API_KEY"] = "sk-YOUR_KEY_HERE"
```

Then, we can create an instance of GPT-3 davinci-002 (an API call happens when we use this object)

```python
llm = OpenAI(model_name='text-davinci-002', temperature=0)
```

Here is the few shot prompt:

```python
MATH_PROMPT = '''
Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?
# solution in Python:
"""There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?"""
computers_initial = 9
computers_per_day = 5
num_days = 4 # 4 days between monday and thursday
computers_added = computers_per_day * num_days
computers_total = computers_initial + computers_added
result = computers_total
return result
Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?
# solution in Python:
"""Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?"""
toys_initial = 5
mom_toys = 2
dad_toys = 2
total_received = mom_toys + dad_toys
total_toys = toys_initial + total_received
result = total_toys
Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?
# solution in Python:
"""Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?"""
jason_lollipops_initial = 20
jason_lollipops_after = 12
denny_lollipops = jason_lollipops_initial - jason_lollipops_after
result = denny_lollipops
Q: {question}
# solution in Python:
'''
```

Now we can pass the combined prompt to GPT-3.

```python
llm_out = llm(MATH_PROMPT.format(question=question))
print(llm_out)
```

The output is:

<pre>
<span className="bluegreen-highlight">
Emma took a 60 minute plane ride to seattle. She then took a 2 hour train
ride to portland, and then a 30 minute bus ride to vancouver. How long did
it take her to get to vancouver?
<br />
<br />
plane_ride = 60
<br />
train_ride = 2 * 60 # 2 hours in minutes
<br />
bus_ride = 30
<br />
total_time = plane_ride + train_ride + bus_ride
<br />
result = total_time
</span>
</pre>

Finally, we can pass this code to a Python runtime to get the answer:

```python
exec(llm_out)
print(result)
```

The output is **210**, which is correct.

See the Jupyter notebook for this example [here](https://github.com/trigaten/Learn_Prompting/tree/main/docs/code_examples/PAL.ipynb).

## More

Also see [PAL's colab example](https://colab.research.google.com/drive/1u4_RsdI0E79PCMDdcPiJUzYhdnjoXeXc?usp=sharing#scrollTo=Ba0ycacK4i1V).
Loading

0 comments on commit 08ba7b6

Please sign in to comment.