Duke-911 commited on
Commit
5dfb234
·
1 Parent(s): 4a80e6e

Refactor system prompt in app.py for clarity and update agent response handling

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -15,32 +15,27 @@ from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
 
18
- llm = HuggingFaceInferenceAPI(model_name='Qwen/Qwen3-32B', num_output=2048)
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  wikipedia_tools = WikipediaToolSpec().to_tool_list()
20
  search_tool = FunctionTool.from_defaults(DuckDuckGoSearchToolSpec().duckduckgo_full_search)
21
 
22
  agent = AgentWorkflow.from_tools_or_functions(
23
  tools_or_functions=[search_tool],
24
  llm=llm,
25
- system_prompt="""You are a concise answer engine.
26
- ALWAYS output *only* the single entity requested—no explanations, no punctuation beyond the entity itself.
27
- If unsure, reply “Unknown”.
28
- Output must be a single word or name or number. Do not output anything else.
29
- Examples:
30
- Q: What is the capital of France?
31
- A: Paris
32
-
33
- Q: Who nominated the only Featured Article on English Wikipedia about a dinosaur promoted in November 2016?
34
- A: Ian Rose
35
-
36
- Q: How many legs does a spider have?
37
- A: 8
38
-
39
- Do not think step by step. Do not show any internal reasoning. Only respond with the exact entity.
40
-
41
- You can use the Wikipedia tool to search for information on Wikipedia, and the DuckDuckGo tool to search the web.
42
- Some of the questions might be valid sentences but with characters reversed.
43
- """,
44
  verbose=False,
45
  )
46
 
@@ -100,7 +95,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
100
  print(f"Skipping item with missing task_id or question: {item}")
101
  continue
102
  try:
103
- r = await agent.run(question_text)
104
  submitted_answer = r.response.blocks[0].text
105
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
106
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
 
18
+ system_prompt="""You are a general AI assistant. I will ask you a question. Report your thoughts, and finish
19
+ your answer with the following template:
20
+ [YOUR FINAL ANSWER].
21
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of
22
+ numbers and/or strings.
23
+ If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent
24
+ sign unless specified otherwise.
25
+ If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in
26
+ plain text unless specified otherwise.
27
+ If you are asked for a comma separated list, apply the above rules depending of whether the element to be put
28
+ in the list is a number or a string.
29
+ """
30
+
31
+ llm = HuggingFaceInferenceAPI(model_name='Qwen/Qwen3-32B', num_output=2048, temperature=0.01)
32
  wikipedia_tools = WikipediaToolSpec().to_tool_list()
33
  search_tool = FunctionTool.from_defaults(DuckDuckGoSearchToolSpec().duckduckgo_full_search)
34
 
35
  agent = AgentWorkflow.from_tools_or_functions(
36
  tools_or_functions=[search_tool],
37
  llm=llm,
38
+ system_prompt=system_prompt,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  verbose=False,
40
  )
41
 
 
95
  print(f"Skipping item with missing task_id or question: {item}")
96
  continue
97
  try:
98
+ r = await agent.run(system_prompt + question_text)
99
  submitted_answer = r.response.blocks[0].text
100
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
101
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})