Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed May 19, 2023
2 parents 231e5be + 146402e commit 7e4708d
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 49 deletions.
2 changes: 1 addition & 1 deletion concepts/watcher.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ The -w (watch) command line option can be passed to the chainlit run command to
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.

```bash
$ chainlit run app.py -w
chainlit run app.py -w
```
45 changes: 30 additions & 15 deletions examples/auto-gpt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
title: Auto GPT
---

Example inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html)
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.

<Note>
This example has extra dependencies, such as `openai`, `google-search-results`
and `faiss-cpu`. You might have to install them manually.
</Note>
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.

This example is inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html).

## Prerequisites

This example has extra dependencies. You can install them with:

```bash
pip install chainlit langchain openai google-search-results faiss-cpu
```

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/).

## Code

Expand All @@ -18,10 +27,20 @@ from langchain.tools.file_management.write import WriteFileTool
from langchain.tools.file_management.read import ReadFileTool
import os

from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain.embeddings import OpenAIEmbeddings
import faiss

from langchain.experimental import AutoGPT
from langchain.chat_models import ChatOpenAI
import chainlit as cl


os.environ["OPENAI_API_KEY"] = "OPENAI_API_KEY"
os.environ["SERPAPI_API_KEY"] = "SERPAPI_API_KEY"


# Tools the langchain agent will have access to
search = SerpAPIWrapper()
tools = [
Tool(
Expand All @@ -33,23 +52,16 @@ tools = [
ReadFileTool(),
]

from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain.embeddings import OpenAIEmbeddings

# Define your embedding model
embeddings_model = OpenAIEmbeddings()
# Initialize the vectorstore as empty
import faiss

embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)

from langchain.experimental import AutoGPT
from langchain.chat_models import ChatOpenAI
import chainlit as cl


# Create the agent with the chainlit decorator
@cl.langchain_factory
def agent():
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})
Expand All @@ -71,10 +83,13 @@ def run(agent, input):
cl.send_message(res)
```

Here you can see [langchain_run](/api-reference/langchain-run) and [langchain_factory](/api-reference/langchain-factory) were used.
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.

## Try it out

```bash
$ chainlit run autogpt.py
chainlit run autogpt.py
```

You can ask questions like `Create a weather report for san francisco`.
13 changes: 10 additions & 3 deletions examples/mrkl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ title: MRKL

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

<Note>This example has extra dependencies, such as `google-search-results` and `openai`. You might have to install them manually.</Note>
## Prerequisites

This example has extra dependencies. You can install them with:

```bash
pip install chainlit langchain openai google-search-results
```

## Code

```python mrkl.py
from langchain import OpenAI, LLMMathChain, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
Expand Down Expand Up @@ -45,9 +52,9 @@ def load():
## Try it out

```bash
$ chainlit run mrkl.py
chainlit run mrkl.py
```

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

![QA](/images/mrkl.png)
![QA](/images/mrkl.png)
20 changes: 12 additions & 8 deletions examples/openai-sql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
title: Text to SQL
---

## Text to SQL with OpenAI

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

<Note>This example has extra dependencies, such as `openai`. You might have to install them manually.</Note>
## Prerequisites

This example has extra dependencies. You can install them with:

```bash
pip install chainlit openai
```

### Imports
## Imports

```python app.py
import chainlit as cl
Expand All @@ -18,7 +22,7 @@ import os
openai.api_key = "YOUR_OPEN_AI_API_KEY"
```

### Define a prompt and LLM settings
## Define a prompt and LLM settings

````python app.py
prompt = """SQL tables (and columns):
Expand All @@ -40,7 +44,7 @@ settings = {
}
````

### Listen and Reply
## Listen and Reply

Here, we decorate the `main` function with the [@on_message](api-reference/on-message) decorator to tell Chainlit to run the `main` function each time a user sends a message.
Then, we send back the answer to the UI with the [send_message](api-reference/send-message) function.
Expand All @@ -64,10 +68,10 @@ def main(message: str):
)
```

### Try it out
## Try it out

```bash
$ chainlit run app.py -w
chainlit run app.py -w
```

You can ask questions like `Compute the number of customers who watched more than 50 minutes of video this month`.
Expand Down
25 changes: 18 additions & 7 deletions examples/qa.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
title: Document QA
---

Example inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/question_answering.html)
In this example, we're going to build an chatbot QA app. We'll learn how to:

<Note>
This example has extra dependencies, such as `chromadb`, `tiktoken` and
`openai`. You might have to install them manually.
</Note>
- Upload a document
- Create vector embeddings from a file
- Create a chatbot app with the ability to display sources used to generate an answer

This example is inspired from the [LangChain doc](https://python.langchain.com/en/latest/use_cases/question_answering.html)

## Prerequisites

This example has extra dependencies. You can install them with:

```bash
pip installchromadb tiktoken openai
```

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/).

<Note>
The state of the union file is available
Expand Down Expand Up @@ -135,15 +146,15 @@ def process_response(res):
````

We are making use of the [@langchain_factory](/api-reference/langchain/langchain-factory) decorator to tell Chainlit on how to get the LangChain agent.
Then, we use [@langchain_postprocess](/api-reference/langchain/langchain-postprocess) (which takes the raw response from the agent) as well as [send_text](/api-reference/send-text) to:
Then, we use [@langchain_postprocess](/api-reference/langchain/langchain-postprocess) (which takes the raw response from the agent) as well as the [Text Element](/api-reference/elements/text) to:

- Add the relevant sources to the final answer
- Send the sources to the UI

## Try it out

```bash
$ chainlit run qa.py
chainlit run qa.py
```

You can then upload any `.txt` file to the UI and ask questions about it.
Expand Down
8 changes: 4 additions & 4 deletions installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Chainlit requires `python>=3.8`.

Open a terminal and run:
```bash
$ pip install chainlit
pip install chainlit
```

To try if everything works correctly run:
Make sure everything runs smoothly:
```bash
$ chainlit hello
chainlit hello
```

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

<Card title="With PurePython" icon="link" href="/pure-python">
Learn on how to use Chainlit with any python code.
Learn on how to use Chainlit with any python code.
</Card>
2 changes: 1 addition & 1 deletion langchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def factory():
That's it. Run the following command to start the chatbot UI.

```bash
$ chainlit run app.py -w
chainlit run app.py -w
```

Congratulations, your first chainlit app is ready 🥳
Expand Down
11 changes: 8 additions & 3 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"url": "https://discord.gg/ZThrUxbAYw"
}
],
"topbarCtaButton": {
"type": "link",
"name": "Get Started",
"url": "https://github.com/Chainlit/chainlit"
},
"navigation": [
{
"group": "Get Started",
Expand All @@ -42,10 +47,10 @@
{
"group": "Examples",
"pages": [
"examples/auto-gpt",
"examples/openai-sql",
"examples/mrkl",
"examples/qa",
"examples/openai-sql"
"examples/auto-gpt",
"examples/qa"
]
},
{
Expand Down
14 changes: 8 additions & 6 deletions overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ Chainlit is an open-source Python package that focuses on making it incredibly e


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

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

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

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

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

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.
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.

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.
2 changes: 1 addition & 1 deletion pure-python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main(message: str):
That's it. Run the following command to start the chatbot UI.

```bash
$ chainlit run app.py -w
chainlit run app.py -w
```

Congratulations, your first chainlit app is ready 🥳
Expand Down

0 comments on commit 7e4708d

Please sign in to comment.