pmeyhoefer commited on
Commit
35bdc51
·
verified ·
1 Parent(s): d876082

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -31
app.py CHANGED
@@ -4,7 +4,7 @@ import traceback
4
  import gradio as gr
5
  import requests
6
  import pandas as pd
7
- from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
8
  from smolagents.models import OpenAIServerModel
9
 
10
  # Setup logging
@@ -19,32 +19,6 @@ if not GITHUB_TOKEN:
19
  GITHUB_ENDPOINT = "https://models.github.ai/inference"
20
  MODEL_ID = os.getenv("MODEL_ID", "openai/gpt-4o-mini")
21
 
22
- # Initialize search tool
23
- try:
24
- search_tool_instance = DuckDuckGoSearchTool()
25
- logger.info("DuckDuckGoSearchTool initialized successfully.")
26
- except Exception as e:
27
- logger.error(f"Failed to initialize DuckDuckGoSearchTool: {e}")
28
- search_tool_instance = None
29
-
30
- @tool
31
- def web_search(query: str) -> str:
32
- """
33
- Performs a web search using DuckDuckGo. Use this for general questions or current info.
34
-
35
- Args:
36
- query (str): The search query string.
37
- """
38
- logger.info(f"Searching: '{query[:50]}...'")
39
- if search_tool_instance is None:
40
- return "Search Error: Tool not initialized."
41
- try:
42
- result = search_tool_instance(query=query)
43
- return result[:3000] + "... (truncated)" if len(result) > 3000 else result
44
- except Exception as e:
45
- logger.exception("Search failed")
46
- return f"Search Error: {e}"
47
-
48
  @tool
49
  def wikipedia_lookup(page_title: str) -> str:
50
  """
@@ -75,14 +49,13 @@ def wikipedia_lookup(page_title: str) -> str:
75
  except Exception as e:
76
  return f"Wikipedia Error: {e}"
77
 
78
- # Agent prompt
79
  REACT_INSTRUCTION_PROMPT = """You are a helpful assistant using tools to answer questions.
80
  Available Tools:
81
- - web_search(query: str): Searches the web. Use for general info or current events.
82
  - wikipedia_lookup(page_title: str): Looks up a specific English Wikipedia page. Use exact titles (e.g., 'Berlin').
83
  Follow these steps:
84
  1. Thought: Plan which tool to use and why.
85
- 2. Action: Call ONE tool (e.g., web_search(query="...") or wikipedia_lookup(page_title="...")).
86
  3. Observation: Record the result.
87
  4. Thought: Analyze result. If answered, prepare final answer. If not, plan next step.
88
  5. Repeat Action/Observation/Thought until answered or determined impossible.
@@ -105,7 +78,7 @@ try:
105
  )
106
 
107
  agent = CodeAgent(
108
- tools=[web_search, wikipedia_lookup],
109
  model=llm_model
110
  )
111
  logger.info("Agent initialization complete")
 
4
  import gradio as gr
5
  import requests
6
  import pandas as pd
7
+ from smolagents import CodeAgent, tool
8
  from smolagents.models import OpenAIServerModel
9
 
10
  # Setup logging
 
19
  GITHUB_ENDPOINT = "https://models.github.ai/inference"
20
  MODEL_ID = os.getenv("MODEL_ID", "openai/gpt-4o-mini")
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  @tool
23
  def wikipedia_lookup(page_title: str) -> str:
24
  """
 
49
  except Exception as e:
50
  return f"Wikipedia Error: {e}"
51
 
52
+ # Agent prompt - updated to mention only Wikipedia tool
53
  REACT_INSTRUCTION_PROMPT = """You are a helpful assistant using tools to answer questions.
54
  Available Tools:
 
55
  - wikipedia_lookup(page_title: str): Looks up a specific English Wikipedia page. Use exact titles (e.g., 'Berlin').
56
  Follow these steps:
57
  1. Thought: Plan which tool to use and why.
58
+ 2. Action: Call the tool (e.g., wikipedia_lookup(page_title="...")).
59
  3. Observation: Record the result.
60
  4. Thought: Analyze result. If answered, prepare final answer. If not, plan next step.
61
  5. Repeat Action/Observation/Thought until answered or determined impossible.
 
78
  )
79
 
80
  agent = CodeAgent(
81
+ tools=[wikipedia_lookup], # Only Wikipedia tool
82
  model=llm_model
83
  )
84
  logger.info("Agent initialization complete")