Update
Browse files
app.py
CHANGED
@@ -47,19 +47,18 @@ else:
|
|
47 |
@cl.on_chat_start
|
48 |
async def on_chat_start():
|
49 |
print("On Chat Start")
|
50 |
-
await cl.Message(content="Hello, i am your movie recommender, how can i help you today?").send()
|
51 |
prompt_template = ChatPromptTemplate.from_template(
|
52 |
"You are a movie recommendation system, for a given {query} find recommendations from {content}."
|
53 |
)
|
54 |
retriever = vector_store.as_retriever()
|
55 |
-
chat_model = ChatOpenAI(model="gpt-4o", temperature=0.2, openai_api_key=openai_api_key)
|
56 |
parser = StrOutputParser()
|
57 |
|
58 |
runnable_chain = (
|
59 |
{"query": RunnablePassthrough(), "content": retriever}
|
60 |
| prompt_template
|
61 |
| chat_model
|
62 |
-
|
|
63 |
)
|
64 |
cl.user_session.set("chain", runnable_chain)
|
65 |
|
@@ -72,8 +71,6 @@ async def main(message):
|
|
72 |
user_input = cl.Message(content="")
|
73 |
await user_input.send()
|
74 |
|
75 |
-
async for stream in chain.astream(user_input, cb):
|
76 |
print("Stream is: " + stream)
|
77 |
-
await user_input.stream_token(stream)
|
78 |
-
|
79 |
-
await user_input.update()
|
|
|
47 |
@cl.on_chat_start
|
48 |
async def on_chat_start():
|
49 |
print("On Chat Start")
|
|
|
50 |
prompt_template = ChatPromptTemplate.from_template(
|
51 |
"You are a movie recommendation system, for a given {query} find recommendations from {content}."
|
52 |
)
|
53 |
retriever = vector_store.as_retriever()
|
54 |
+
chat_model = ChatOpenAI(model="gpt-4o", temperature=0.2, openai_api_key=openai_api_key, streaming=True)
|
55 |
parser = StrOutputParser()
|
56 |
|
57 |
runnable_chain = (
|
58 |
{"query": RunnablePassthrough(), "content": retriever}
|
59 |
| prompt_template
|
60 |
| chat_model
|
61 |
+
| parser
|
62 |
)
|
63 |
cl.user_session.set("chain", runnable_chain)
|
64 |
|
|
|
71 |
user_input = cl.Message(content="")
|
72 |
await user_input.send()
|
73 |
|
74 |
+
async for stream in chain.astream(user_input.content, cb):
|
75 |
print("Stream is: " + stream)
|
76 |
+
await user_input.stream_token(stream)
|
|
|
|