Examples
RAG Chatbot: Embedchain + Chainlit
Learn how to build a streaming RAG chatbot with Embedchain, OpenAI, Chainlit for chat UI, and Aporia Guardrails.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Learn how to build a streaming RAG chatbot with Embedchain, OpenAI, Chainlit for chat UI, and Aporia Guardrails.
pip3 install chainlit embedchain --upgrade
import chainlit as cl
from embedchain import App
import uuid
@cl.on_chat_start
async def chat_startup():
app = App.from_config(config={
"app": {
"config": {
"name": "my-chatbot",
"id": str(uuid.uuid4()),
"collect_metrics": False
}
},
"llm": {
"config": {
"model": "gpt-3.5-turbo-0125",
"stream": True,
"temperature": 0.0,
}
}
})
# Add documents to be used as knowledge base for the chatbot
app.add("my_knowledge.pdf", data_type='pdf_file')
cl.user_session.set("app", app)
@cl.on_message
async def on_new_message(message: cl.Message):
app = cl.user_session.get("app")
msg = cl.Message(content="")
for chunk in await cl.make_async(app.chat)(message.content):
await msg.stream_token(chunk)
await msg.send()
chainlit run <your script>.py
app = App.from_config(config={
"llm": {
"config": {
"base_url": "https://gr-prd.aporia.com/<PROJECT_ID>",
"model_kwargs": {
"default_headers": { "X-APORIA-API-KEY": "<YOUR_APORIA_API_KEY>" }
},
# ...
}
},
# ...
})
X5O!P%@AP[4\PZX54(P^)7CC)7}$AGT-STANDARD-GUARDRAILS-TEST-MSG!$H+H*