Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,7 +39,7 @@ class ReasoningAgent:
|
|
| 39 |
)
|
| 40 |
|
| 41 |
def __call__(self, question: str) -> str:
|
| 42 |
-
print(f"
|
| 43 |
|
| 44 |
# Prompt structuré
|
| 45 |
prompt = f"""
|
|
@@ -59,34 +59,40 @@ Question: {question}
|
|
| 59 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 60 |
output = model.generate(**inputs, max_new_tokens=300)
|
| 61 |
text_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 62 |
-
print(f"Raw model output:
|
| 63 |
|
| 64 |
# Parser le JSON
|
| 65 |
try:
|
| 66 |
parsed = json.loads(text_output)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# --- Main Evaluation & Submission Function ---
|
| 92 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
def __call__(self, question: str) -> str:
|
| 42 |
+
print(f"\n=== New Question ===\n{question}\n")
|
| 43 |
|
| 44 |
# Prompt structuré
|
| 45 |
prompt = f"""
|
|
|
|
| 59 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 60 |
output = model.generate(**inputs, max_new_tokens=300)
|
| 61 |
text_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 62 |
+
print(f"Raw model output:\n{text_output[:1000]}...\n") # on affiche un gros morceau du texte
|
| 63 |
|
| 64 |
# Parser le JSON
|
| 65 |
try:
|
| 66 |
parsed = json.loads(text_output)
|
| 67 |
+
except json.JSONDecodeError as e:
|
| 68 |
+
print(f"⚠️ JSON decode error: {e}")
|
| 69 |
+
parsed = {"thought": "", "action": "None", "observation": "", "answer": text_output}
|
| 70 |
+
|
| 71 |
+
thought = parsed.get("thought", "")
|
| 72 |
+
action = parsed.get("action", "None")
|
| 73 |
+
observation = parsed.get("observation", "")
|
| 74 |
+
answer = parsed.get("answer", "No answer returned.")
|
| 75 |
+
|
| 76 |
+
# Exécution de l'outil si nécessaire
|
| 77 |
+
if action.startswith("AddTwoNumbers"):
|
| 78 |
+
try:
|
| 79 |
+
numbers = action[action.find("(")+1:action.find(")")].split(",")
|
| 80 |
+
a, b = int(numbers[0].strip()), int(numbers[1].strip())
|
| 81 |
+
observation = AddTwoNumbers(a, b)
|
| 82 |
+
parsed["observation"] = str(observation)
|
| 83 |
+
print(f"✅ Tool executed: {action} -> {observation}")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
observation = f"⚠️ Error executing tool: {e}"
|
| 86 |
+
parsed["observation"] = observation
|
| 87 |
+
print(observation)
|
| 88 |
+
|
| 89 |
+
# Print du raisonnement actuel
|
| 90 |
+
print(f"💭 Thought: {thought}")
|
| 91 |
+
print(f"🔧 Action: {action}")
|
| 92 |
+
print(f"👀 Observation: {observation}")
|
| 93 |
+
print(f"📝 Answer: {answer}\n{'-'*50}\n")
|
| 94 |
+
|
| 95 |
+
return answer
|
| 96 |
|
| 97 |
# --- Main Evaluation & Submission Function ---
|
| 98 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|