kenqia commited on
Commit
dbe065b
·
verified ·
1 Parent(s): da4480d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -17
app.py CHANGED
@@ -11,7 +11,13 @@ from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage, AIM
11
  from langgraph.graph.message import add_messages
12
  from langgraph.prebuilt import ToolNode, tools_condition
13
  from langchain_tavily import TavilySearch
14
- from tools import answer_excel_question, answer_python_question, extract_youtube_id, get_youtube_transcript
 
 
 
 
 
 
15
  # (Keep Constants as is)
16
  # --- Constants ---
17
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -41,15 +47,17 @@ class BasicAgent:
41
  max_retries=1,
42
  max_tokens=128,
43
  )
44
- self.tools = [answer_excel_question,
45
- answer_python_question,
46
- extract_youtube_id,
47
- get_youtube_transcript,
48
- TavilySearch(
49
- max_results=5,
50
- topic="general",
51
- search_depth="basic",
52
- )
 
 
53
  ]
54
 
55
  self.chat_with_tools = self.model.bind_tools(self.tools)
@@ -126,12 +134,22 @@ class BasicAgent:
126
  return "tools"
127
 
128
  return "final_process"
129
-
130
- def answer_question(self, question: str) -> str:
131
- # TODO:
132
- messages = [HumanMessage(content=question)]
133
- messages = self.react_graph.invoke({"messages" : messages})
134
- return messages["messages"][-1].content
 
 
 
 
 
 
 
 
 
 
135
 
136
  def run_and_submit_all( profile: gr.OAuthProfile | None):
137
  """
@@ -194,7 +212,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
194
  print(f"Skipping item with missing task_id or question: {item}")
195
  continue
196
  try:
197
- submitted_answer = agent(question_text)
198
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
199
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
200
  except Exception as e:
 
11
  from langgraph.graph.message import add_messages
12
  from langgraph.prebuilt import ToolNode, tools_condition
13
  from langchain_tavily import TavilySearch
14
+ from tools import (
15
+ download_task_file,
16
+ read_attached_text_file,
17
+ answer_excel_question,
18
+ answer_python_question,
19
+ get_youtube_transcript,
20
+ )
21
  # (Keep Constants as is)
22
  # --- Constants ---
23
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
47
  max_retries=1,
48
  max_tokens=128,
49
  )
50
+ self.tools = [
51
+ download_task_file,
52
+ read_attached_text_file,
53
+ answer_excel_question,
54
+ answer_python_question,
55
+ get_youtube_transcript,
56
+ TavilySearch(
57
+ max_results=5,
58
+ topic="general",
59
+ search_depth="basic",
60
+ ),
61
  ]
62
 
63
  self.chat_with_tools = self.model.bind_tools(self.tools)
 
134
  return "tools"
135
 
136
  return "final_process"
137
+
138
+ def answer_question(self, question: str, task_id: str | None = None) -> str:
139
+ user_content = question
140
+
141
+ if task_id:
142
+ user_content += (
143
+ f"\n\nTask ID: {task_id}. "
144
+ "If the question mentions an attached file, spreadsheet, code file, audio, or image, "
145
+ "use the available tools with this task_id."
146
+ )
147
+
148
+ messages = [HumanMessage(content=user_content)]
149
+ result = self.react_graph.invoke({"messages": messages})
150
+ return result["messages"][-1].content
151
+
152
+
153
 
154
  def run_and_submit_all( profile: gr.OAuthProfile | None):
155
  """
 
212
  print(f"Skipping item with missing task_id or question: {item}")
213
  continue
214
  try:
215
+ submitted_answer = agent(question_text, task_id)
216
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
217
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
218
  except Exception as e: