repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: '⛓️ Chainlit' |
| #3 | description: 'Integrate with Chainlit to create LLM chat apps' |
| #4 | --- |
| #5 | |
| #6 | In this example, we will learn how to use Chainlit and Embedchain together. |
| #7 | |
| #8 |  |
| #9 | |
| #10 | ## Setup |
| #11 | |
| #12 | First, install the required packages: |
| #13 | |
| #14 | ```bash |
| #15 | pip install embedchain chainlit |
| #16 | ``` |
| #17 | |
| #18 | ## Create a Chainlit app |
| #19 | |
| #20 | Create a new file called `app.py` and add the following code: |
| #21 | |
| #22 | ```python |
| #23 | import chainlit as cl |
| #24 | from embedchain import App |
| #25 | |
| #26 | import os |
| #27 | |
| #28 | os.environ["OPENAI_API_KEY"] = "sk-xxx" |
| #29 | |
| #30 | @cl.on_chat_start |
| #31 | async def on_chat_start(): |
| #32 | app = App.from_config(config={ |
| #33 | 'app': { |
| #34 | 'config': { |
| #35 | 'name': 'chainlit-app' |
| #36 | } |
| #37 | }, |
| #38 | 'llm': { |
| #39 | 'config': { |
| #40 | 'stream': True, |
| #41 | } |
| #42 | } |
| #43 | }) |
| #44 | # import your data here |
| #45 | app.add("https://www.forbes.com/profile/elon-musk/") |
| #46 | app.collect_metrics = False |
| #47 | cl.user_session.set("app", app) |
| #48 | |
| #49 | |
| #50 | @cl.on_message |
| #51 | async def on_message(message: cl.Message): |
| #52 | app = cl.user_session.get("app") |
| #53 | msg = cl.Message(content="") |
| #54 | for chunk in await cl.make_async(app.chat)(message.content): |
| #55 | await msg.stream_token(chunk) |
| #56 | |
| #57 | await msg.send() |
| #58 | ``` |
| #59 | |
| #60 | ## Run the app |
| #61 | |
| #62 | ``` |
| #63 | chainlit run app.py |
| #64 | ``` |
| #65 | |
| #66 | ## Try it out |
| #67 | |
| #68 | Open the app in your browser and start chatting with it! |
| #69 |