qver3nc1a commited on
Commit
07c0fb4
·
verified ·
1 Parent(s): 6aecd1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -29,27 +29,35 @@ def wikipedia_search(query: str) -> str:
29
 
30
  # --- Basic Agent Definition ---
31
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
32
- class BasicAgent:
33
- def __init__(self):
34
- print('BasicAgent initialized.')
35
-
36
- def __call__(self, question: str) -> str:
37
- print(f"Agent received question: {question[:50]}...")
38
 
39
- web_search_tool = ToolNode([DuckDuckGoSearchRun().run])
40
- open_webpage_tool = ToolNode([wikipedia_search])
 
41
 
42
- agent = ToolCallingAgent(
43
- tools=[web_search_tool, open_webpage_tool],
 
 
 
 
44
  model=LiteLLMModel(
45
- model_id="ollama/qwen2:7b",
46
- api_base='http://192.168.1.77:11434'
47
  ),
48
  max_steps=15,
49
  verbosity_level=2,
50
  )
51
 
52
- return agent.run(question)
 
 
 
 
 
 
53
 
54
  def run_and_submit_all( profile: gr.OAuthProfile | None):
55
  """
 
29
 
30
  # --- Basic Agent Definition ---
31
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
32
+ def web_search(query: str):
33
+ """Search the web for information."""
34
+ return DuckDuckGoSearchRun().run(query)
 
 
 
35
 
36
+ def wikipedia_search(query: str):
37
+ """Search Wikipedia for information."""
38
+ return wikipedia.run(query)
39
 
40
+ class BasicAgent:
41
+ def __init__(self, model_id="ollama/qwen2:7b", api_base="http://192.168.1.77:11434"):
42
+ print('BasicAgent initialized.')
43
+ self.tool_node = ToolNode([web_search, wikipedia_search])
44
+ self.agent = ToolCallingAgent(
45
+ tools=[self.tool_node],
46
  model=LiteLLMModel(
47
+ model_id=model_id,
48
+ api_base=api_base
49
  ),
50
  max_steps=15,
51
  verbosity_level=2,
52
  )
53
 
54
+ def __call__(self, question: str) -> str:
55
+ print(f"Agent received question: {question[:50]}...")
56
+ try:
57
+ return self.agent.run(question)
58
+ except Exception as e:
59
+ print(f"Error in agent: {e}")
60
+ return f"AGENT ERROR: {e}"
61
 
62
  def run_and_submit_all( profile: gr.OAuthProfile | None):
63
  """