cowrycode commited on
Commit
440ab82
·
verified ·
1 Parent(s): 941afae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -36,20 +36,6 @@ class BasicAgent:
36
  llm=self.llm
37
  )
38
 
39
- # self.tools = [
40
- # wikipedia_search_tool,
41
- # youtube_transcript_tool,
42
- # youtube_transcript_snippet_tool,
43
- # round_to_two_decimals_tool,
44
- # text_inverter_tool,
45
- # google_web_search_tool
46
- # ]
47
-
48
- # self.agent = ReActAgent.from_tools(
49
- # tools=self.tools,
50
- # llm=self.llm,
51
- # verbose=True
52
- # )
53
 
54
  async def run(self, question: str) -> str:
55
  print(f"Agent received question (first 50 chars): {question[:50]}...")
@@ -62,6 +48,32 @@ class BasicAgent:
62
  return self.run(question)
63
  #return self.agent.run(question)
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  def run_and_submit_all( profile: gr.OAuthProfile | None):
66
  """
67
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -82,11 +94,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
82
  submit_url = f"{api_url}/submit"
83
 
84
  # 1. Instantiate Agent ( modify this part to create your agent)
85
- try:
86
- agent = BasicAgent()
87
- except Exception as e:
88
- print(f"Error instantiating agent: {e}")
89
- return f"Error initializing agent: {e}", None
 
90
  #In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
91
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
92
  print(agent_code)
 
36
  llm=self.llm
37
  )
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  async def run(self, question: str) -> str:
41
  print(f"Agent received question (first 50 chars): {question[:50]}...")
 
48
  return self.run(question)
49
  #return self.agent.run(question)
50
 
51
+ def create_llamaindex_agent() -> ReActAgent:
52
+ api_key = os.getenv("HF_TOKEN")
53
+ llm = HuggingFaceInferenceAPI(
54
+ model_name="deepseek-ai/DeepSeek-R1-0528",
55
+ token=api_key,
56
+ provider="auto",
57
+ max_iterations=10
58
+ )
59
+
60
+ tools = [
61
+ wikipedia_search_tool,
62
+ youtube_transcript_tool,
63
+ youtube_transcript_snippet_tool,
64
+ round_to_two_decimals_tool,
65
+ text_inverter_tool,
66
+ google_web_search_tool
67
+ ]
68
+
69
+ agent = ReActAgent.from_tools(
70
+ tools=tools,
71
+ llm=self.llm,
72
+ verbose=True
73
+ )
74
+
75
+ return agent
76
+
77
  def run_and_submit_all( profile: gr.OAuthProfile | None):
78
  """
79
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
94
  submit_url = f"{api_url}/submit"
95
 
96
  # 1. Instantiate Agent ( modify this part to create your agent)
97
+ agent = create_llamaindex_agent()
98
+ # try:
99
+ # agent = BasicAgent()
100
+ # except Exception as e:
101
+ # print(f"Error instantiating agent: {e}")
102
+ # return f"Error initializing agent: {e}", None
103
  #In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
104
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
105
  print(agent_code)