Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,13 +31,13 @@ llm = ChatOpenAI(
|
|
| 31 |
api_key=openai_api_key
|
| 32 |
)
|
| 33 |
|
| 34 |
-
# ✅ Chat Function
|
| 35 |
-
def get_text_response(user_message, state):
|
| 36 |
-
# create
|
| 37 |
if state is None:
|
| 38 |
state = ConversationBufferMemory(memory_key="chat_history")
|
| 39 |
|
| 40 |
-
#
|
| 41 |
llm_chain = LLMChain(
|
| 42 |
llm=llm,
|
| 43 |
prompt=prompt,
|
|
@@ -48,7 +48,7 @@ def get_text_response(user_message, state):
|
|
| 48 |
response = llm_chain.predict(user_message=user_message)
|
| 49 |
return response, state
|
| 50 |
|
| 51 |
-
# ✅ Gradio Chat App
|
| 52 |
demo = gr.ChatInterface(
|
| 53 |
fn=get_text_response,
|
| 54 |
examples=[
|
|
@@ -56,7 +56,7 @@ demo = gr.ChatInterface(
|
|
| 56 |
["What are your interests?", None],
|
| 57 |
["Which places do you like to visit?", None]
|
| 58 |
],
|
| 59 |
-
additional_inputs=[gr.State()]
|
| 60 |
)
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
|
|
|
| 31 |
api_key=openai_api_key
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# ✅ Chat Function (3 args required!)
|
| 35 |
+
def get_text_response(user_message, history, state):
|
| 36 |
+
# create memory if none exists for this session
|
| 37 |
if state is None:
|
| 38 |
state = ConversationBufferMemory(memory_key="chat_history")
|
| 39 |
|
| 40 |
+
# Chain with per-user memory
|
| 41 |
llm_chain = LLMChain(
|
| 42 |
llm=llm,
|
| 43 |
prompt=prompt,
|
|
|
|
| 48 |
response = llm_chain.predict(user_message=user_message)
|
| 49 |
return response, state
|
| 50 |
|
| 51 |
+
# ✅ Gradio Chat App
|
| 52 |
demo = gr.ChatInterface(
|
| 53 |
fn=get_text_response,
|
| 54 |
examples=[
|
|
|
|
| 56 |
["What are your interests?", None],
|
| 57 |
["Which places do you like to visit?", None]
|
| 58 |
],
|
| 59 |
+
additional_inputs=[gr.State()]
|
| 60 |
)
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|