InfinityCoder5607 commited on
Commit
86f0f36
·
1 Parent(s): 820ab2a
Files changed (3) hide show
  1. __pycache__/app.cpython-312.pyc +0 -0
  2. app.py +65 -5
  3. show_questions.py +19 -0
__pycache__/app.cpython-312.pyc ADDED
Binary file (11.1 kB). View file
 
app.py CHANGED
@@ -4,7 +4,8 @@ import requests
4
  import inspect
5
  import pandas as pd
6
  import spaces
7
-
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -14,14 +15,73 @@ def zerogpu_function():
14
  # --- Basic Agent Definition ---
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  class BasicAgent:
18
  def __init__(self):
19
  print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def __call__(self, question: str) -> str:
21
- print(f"Agent received question (first 50 chars): {question[:50]}...")
22
- fixed_answer = "This is a default answer."
23
- print(f"Agent returning fixed answer: {fixed_answer}")
24
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def run_and_submit_all( profile: gr.OAuthProfile | None):
27
  """
 
4
  import inspect
5
  import pandas as pd
6
  import spaces
7
+ from langchain_openai import ChatOpenAI
8
+ from langchain.agents import create_agent
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
15
  # --- Basic Agent Definition ---
16
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
17
 
18
+ # class BasicAgent:
19
+ # def __init__(self):
20
+ # print("BasicAgent initialized.")
21
+ # def __call__(self, question: str) -> str:
22
+ # print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+ # fixed_answer = "This is a default answer."
24
+ # print(f"Agent returning fixed answer: {fixed_answer}")
25
+ # return fixed_answer
26
+
27
+ model = ChatOpenAI(
28
+ model="qwen-plus",
29
+ api_key=os.environ["DASHSCOPE_API_KEY"],
30
+ base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
31
+ temperature=0,
32
+ )
33
+
34
  class BasicAgent:
35
  def __init__(self):
36
  print("BasicAgent initialized.")
37
+
38
+ agent_model = model
39
+
40
+ self.agent = create_agent(
41
+ model=agent_model,
42
+ tools=[],
43
+ system_prompt="""
44
+ You are solving GAIA benchmark questions.
45
+
46
+ You have NO external tools.
47
+ You cannot browse the web.
48
+ You cannot access files or attachments.
49
+ You cannot use a calculator or Python.
50
+
51
+ Solve each question using only your internal knowledge and reasoning.
52
+
53
+ IMPORTANT:
54
+ - Return only the final answer.
55
+ - Do not explain your reasoning.
56
+ - Do not include phrases such as "FINAL ANSWER".
57
+ - Follow the exact output format requested by the question.
58
+ """
59
+ )
60
+
61
  def __call__(self, question: str) -> str:
62
+ print(f"Agent received question: {question[:100]}...")
63
+
64
+ result = self.agent.invoke({
65
+ "messages": [
66
+ {
67
+ "role": "user",
68
+ "content": question
69
+ }
70
+ ]
71
+ })
72
+
73
+ answer = result["messages"][-1].content
74
+
75
+ print(f"Agent answer: {answer}")
76
+
77
+ return answer
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
 
86
  def run_and_submit_all( profile: gr.OAuthProfile | None):
87
  """
show_questions.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ API_URL = "https://agents-course-unit4-scoring.hf.space"
4
+ QUESTIONS_URL = f"{API_URL}/questions"
5
+
6
+ response = requests.get(QUESTIONS_URL, timeout=30)
7
+ response.raise_for_status()
8
+
9
+ questions = response.json()
10
+
11
+ print(f"总题数: {len(questions)}\n")
12
+
13
+ for i, item in enumerate(questions, start=1):
14
+ print("=" * 80)
15
+ print(f"第 {i} 题")
16
+ print(f"task_id: {item.get('task_id')}")
17
+ print(f"question: {item.get('question')}")
18
+ print(f"file_name: {item.get('file_name', '')}")
19
+ print()