CoolFace
Apppublic

nasim-samei/AI-agent

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py31 linesDownload Raw Back to root
1 2import chainlit as cl3from chainlit.message import Message4import uuid5from main import EIAgent6agent = EIAgent()7@cl.on_chat_start8async def on_chat_start():9    thread_id = str(uuid.uuid4())10    cl.user_session.set("thread_id", thread_id)11    """Send a welcome message when the chat starts."""12    welcome_text = "Hi! I'm an AI-powered EI assistant and ready to help you with questions about Employment Insurance benefits. Please note that while I strive to provide accurate information, my responses may not always be correct or complete. Always verify critical information independently."13    await cl.Message(content=welcome_text).send()14 15 16@cl.on_message17async def on_message(message: Message):18    thread_id = cl.user_session.get("thread_id") # Unique ID for the session19    config = {"configurable": {"thread_id": thread_id}}20    """Handle incoming messages."""21    msg = cl.Message(content="")22    async with cl.Step("Fetched Content 🤔"):23        response= agent.ask(message.content, config)24        await msg.stream_token(response["answer"][-1].content + "\n\n")25        if str(response["with citations"]) != "" and str(response["with citations"])!= '[0]' and str(response["with citations"]) != "[]":26            await msg.stream_token("You can find the related information in the following chapters from [Digest of Benefit Entitlement Principles](https://www.canada.ca/en/employment-social-development/programs/ei/ei-list/reports/digest.html): "+ str(response["with citations"]).strip("[]"))27 28    await msg.send()29 30if __name__ == "__main__":31    cl.run()