Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions (docs)/fr/docs/advanced_applications/mrkl/page.mdx
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
export const metadata = { sidebar_position: 2, title: "🟡 LLMs Using Tools" };
export const metadata = { sidebar_position: 2, title: "🟡 Les LLMs utilisant des outils" };

# 🟡 LLMs Using Tools
# 🟡 Les LLMs utilisant des outils

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.
Les systèmes MRKL(@karpas2022mrkl) (Modular Reasoning, Knowledge and Language, prononcé "miracle")
sont une **architecture neuro-symbolique** qui combine les LLMs (calcul neuronal) et des outils
externes comme les calculatrices (calcul symbolique) pour résoudre des problèmes complexes.

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.
Un système MRKL est composé d'un ensemble de modules (par exemple, une calculatrice, une API météo, une base de données, etc.) et d'un routeur qui décide comment 'router' les requêtes en langage naturel vers le module approprié.

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:
Un exemple simple d'un système MRKL est un LLM qui peut
utiliser une application calculatrice. C'est un système à module unique, où le LLM est le routeur.
Lorsqu'on lui demande `Combien fait 100*100 ?`, le LLM peut choisir d'
extraire les nombres de la requête, puis dire au système MRKL d'utiliser une application
calculatrice pour calculer le résultat. Cela pourrait ressembler à ceci :

<pre>
<p>What is 100*100?</p>
<p>Combien fait 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.
Le système MRKL verrait le mot `CALCULATOR` et insérerait `100*100` dans l'application calculatrice.
Cette idée simple peut facilement être étendue à divers outils de calcul symbolique.

Consider the following additional examples of applications:
Voici d'autres exemples d'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.
- Un chatbot capable de répondre à des questions sur une base de données financière en
extrayant des informations pour former une requête SQL à partir du texte des utilisateurs.

<pre>
<p>What is the price of Apple stock right now?</p>
<p>Quel est le prix actuel de l'action Apple ?</p>

