Spaces:
Running
Running
fix bug qa caching
Browse files- app.py +13 -8
- notebooks/chat_with_avatar.ipynb +2 -2
app.py
CHANGED
|
@@ -143,8 +143,8 @@ class MyProfileAvatarChat(Config, FileReader):
|
|
| 143 |
print(f"Reusing past answer (similarity={sim_score:.2%})")
|
| 144 |
refine_prompt = (
|
| 145 |
f"The user previously asked a similar question:\n"
|
| 146 |
-
+ f"Old question: {similar[
|
| 147 |
-
+ f"Old answer: {similar[
|
| 148 |
+ f"Now user asks: {message}\n\n"
|
| 149 |
+ f"Please update or refine the old answer to match the new question."
|
| 150 |
)
|
|
@@ -192,11 +192,11 @@ class MyProfileAvatarChat(Config, FileReader):
|
|
| 192 |
traceback.print_exc()
|
| 193 |
emb = None
|
| 194 |
|
| 195 |
-
self.qa_cache.append(
|
| 196 |
-
question
|
| 197 |
-
answer
|
| 198 |
-
embedding
|
| 199 |
-
)
|
| 200 |
|
| 201 |
return reply
|
| 202 |
|
|
@@ -215,5 +215,10 @@ class MyProfileAvatarChat(Config, FileReader):
|
|
| 215 |
if __name__ == "__main__":
|
| 216 |
|
| 217 |
my_profile = MyProfileAvatarChat()
|
| 218 |
-
gr.ChatInterface(my_profile.chat_traced)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
|
|
|
| 143 |
print(f"Reusing past answer (similarity={sim_score:.2%})")
|
| 144 |
refine_prompt = (
|
| 145 |
f"The user previously asked a similar question:\n"
|
| 146 |
+
+ f"Old question: {similar["question"]}\n"
|
| 147 |
+
+ f"Old answer: {similar["answer"]}\n\n"
|
| 148 |
+ f"Now user asks: {message}\n\n"
|
| 149 |
+ f"Please update or refine the old answer to match the new question."
|
| 150 |
)
|
|
|
|
| 192 |
traceback.print_exc()
|
| 193 |
emb = None
|
| 194 |
|
| 195 |
+
self.qa_cache.append({
|
| 196 |
+
"question":message,
|
| 197 |
+
"answer":reply,
|
| 198 |
+
"embedding":emb
|
| 199 |
+
})
|
| 200 |
|
| 201 |
return reply
|
| 202 |
|
|
|
|
| 215 |
if __name__ == "__main__":
|
| 216 |
|
| 217 |
my_profile = MyProfileAvatarChat()
|
| 218 |
+
demo = gr.ChatInterface(my_profile.chat_traced)
|
| 219 |
+
|
| 220 |
+
demo.queue(max_size=10).launch( # allows up to 10 tasks in queue
|
| 221 |
+
server_name="0.0.0.0",
|
| 222 |
+
server_port=7860,
|
| 223 |
+
share=False)
|
| 224 |
|
notebooks/chat_with_avatar.ipynb
CHANGED
|
@@ -411,7 +411,7 @@
|
|
| 411 |
],
|
| 412 |
"metadata": {
|
| 413 |
"kernelspec": {
|
| 414 |
-
"display_name": "
|
| 415 |
"language": "python",
|
| 416 |
"name": "python3"
|
| 417 |
},
|
|
@@ -425,7 +425,7 @@
|
|
| 425 |
"name": "python",
|
| 426 |
"nbconvert_exporter": "python",
|
| 427 |
"pygments_lexer": "ipython3",
|
| 428 |
-
"version": "3.
|
| 429 |
}
|
| 430 |
},
|
| 431 |
"nbformat": 4,
|
|
|
|
| 411 |
],
|
| 412 |
"metadata": {
|
| 413 |
"kernelspec": {
|
| 414 |
+
"display_name": ".venv",
|
| 415 |
"language": "python",
|
| 416 |
"name": "python3"
|
| 417 |
},
|
|
|
|
| 425 |
"name": "python",
|
| 426 |
"nbconvert_exporter": "python",
|
| 427 |
"pygments_lexer": "ipython3",
|
| 428 |
+
"version": "3.13.1"
|
| 429 |
}
|
| 430 |
},
|
| 431 |
"nbformat": 4,
|