Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,16 +6,12 @@ from pydantic import BaseModel
|
|
| 6 |
import uvicorn
|
| 7 |
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
-
|
| 10 |
-
# Correct endpoint for your model
|
| 11 |
API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.3"
|
| 12 |
|
| 13 |
-
SYSTEM_PROMPT = "Tu es l'assistant SAV officiel du Centre Chery Tunisie. Tu réponds en français ou en arabe dialectal tunisien selon la langue du client."
|
| 14 |
|
| 15 |
def chat(message, history):
|
| 16 |
-
# Build prompt in Mistral instruct format
|
| 17 |
prompt = f"[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\n"
|
| 18 |
-
|
| 19 |
for h in history:
|
| 20 |
if isinstance(h, dict):
|
| 21 |
if h["role"] == "user":
|
|
@@ -24,7 +20,6 @@ def chat(message, history):
|
|
| 24 |
prompt += f"{h['content']} </s><s>[INST] "
|
| 25 |
else:
|
| 26 |
prompt += f"{h[0]} [/INST] {h[1]} </s><s>[INST] "
|
| 27 |
-
|
| 28 |
prompt += f"{message} [/INST]"
|
| 29 |
|
| 30 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
|
@@ -38,9 +33,7 @@ def chat(message, history):
|
|
| 38 |
}
|
| 39 |
|
| 40 |
try:
|
| 41 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=
|
| 42 |
-
print("Status:", response.status_code)
|
| 43 |
-
print("Body:", response.text[:300])
|
| 44 |
result = response.json()
|
| 45 |
if isinstance(result, list):
|
| 46 |
return result[0].get("generated_text", "Pas de réponse")
|
|
|
|
| 6 |
import uvicorn
|
| 7 |
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
|
|
|
|
| 9 |
API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.3"
|
| 10 |
|
| 11 |
+
SYSTEM_PROMPT = "Tu es l'assistant SAV officiel du Centre Chery Tunisie. Tu réponds en français ou en arabe dialectal tunisien selon la langue du client. Réponds uniquement aux questions liées aux véhicules Chery, la maintenance, les pannes, et le service après-vente."
|
| 12 |
|
| 13 |
def chat(message, history):
|
|
|
|
| 14 |
prompt = f"[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\n"
|
|
|
|
| 15 |
for h in history:
|
| 16 |
if isinstance(h, dict):
|
| 17 |
if h["role"] == "user":
|
|
|
|
| 20 |
prompt += f"{h['content']} </s><s>[INST] "
|
| 21 |
else:
|
| 22 |
prompt += f"{h[0]} [/INST] {h[1]} </s><s>[INST] "
|
|
|
|
| 23 |
prompt += f"{message} [/INST]"
|
| 24 |
|
| 25 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
try:
|
| 36 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=60)
|
|
|
|
|
|
|
| 37 |
result = response.json()
|
| 38 |
if isinstance(result, list):
|
| 39 |
return result[0].get("generated_text", "Pas de réponse")
|