<span className="bluegreen-highlight">
The current price is DATABASE[SELECT price FROM stock WHERE company =
Le prix actuel est 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.
- Un chatbot capable de répondre à des questions sur la météo en extrayant
des informations du prompt et en utilisant une API météo pour récupérer l'information.

<pre>
<p>What is the weather like in New York?</p>
<p>Quel temps fait-il à Paris ?</p>

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

- Or even much more complex tasks that depend on multiple datasources, such as the
following:
- Ou même des tâches beaucoup plus complexes qui dépendent de plusieurs sources de données,
comme l'exemple suivant :

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -60,17 +60,17 @@ Consider the following additional examples of applications:
/>
</div>

<div style={{ textAlign: "center" }}>Example MRKL System (AI21)</div>
<div style={{ textAlign: "center" }}>Exemple de système MRKL (AI21)</div>

## An Example
## Un exemple

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:
J'ai reproduit un exemple de système MRKL tiré de l'article original, en utilisant Dust.tt,
accessible [ici](https://dust.tt/w/ddebdfcdde/a/98bdd65cb7).
Le système lit un problème mathématique (par exemple `Combien fait 20 fois 5^6 ?`), extrait les nombres et les opérations,
et les reformate pour une application calculatrice (par exemple `20*5^6`). Il envoie ensuite l'équation reformatée
à l'application calculatrice de Google et renvoie le résultat. Notez que l'article original effectue un ajustement du prompt sur le routeur (le LLM), ce que je ne fais pas dans cet exemple. Voyons comment cela fonctionne :

First, I made a simple dataset in the Dust `Datasets` tab.
Tout d'abord, j'ai créé un simple jeu de données dans l'onglet `Datasets` de Dust.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -81,7 +81,7 @@ First, I made a simple dataset in the Dust `Datasets` tab.
/>
</div>

Then, I switched to the `Specification` tab and loaded the dataset using an `input` block.
Ensuite, je suis passé à l'onglet `Specification` et j'ai chargé le jeu de données en utilisant un bloc `input`.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -92,9 +92,9 @@ Then, I switched to the `Specification` tab and loaded the dataset using an `inp
/>
</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.
Ensuite, j'ai créé un bloc `llm` qui extrait les nombres et les opérations. Remarquez comment
dans le prompt, j'ai indiqué que nous utiliserions la calculatrice Google. Le modèle que j'utilise (GPT-3)
a probablement une certaine connaissance de la calculatrice Google grâce à son pré-entraînement.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -105,8 +105,8 @@ likely has some knowledge of Google's calculator from pretraining.
/>
</div>

Then, I made a `code` block, which runs some simple javascript code to remove
spaces from the completion.
Puis, j'ai créé un bloc `code` qui exécute un simple code javascript pour supprimer
les espaces de la complétion.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -117,7 +117,7 @@ spaces from the completion.
/>
</div>

Finally, I made a `search` block that sends the reformatted equation to Google's calculator.
Enfin, j'ai créé un bloc `search` qui envoie l'équation reformatée à la calculatrice Google.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -128,7 +128,7 @@ Finally, I made a `search` block that sends the reformatted equation to Google's
/>
</div>

Below we can see the final results, which are all correct!
Ci-dessous, nous pouvons voir les résultats finaux, qui sont tous corrects !

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -139,14 +139,14 @@ Below we can see the final results, which are all correct!
/>
</div>

Feel free to clone and experiment with this playground [here](https://dust.tt/w/ddebdfcdde/a/98bdd65cb7).
N'hésitez pas à cloner et expérimenter avec ce playground [ici](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.
MRKL a été développé par [AI21](https://www.ai21.com/) et utilisait initialement leur
LLM J-1 (Jurassic 1)(@lieberjurassic).

## More
## Pour aller plus loin

See [this example](https://python.langchain.com/docs/modules/agents/how_to/mrkl) of a MRKL System
built with LangChain.
Consultez [cet exemple](https://python.langchain.com/docs/modules/agents/how_to/mrkl) d'un système MRKL
construit avec LangChain.
6 changes: 2 additions & 4 deletions (docs)/fr/docs/advanced_applications/overview/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ 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.
Nous avons vu jusqu'à présent plusieurs méthodes de prompting/ingénierie de prompts.
Nous allons maintenant aborder des applications avancées du prompting qui peuvent résoudre des tâches de raisonnement complexes en effectuant des recherches d'informations via internet ou d'autres sources externes.
81 changes: 41 additions & 40 deletions (docs)/fr/docs/advanced_applications/pal/page.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const metadata = { sidebar_position: 4, title: "🟡 Code as Reasoning" };
export const metadata = { sidebar_position: 4, title: "🟡 Le Code comme Raisonnement" };

# 🟡 Code as Reasoning
# 🟡 Le Code comme Raisonnement

[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.
Les [Program-aided Language Models (PAL)](https://reasonwithpal.com)(@gao2022pal) sont un autre exemple de système MRKL.
Lorsqu'une question leur est posée, les PAL sont capables d'**écrire du code** qui résout cette question. Ils envoient le
code à un environnement d'exécution programmatique pour obtenir le résultat. PAL fonctionne différemment de CoT ; le raisonnement intermédiaire de PAL
est du code, tandis que celui de CoT est en langage naturel.

<div style={{ textAlign: "center" }}>
<Image
Expand All @@ -16,55 +16,56 @@ reasoning is code, while CoT's is natural language.
/>
</div>

<div style={{ textAlign: "center" }}>PAL Example (Gao et al.)</div>
<div style={{ textAlign: "center" }}>Exemple PAL (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.
Un point important à noter est que PAL entrelace en réalité le langage naturel (NL) et le code.
Dans l'image ci-dessus, en bleu se trouve le raisonnement en langage naturel que PAL génère. Bien que
ce ne soit pas montré dans l'image, PAL génère en fait '\#' avant chaque ligne de raisonnement NL,
afin qu'elles soient interprétées comme des commentaires par l'environnement d'exécution.

## Example
## Exemple

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).
Examinons un exemple de PAL résolvant une question mathématique. J'utilise un prompt à 3 exemples,
qui est une version simplifiée de [celui-ci](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:
Je vais utiliser langchain, un package Python pour chaîner les fonctionnalités LLM.
Tout d'abord, quelques installations sont nécessaires :

```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"
os.environ["OPENAI_API_KEY"] = "sk-VOTRE_CLE_ICI"
```

Then, we can create an instance of GPT-3 davinci-002 (an API call happens when we use this object)
Ensuite, nous pouvons créer une instance de GPT-3 davinci-002 (un appel API se produit lorsque nous utilisons cet objet)

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

Here is the few shot prompt:
Voici le prompt à quelques exemples :

```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?
Q: Il y avait neuf ordinateurs dans la salle des serveurs. Cinq ordinateurs supplémentaires ont été installés chaque jour, du lundi au jeudi. Combien y a-t-il maintenant d'ordinateurs dans la salle des serveurs ?

# 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?"""
# solution en Python:
"""Il y avait neuf ordinateurs dans la salle des serveurs. Cinq ordinateurs supplémentaires ont été installés chaque jour, du lundi au jeudi. Combien y a-t-il maintenant d'ordinateurs dans la salle des serveurs ?"""
computers_initial = 9
computers_per_day = 5
num_days = 4 # 4 days between monday and thursday
num_days = 4 # 4 jours entre lundi et jeudi
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?
Q: Shawn a cinq jouets. Pour Noël, il a reçu deux jouets de sa mère et deux de son père. Combien de jouets a-t-il maintenant ?

# 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?"""
# solution en Python:
"""Shawn a cinq jouets. Pour Noël, il a reçu deux jouets de sa mère et deux de son père. Combien de jouets a-t-il maintenant ?"""
toys_initial = 5
mom_toys = 2
dad_toys = 2
Expand All @@ -73,40 +74,40 @@ 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?
Q: Jason avait 20 sucettes. Il en a donné quelques-unes à Denny. Maintenant Jason a 12 sucettes. Combien de sucettes Jason a-t-il données à 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?"""
# solution en Python:
"""Jason avait 20 sucettes. Il en a donné quelques-unes à Denny. Maintenant Jason a 12 sucettes. Combien de sucettes Jason a-t-il données à 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:
# solution en Python:
'''
```

Now we can pass the combined prompt to GPT-3.
Maintenant, nous pouvons passer le prompt combiné à GPT-3.

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

The output is:
La sortie est :

<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?
Emma a pris un vol de 60 minutes vers Seattle. Elle a ensuite pris un train
pendant 2 heures jusqu'à Portland, puis un bus pendant 30 minutes jusqu'à Vancouver.
Combien de temps lui a-t-il fallu pour arriver à Vancouver ?
<br />
<br />
plane_ride = 60
<br />
train_ride = 2 * 60 # 2 hours in minutes
train_ride = 2 * 60 # 2 heures en minutes
<br />
bus_ride = 30
<br />
Expand All @@ -116,17 +117,17 @@ The output is:
</span>
</pre>

Finally, we can pass this code to a Python runtime to get the answer:
Enfin, nous pouvons passer ce code à un environnement d'exécution Python pour obtenir la réponse :

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

The output is **210**, which is correct.
La sortie est **210**, ce qui est correct.

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

## More
## Plus d'informations

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