Skip to content

Commit 74e28ee

Browse files
Dan ConstantiniDan Constantini
authored andcommitted
Added explanations
1 parent cdbc32a commit 74e28ee

File tree

10 files changed

+70
-35
lines changed

10 files changed

+70
-35
lines changed

concepts/watcher.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ The -w (watch) command line option can be passed to the chainlit run command to
55
When this option is specified, the file watcher will be started and any changes to files will cause the server to reload the app, allowing faster iterations.
66

77
```bash
8-
$ chainlit run app.py -w
8+
chainlit run app.py -w
99
```

examples/auto-gpt.mdx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
title: Auto GPT
33
---
44

5-
Example inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html)
5+
Auto-GPT is an AI tool that uses OpenAI's GPT-4 or GPT-3.5 APIs to perform autonomous tasks. It is an "AI agent" that can be given a goal in natural language and will attempt to achieve it by breaking it into sub-tasks and using the internet and other tools in an automatic loop. Unlike interactive systems such as ChatGPT, which require manual commands for every task, Auto-GPT assigns itself new objectives to work on with the aim of reaching a greater goal, without a mandatory need for human input.
66

7-
<Note>This example has extra dependencies, such as `openai`, `google-search-results` and `faiss-cpu`. You might have to install them manually.</Note>
7+
This example is inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html).
8+
9+
<Note>This example has extra dependencies, such as `openai`, `google-search-results` and `faiss-cpu`.</Note>
10+
11+
```bash
12+
pip install chainlit langchain openai google-search-results faiss-cpu
13+
```
14+
15+
Then, you need to go to create an OpenAI key [here](https://platform.openai.com/account/api-keys) and get a SperpApi key [here](https://serpapi.com/).
816

917
## Code
1018
```python autogpt.py
@@ -14,10 +22,20 @@ from langchain.tools.file_management.write import WriteFileTool
1422
from langchain.tools.file_management.read import ReadFileTool
1523
import os
1624

25+
from langchain.vectorstores import FAISS
26+
from langchain.docstore import InMemoryDocstore
27+
from langchain.embeddings import OpenAIEmbeddings
28+
import faiss
29+
30+
from langchain.experimental import AutoGPT
31+
from langchain.chat_models import ChatOpenAI
32+
import chainlit as cl
33+
34+
1735
os.environ["OPENAI_API_KEY"] = "OPENAI_API_KEY"
1836
os.environ["SERPAPI_API_KEY"] = "SERPAPI_API_KEY"
1937

20-
38+
# Tools the langchain agent will have access to
2139
search = SerpAPIWrapper()
2240
tools = [
2341
Tool(
@@ -29,23 +47,16 @@ tools = [
2947
ReadFileTool(),
3048
]
3149

32-
from langchain.vectorstores import FAISS
33-
from langchain.docstore import InMemoryDocstore
34-
from langchain.embeddings import OpenAIEmbeddings
3550

3651
# Define your embedding model
3752
embeddings_model = OpenAIEmbeddings()
3853
# Initialize the vectorstore as empty
39-
import faiss
4054

4155
embedding_size = 1536
4256
index = faiss.IndexFlatL2(embedding_size)
4357

44-
from langchain.experimental import AutoGPT
45-
from langchain.chat_models import ChatOpenAI
46-
import chainlit as cl
47-
4858

59+
# Create the agent with the chainlit decorator
4960
@cl.langchain_factory
5061
def agent():
5162
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})
@@ -66,10 +77,14 @@ def run(agent, input):
6677
return agent.run([input])
6778
```
6879

80+
Here you can see [langchain_run](/api-reference/langchain-run) and [langchain_factory](/api-reference/langchain-factory) were used.
81+
Langchain agents usually take a string as input. The `AutoGPT` class takes in a list. These two helper functions allow to change the default behavior.
82+
83+
6984
## Try it out
7085

7186
```bash
72-
$ chainlit run autogpt.py
87+
chainlit run autogpt.py
7388
```
7489

7590
You can ask questions like `Create a weather report for san francisco`.

examples/mrkl.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ title: MRKL
44

55
Example inspired from the [LangChain doc](https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html)
66

7-
<Note>This example has extra dependencies, such as `google-search-results` and `openai`. You might have to install them manually.</Note>
7+
<Note>This example has extra dependencies, such as `google-search-results` and `openai`.</Note>
8+
9+
```bash
10+
pip install chainlit langchain openai google-search-results
11+
```
812

913
## Code
1014
```python mrkl.py
@@ -45,7 +49,7 @@ def load():
4549
## Try it out
4650

4751
```bash
48-
$ chainlit run mrkl.py
52+
chainlit run mrkl.py
4953
```
5054

5155
You can ask questions like `What is the Paris weather forecast for tomorrow? How does it compare to today's?`.

examples/openai-sql.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ title: Text to SQL
66

77
Let's build a simple agent that helps users to create SQL queries with natural language.
88

9-
<Note>This example has extra dependencies, such as `openai`. You might have to install them manually.</Note>
9+
<Note>This example has extra dependencies, such as `openai`.</Note>
10+
11+
```bash
12+
pip install chainlit openai
13+
```
1014

1115
### Imports
1216

@@ -67,7 +71,7 @@ def main(message: str):
6771
### Try it out
6872

6973
```bash
70-
$ chainlit run app.py -w
74+
chainlit run app.py -w
7175
```
7276

7377
You can ask questions like `Compute the number of customers who watched more than 50 minutes of video this month`.

examples/qa.mdx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
title: Document QA
33
---
44

5-
Example inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/question_answering.html)
5+
In this example, we're going to build an chatbot QA app. In this example, we'll learn how to:
6+
- Upload a document
7+
- Create vector embeddings from a file
8+
- Create a chatbot app with the ability to display sources used to generate an answer
69

