Update app.py
Browse files
app.py
CHANGED
@@ -82,7 +82,7 @@ async def chat(request: ChatRequest):
|
|
82 |
})
|
83 |
|
84 |
# summarize chat history
|
85 |
-
summary_thresh =
|
86 |
if len(request.chat_history) > summary_thresh:
|
87 |
summarize_prompt = f"""Please summarize the following chat history concisely, focusing on the key points and main topics discussed. Avoid
|
88 |
unnecessary details and provide a clear, straightforward summary. {request.chat_history[:-summary_thresh]}""" # summarize everything except last k items
|
@@ -114,9 +114,9 @@ async def chat(request: ChatRequest):
|
|
114 |
|
115 |
# remove the unfformatted user message
|
116 |
del request.chat_history[-1]
|
117 |
-
|
118 |
# add the user message with RAG data
|
119 |
-
|
|
|
120 |
|
121 |
response = client.models.generate_content(
|
122 |
model="gemini-2.0-flash",
|
@@ -130,7 +130,7 @@ async def chat(request: ChatRequest):
|
|
130 |
del request.chat_history[-1]
|
131 |
request.chat_history.append({"role": "user", "parts": [{"text": request.message}]})
|
132 |
|
133 |
-
return {"response": response.text, "dataset_str": concise_text_string, "history": request.chat_history, "RAG_prompt": rag_prompt, "chunks": chunks, "results": results}
|
134 |
|
135 |
if request.model_choice == "HF":
|
136 |
if hf_token:
|
|
|
82 |
})
|
83 |
|
84 |
# summarize chat history
|
85 |
+
summary_thresh = 10
|
86 |
if len(request.chat_history) > summary_thresh:
|
87 |
summarize_prompt = f"""Please summarize the following chat history concisely, focusing on the key points and main topics discussed. Avoid
|
88 |
unnecessary details and provide a clear, straightforward summary. {request.chat_history[:-summary_thresh]}""" # summarize everything except last k items
|
|
|
114 |
|
115 |
# remove the unfformatted user message
|
116 |
del request.chat_history[-1]
|
|
|
117 |
# add the user message with RAG data
|
118 |
+
rag_prompt = textwrap.dedent(rag_prompt)
|
119 |
+
request.chat_history.append({"role": "user", "parts": [{"text": rag_prompt}]})
|
120 |
|
121 |
response = client.models.generate_content(
|
122 |
model="gemini-2.0-flash",
|
|
|
130 |
del request.chat_history[-1]
|
131 |
request.chat_history.append({"role": "user", "parts": [{"text": request.message}]})
|
132 |
|
133 |
+
return {"response": response.text, "dataset_str": concise_text_string[:150], "history": request.chat_history, "RAG_prompt": rag_prompt, "chunks": chunks, "results": results}
|
134 |
|
135 |
if request.model_choice == "HF":
|
136 |
if hf_token:
|