zerito commited on
Commit
b1531aa
·
verified ·
1 Parent(s): c472bd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from smolagents import CodeAgent, HfApiModel, tool
2
  import requests
3
- from requests.exceptions import RequestException # Import request exception handling
4
  from tools.final_answer import FinalAnswerTool
5
  from Gradio_UI import GradioUI
6
  import markdownify
@@ -50,12 +50,32 @@ def visit_webpage(url: str) -> str:
50
  except Exception as e:
51
  return f"An unexpected error occurred: {str(e)}"
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Initialize the FinalAnswerTool
54
  final_answer = FinalAnswerTool()
55
 
56
  # Initialize the model
57
  model = HfApiModel(
58
- max_tokens=1500, # Adjusted to avoid token limit errors
59
  temperature=0.5,
60
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
61
  custom_role_conversions=None,
@@ -64,7 +84,7 @@ model = HfApiModel(
64
  # Create the agent
65
  agent = CodeAgent(
66
  model=model,
67
- tools=[web_search, visit_webpage, final_answer], # Added web_search tool
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,
 
1
  from smolagents import CodeAgent, HfApiModel, tool
2
  import requests
3
+ from requests.exceptions import RequestException # Import for handling request errors
4
  from tools.final_answer import FinalAnswerTool
5
  from Gradio_UI import GradioUI
6
  import markdownify
 
50
  except Exception as e:
51
  return f"An unexpected error occurred: {str(e)}"
52
 
53
+ @tool
54
+ def get_btc_price() -> str:
55
+ """Fetches the current Bitcoin price in USD using the CoinGecko API."""
56
+ url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
57
+ try:
58
+ response = requests.get(url)
59
+ response.raise_for_status()
60
+ data = response.json()
61
+ price = data.get('bitcoin', {}).get('usd')
62
+
63
+ if price is None:
64
+ return '{"error": "Bitcoin price not found"}'
65
+
66
+ return f"The current Bitcoin price is ${price:.2f} USD."
67
+
68
+ except RequestException as e:
69
+ return f"Error fetching Bitcoin price: {str(e)}"
70
+ except Exception as e:
71
+ return f"An unexpected error occurred: {str(e)}"
72
+
73
  # Initialize the FinalAnswerTool
74
  final_answer = FinalAnswerTool()
75
 
76
  # Initialize the model
77
  model = HfApiModel(
78
+ max_tokens=1000, # Adjusted to avoid token limit errors
79
  temperature=0.5,
80
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
81
  custom_role_conversions=None,
 
84
  # Create the agent
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[web_search, visit_webpage, get_btc_price, final_answer], # Added all tools
88
  max_steps=6,
89
  verbosity_level=1,
90
  grammar=None,