Spaces:
Build error
Build error
Commit ·
a4c9a4a
1
Parent(s): 6387e77
+ error handling
Browse filesFiles changed (3)
- agents.py+9-1
- app.py+14-11
- system_prompt.txt+5-1
11 unmodified lines1213141516171878 unmodified lines9798991009910110210310410510610710810911011 unmodified linesfrom opentelemetry.sdk.trace import TracerProviderfrom langfuse import get_clientfrom rich.pretty import pprintimport aiohttp
78 unmodified lines # Optionally set trace attributes span.update_trace(user_id="user_123", input={"query": query})
try: response = await self.alfred.run(query) response = await self.alfred.run(query) except aiohttp.client_exceptions.ClientConnectionError as e: span.update_trace(output={"response": f"Connection error: {e}"}) return f"AGENT ERROR: Connection error to LLM API: {e}" except Exception as e: span.update_trace(output={"response": f"General error: {e}"}) return f"AGENT ERROR: {e}"
# Optionally set trace output span.update_trace(output={"response": str(response)})4 unmodified lines56789101147 unmodified lines596061626364626364656667686970717265666768697071727374757677784 unmodified linesimport pandas as pdfrom agents import LlamaIndexAgentimport asyncioimport aiohttp
# (Keep Constants as is)# --- Constants ---47 unmodified lines cached_questions = questions_data total = len(questions_data) progress(0, desc="Starting answer generation...") semaphore = asyncio.Semaphore(3) # Limit concurrency to 3 async def answer_one(item): async with semaphore: task_id = item.get("task_id") question_text = item.get("question") if not task_id or question_text is None: print(f"Skipping item with missing task_id or question: {item}") return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, None try: submitted_answer = await agent.aquery(question_text) return {"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}, {"task_id": task_id, "submitted_answer": submitted_answer} except Exception as e: print(f"Error running agent on task {task_id}: {e}") return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None task_id = item.get("task_id") question_text = item.get("question") if not task_id or question_text is None: print(f"Skipping item with missing task_id or question: {item}") return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, None try: submitted_answer = await agent.aquery(question_text) return {"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}, {"task_id": task_id, "submitted_answer": submitted_answer} except Exception as e: print(f"Error running agent on task {task_id}: {e}") return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None tasks = [answer_one(item) for item in questions_data] results_log = [] answers_payload = []112345give single word answer and reply.You are a helpful assistant tasked with answering questions using a set of tools. Now, I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.Your answer should only start with "FINAL ANSWER: ", then follows with the answer. agents.py+9-1
app.py+14-11
system_prompt.txt+5-1