Spaces:
Runtime error
Runtime error
Commit
·
a264065
1
Parent(s):
1817a62
task: adds user session conversation
Browse files- src/app.py +15 -12
src/app.py
CHANGED
@@ -1,10 +1,18 @@
|
|
1 |
import chainlit as cl
|
2 |
-
from langchain_openai import
|
3 |
from langchain_core.messages import HumanMessage, SystemMessage
|
4 |
from chains.design_rag import DesignRAG
|
5 |
|
6 |
# Initialize components
|
7 |
design_rag = DesignRAG()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
conversation_history = []
|
9 |
|
10 |
# System message focused on design analysis
|
@@ -20,23 +28,18 @@ First briefly explain how you understand their requirements, then show the close
|
|
20 |
|
21 |
@cl.on_chat_start
|
22 |
async def init():
|
23 |
-
# Initialize LLM with streaming
|
24 |
-
global llm
|
25 |
-
llm = ChatOpenAI(
|
26 |
-
model="gpt-4",
|
27 |
-
temperature=0,
|
28 |
-
streaming=True,
|
29 |
-
callbacks=[cl.LangchainCallbackHandler()]
|
30 |
-
)
|
31 |
|
32 |
-
#
|
33 |
-
|
|
|
|
|
34 |
|
35 |
# Send welcome message
|
36 |
-
await cl.Message(content="
|
37 |
|
38 |
@cl.on_message
|
39 |
async def main(message: cl.Message):
|
|
|
40 |
# Add user message to history
|
41 |
conversation_history.append(HumanMessage(content=message.content))
|
42 |
|
|
|
1 |
import chainlit as cl
|
2 |
+
from langchain_openai import AsyncChatOpenAI
|
3 |
from langchain_core.messages import HumanMessage, SystemMessage
|
4 |
from chains.design_rag import DesignRAG
|
5 |
|
6 |
# Initialize components
|
7 |
design_rag = DesignRAG()
|
8 |
+
|
9 |
+
llm = AsyncChatOpenAI(
|
10 |
+
model="gpt-4o-mini",
|
11 |
+
temperature=0,
|
12 |
+
streaming=True,
|
13 |
+
callbacks=[cl.LangchainCallbackHandler()]
|
14 |
+
)
|
15 |
+
|
16 |
conversation_history = []
|
17 |
|
18 |
# System message focused on design analysis
|
|
|
28 |
|
29 |
@cl.on_chat_start
|
30 |
async def init():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
# init conversation history for each user
|
33 |
+
cl.user_session.set("conversation_history", [
|
34 |
+
SystemMessage(content=SYSTEM_MESSAGE)
|
35 |
+
])
|
36 |
|
37 |
# Send welcome message
|
38 |
+
await cl.Message(content="Welcome to ImagineUI! I'm here to help you design beautiful and functional user interfaces. What kind of design are you looking for?").send()
|
39 |
|
40 |
@cl.on_message
|
41 |
async def main(message: cl.Message):
|
42 |
+
conversation_history = cl.user_session.get("conversation_history")
|
43 |
# Add user message to history
|
44 |
conversation_history.append(HumanMessage(content=message.content))
|
45 |
|