biaotang commited on
Commit
612313f
·
1 Parent(s): 307ffe3

Put retriever and tools together

Browse files
Files changed (2) hide show
  1. app.py +20 -5
  2. tools.py +1 -10
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import os
3
  from smolagents import CodeAgent, HfApiModel, LiteLLMModel
4
  from retriever import load_guest_dataset
5
- from tools import *
6
 
7
  is_running_on_space = os.environ.get('SPACE_ID') is not None
8
  if is_running_on_space:
@@ -13,11 +13,24 @@ else:
13
  api_base="http://127.0.0.1:11434",
14
  num_ctx=8192,)
15
 
16
- # guest_info_tool = load_guest_dataset()
17
 
18
- # Create Alfred, our gala agent, with the guest info tool
19
- alfred = CodeAgent(tools=[hub_stats_tool, search_tool, weather_info_tool], model=model)
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def query_guest(guest_name):
23
  return alfred.run(f"Tell me about our guest named '{guest_name}'.")
@@ -25,6 +38,8 @@ def query_guest(guest_name):
25
  def ai_builder(builder):
26
  return alfred.run(f"What is {builder} most downloaded model on huggingface hub?")
27
 
 
 
28
 
29
- demo = gr.Interface(fn=ai_builder, inputs="text", outputs="text")
30
  demo.launch()
 
2
  import os
3
  from smolagents import CodeAgent, HfApiModel, LiteLLMModel
4
  from retriever import load_guest_dataset
5
+ from tools import DuckDuckGoSearchTool, WeatherInfoTool, HubStatsTool
6
 
7
  is_running_on_space = os.environ.get('SPACE_ID') is not None
8
  if is_running_on_space:
 
13
  api_base="http://127.0.0.1:11434",
14
  num_ctx=8192,)
15
 
16
+ guest_info_tool = load_guest_dataset()
17
 
18
+ # Initialize the web search tool
19
+ search_tool = DuckDuckGoSearchTool()
20
+
21
+ # Initialize the weather tool
22
+ weather_info_tool = WeatherInfoTool()
23
 
24
+ # Initialize the Hub stats tool
25
+ hub_stats_tool = HubStatsTool()
26
+
27
+ # Create Alfred, our gala agent, with the guest info tool
28
+ alfred = CodeAgent(
29
+ tools=[guest_info_tool, hub_stats_tool, weather_info_tool, search_tool],
30
+ model=model,
31
+ add_base_tools=True,
32
+ planning_interval=3
33
+ )
34
 
35
  def query_guest(guest_name):
36
  return alfred.run(f"Tell me about our guest named '{guest_name}'.")
 
38
  def ai_builder(builder):
39
  return alfred.run(f"What is {builder} most downloaded model on huggingface hub?")
40
 
41
+ def query(query):
42
+ return alfred.run(query)
43
 
44
+ demo = gr.Interface(fn=query, inputs="text", outputs="text")
45
  demo.launch()
tools.py CHANGED
@@ -1,10 +1,7 @@
1
  from huggingface_hub import list_models
2
- from smolagents import DuckDuckGoSearchTool, Tool
3
  import random
4
 
5
- # Initialize the DuckDuckGo search tool
6
- search_tool = DuckDuckGoSearchTool()
7
-
8
  class WeatherInfoTool(Tool):
9
  name = "weather_info"
10
  description = "Fetches dummy weather information for a given location."
@@ -27,9 +24,6 @@ class WeatherInfoTool(Tool):
27
  data = random.choice(weather_conditions)
28
  return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
29
 
30
- # Initialize the tool
31
- weather_info_tool = WeatherInfoTool()
32
-
33
  class HubStatsTool(Tool):
34
  name = "hub_stats"
35
  description = "Fetches the most downloaded model from a specific author on the Hugging Face Hub."
@@ -53,6 +47,3 @@ class HubStatsTool(Tool):
53
  return f"No models found for author {author}."
54
  except Exception as e:
55
  return f"Error fetching models for {author}: {str(e)}"
56
-
57
- # Initialize the tool
58
- hub_stats_tool = HubStatsTool()
 
1
  from huggingface_hub import list_models
2
+ from smolagents import Tool, DuckDuckGoSearchTool
3
  import random
4
 
 
 
 
5
  class WeatherInfoTool(Tool):
6
  name = "weather_info"
7
  description = "Fetches dummy weather information for a given location."
 
24
  data = random.choice(weather_conditions)
25
  return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
26
 
 
 
 
27
  class HubStatsTool(Tool):
28
  name = "hub_stats"
29
  description = "Fetches the most downloaded model from a specific author on the Hugging Face Hub."
 
47
  return f"No models found for author {author}."
48
  except Exception as e:
49
  return f"Error fetching models for {author}: {str(e)}"