zerito commited on
Commit
76b9a8e
·
verified ·
1 Parent(s): 19cb351

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,8 +1,9 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
 
 
6
  @tool
7
  def get_btc_price() -> str:
8
  """Fetches the current Bitcoin price in USD using the CoinGecko API."""
@@ -16,22 +17,28 @@ def get_btc_price() -> str:
16
  return '{"error": "Bitcoin price not found"}'
17
  return f"The current Bitcoin price is ${price:.2f} USD."
18
 
 
19
  @tool
20
  def get_btc_news() -> str:
21
- """Fetches the latest Bitcoin news articles."""
22
  search_query = "latest Bitcoin news"
23
  search_results = DuckDuckGoSearchTool()(search_query)
24
  if not search_results:
25
  return '{"error": "Failed to fetch Bitcoin news"}'
 
 
26
  news_titles = [result['title'] for result in search_results]
27
  news_descriptions = [result['snippet'] for result in search_results]
 
 
28
  news_list = "\n".join([f"**{title}**\n{description}" for title, description in zip(news_titles, news_descriptions)])
 
29
  return f"Here are the latest Bitcoin news articles:\n\n{news_list}"
30
 
31
- # Initialize the FinalAnswerTool
32
  final_answer = FinalAnswerTool()
33
 
34
- # Initialize the model
35
  model = HfApiModel(
36
  max_tokens=2096,
37
  temperature=0.5,
@@ -39,14 +46,10 @@ model = HfApiModel(
39
  custom_role_conversions=None,
40
  )
41
 
42
- # Load additional tools if needed
43
- # For example, to load an image generation tool:
44
- # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
45
-
46
  # Create the agent
47
  agent = CodeAgent(
48
  model=model,
49
- tools=[get_btc_price, get_btc_news, final_answer], # Add your tools here
50
  max_steps=6,
51
  verbosity_level=1,
52
  grammar=None,
@@ -56,5 +59,5 @@ agent = CodeAgent(
56
  prompt_templates=None # Set to None if not using prompt templates
57
  )
58
 
59
- # Launch the Gradio interface
60
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
 
6
+ # Fetch the current Bitcoin price
7
  @tool
8
  def get_btc_price() -> str:
9
  """Fetches the current Bitcoin price in USD using the CoinGecko API."""
 
17
  return '{"error": "Bitcoin price not found"}'
18
  return f"The current Bitcoin price is ${price:.2f} USD."
19
 
20
+ # Fetch the latest Bitcoin news
21
  @tool
22
  def get_btc_news() -> str:
23
+ """Fetches the latest Bitcoin news articles using DuckDuckGoSearchTool."""
24
  search_query = "latest Bitcoin news"
25
  search_results = DuckDuckGoSearchTool()(search_query)
26
  if not search_results:
27
  return '{"error": "Failed to fetch Bitcoin news"}'
28
+
29
+ # Extract titles and meta descriptions from the search results
30
  news_titles = [result['title'] for result in search_results]
31
  news_descriptions = [result['snippet'] for result in search_results]
32
+
33
+ # Format the news list into a readable string
34
  news_list = "\n".join([f"**{title}**\n{description}" for title, description in zip(news_titles, news_descriptions)])
35
+
36
  return f"Here are the latest Bitcoin news articles:\n\n{news_list}"
37
 
38
+ # Initialize the FinalAnswerTool for final response processing
39
  final_answer = FinalAnswerTool()
40
 
41
+ # Initialize the model (Qwen2.5-Coder-32B-Instruct from Hugging Face)
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
 
46
  custom_role_conversions=None,
47
  )
48
 
 
 
 
 
49
  # Create the agent
50
  agent = CodeAgent(
51
  model=model,
52
+ tools=[get_btc_price, get_btc_news, final_answer], # Add the tools here
53
  max_steps=6,
54
  verbosity_level=1,
55
  grammar=None,
 
59
  prompt_templates=None # Set to None if not using prompt templates
60
  )
61
 
62
+ # Launch the Gradio UI for interaction
63
  GradioUI(agent).launch()