-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* made changes in function_agent.py file * Chainlit UI added --------- Co-authored-by: THEAVINASHREDDY <avinashreddy1233@gmail.com> Co-authored-by: Dominic <34897716+shroominic@users.noreply.github.com>
- Loading branch information
1 parent
4666afb
commit 8987cda
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import chainlit as cl | ||
from codeinterpreterapi import CodeInterpreterSession | ||
from codeinterpreterapi import File as CIFile | ||
|
||
UPLOADED_FILES = [] | ||
|
||
@cl.action_callback("upload_file") | ||
async def on_action(action): | ||
files = None | ||
|
||
# Wait for the user to upload a file | ||
while files is None: | ||
files = await cl.AskFileMessage( | ||
content="Please upload a text file to begin!", accept=["text/csv"] | ||
).send() | ||
# Decode the file | ||
text_file = files[0] | ||
text = text_file.content.decode("utf-8") | ||
|
||
UPLOADED_FILES.append(text_file) | ||
|
||
# Let the user know that the system is ready | ||
await cl.Message( | ||
content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!" | ||
).send() | ||
await action.remove() | ||
|
||
@cl.on_chat_start | ||
async def start_chat(): | ||
actions = [ | ||
cl.Action(name="upload_file", value="example_value", description="Upload file") | ||
] | ||
|
||
await cl.Message( | ||
content="Hello, How can I assist you today", actions=actions | ||
).send() | ||
|
||
@cl.on_message | ||
async def run_conversation(user_message: str): | ||
session = CodeInterpreterSession() | ||
await session.astart() | ||
|
||
files = [CIFile(name=it.name, content=it.content) for it in UPLOADED_FILES] | ||
|
||
|
||
response = await session.agenerate_response(user_message, files=files) | ||
elements = [ | ||
cl.Image( | ||
content=file.content, | ||
name=f"code-interpreter-image-{file.name}", | ||
display="inline", | ||
) | ||
for file in response.files | ||
] | ||
actions = [ | ||
cl.Action(name="upload_file", value="example_value", description="Upload file") | ||
] | ||
await cl.Message( | ||
content=response.content, | ||
elements=elements, | ||
actions=actions, | ||
).send() | ||
|
||
await session.astop() |