Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,21 +4,33 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
import torch
|
| 6 |
|
| 7 |
-
client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
|
| 8 |
-
|
| 9 |
def respond(message, history):
|
| 10 |
-
|
| 11 |
top_results = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 12 |
print(top_results)
|
| 13 |
-
messages = [{"role": "system", "content": "You are a friendly chatbot. You give people advice about what their dogs can eat. Base your response on the following information {top_results}. You resond in complete sentences"}]
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
messages.extend(history)
|
| 17 |
|
| 18 |
messages.append({"role": "user", "content": message})
|
| 19 |
|
| 20 |
-
response = client.chat_completion(messages, max_tokens
|
| 21 |
-
#connecting to llm, max caps response
|
| 22 |
return response['choices'][0]['message']['content'].strip()
|
| 23 |
|
| 24 |
print("hello world")
|
|
|
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
import torch
|
| 6 |
|
|
|
|
|
|
|
| 7 |
def respond(message, history):
|
|
|
|
| 8 |
top_results = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 9 |
print(top_results)
|
|
|
|
| 10 |
|
| 11 |
+
# ✅ Format context for LLM
|
| 12 |
+
if top_results:
|
| 13 |
+
formatted_info = "\n".join(f"- {chunk}" for chunk in top_results)
|
| 14 |
+
system_prompt = (
|
| 15 |
+
f"You are a friendly chatbot that gives advice about what dogs can eat.\n"
|
| 16 |
+
f"Use the following information to guide your response:\n{formatted_info}\n"
|
| 17 |
+
f"Respond in complete sentences and apply common sense. If the user asks about something not in the list, "
|
| 18 |
+
f"give a cautious answer and suggest checking with a vet."
|
| 19 |
+
)
|
| 20 |
+
else:
|
| 21 |
+
system_prompt = (
|
| 22 |
+
"You are a friendly chatbot that gives advice about what dogs can eat.\n"
|
| 23 |
+
"The user asked about a food not in your database. Respond cautiously and suggest checking with a vet."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 27 |
+
|
| 28 |
+
if history:
|
| 29 |
messages.extend(history)
|
| 30 |
|
| 31 |
messages.append({"role": "user", "content": message})
|
| 32 |
|
| 33 |
+
response = client.chat_completion(messages, max_tokens=100, temperature=0.2)
|
|
|
|
| 34 |
return response['choices'][0]['message']['content'].strip()
|
| 35 |
|
| 36 |
print("hello world")
|