7-
<Note>This example has extra dependencies, such as `chromadb`, `tiktoken` and `openai`. You might have to install them manually.</Note>
10+
This example is inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/question_answering.html)
11+
12+
<Note>This example has extra dependencies, such as `chromadb`, `tiktoken` and `openai`.</Note>
13+
```bash
14+
pip install chainlit langchain openai chromadb tiktoken
15+
```
16+
17+
Then, you need to go to create an OpenAI key [here](https://platform.openai.com/account/api-keys) and get a SperpApi key [here](https://serpapi.com/).
818

919
<Note>The state of the union file is available [here](https://github.com/hwchase17/langchain/blob/master/docs/modules/state_of_the_union.txt)</Note>
1020

@@ -129,7 +139,7 @@ Then, we use [@langchain_postprocess](/api-reference/langchain-postprocess) (whi
129139
## Try it out
130140

131141
```bash
132-
$ chainlit run qa.py
142+
chainlit run qa.py
133143
```
134144

135145
You can then upload any `.txt` file to the UI and ask questions about it.

installation.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Chainlit requires `python>=3.8`.
66

77
Open a terminal and run:
88
```bash
9-
$ pip install chainlit
9+
pip install chainlit
1010
```
1111

12-
To try if everything works correctly run:
12+
Make sure everything runs smoothly:
1313
```bash
14-
$ chainlit hello
14+
chainlit hello
1515
```
1616

1717
This should spawn the chainlit UI and ask for your name like so:
@@ -24,5 +24,5 @@ This should spawn the chainlit UI and ask for your name like so:
2424
</Card>
2525

2626
<Card title="With PurePython" icon="link" href="/pure-python">
27-
Learn on how to use Chainlit with any python code.
27+
Learn on how to use Chainlit with any python code.
2828
</Card>

langchain.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def factory():
2626
That's it. Run the following command to start the chatbot UI.
2727

2828
```bash
29-
$ chainlit run app.py -w
29+
chainlit run app.py -w
3030
```
3131

3232
Congratulations, your first chainlit app is ready 🥳

mint.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
{
4949
"group": "Examples",
5050
"pages": [
51-
"examples/auto-gpt",
51+
"examples/openai-sql",
5252
"examples/mrkl",
53-
"examples/qa",
54-
"examples/openai-sql"
53+
"examples/auto-gpt",
54+
"examples/qa"
5555
]
5656
},
5757
{

overview.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ Chainlit is an open-source Python package that focuses on making it incredibly e
66

77

88
## Advantages of Chainlit
9-
1. **Enhanced explainability:** Chainlit's user interface enables you to visualize intermediary steps, enabling you to understand the reasoning behind an answer.
9+
1. **Chatbot UI:** Create cool LLM-based chatbot apps directly from your python code!
1010

11-
2. **Debugging made easy:** Chainlit's prompt playground allows you to iterate on intermediate prompts, making it easier to identify and fix bugs.
11+
2. **Enhanced explainability:** Chainlit's user interface enables you to visualize intermediary steps, enabling you to understand the reasoning behind an answer.
1212

13-
3. **Plug and play integration with LangChain:** Turn your LangChain agent in a chatbot UI with one line of code.
13+
3. **Debugging made easy:** Chainlit's prompt playground allows you to iterate on intermediate prompts, making it easier to identify and fix bugs.
1414

15-
4. **Seamless file management:** The package includes a set of functions to ask and send files or documents.
15+
4. **Plug and play integration with LangChain:** Turn your LangChain agent in a chatbot UI with one line of code.
1616

17-
5. **Free deployment:** Chainlit offers free deployment, allowing you to quickly and easily share your AI applications with your team or the world.
17+
5. **Seamless file management:** The package includes a set of functions to ask and send files or documents.
1818

19-
6. **Improved team collaboration:** Chainlit's features, such as data persistence, human feedback, and prompt versioning, enable your team to work together more effectively and efficiently.
19+
6. **Deployment (coming soon):** Chainlit offers simple & free deployment, allowing you to quickly and easily share your AI applications with your team or the world.
20+
21+
7. **Improved team collaboration (coming soon):** Chainlit's features, such as data persistence, human feedback, and prompt versioning, enable your team to work together more effectively and efficiently.

pure-python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def main(message: str):
2121
That's it. Run the following command to start the chatbot UI.
2222

2323
```bash
24-
$ chainlit run app.py -w
24+
chainlit run app.py -w
2525
```
2626

2727
Congratulations, your first chainlit app is ready 🥳

0 commit comments

Comments
 (0)