Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,38 +18,6 @@ def get_btc_price() -> str:
|
|
| 18 |
if price is None:
|
| 19 |
return '{"error": "Bitcoin price not found"}'
|
| 20 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 21 |
-
@tool
|
| 22 |
-
def get_btc_news() -> Dict[str, Any]:
|
| 23 |
-
"""Fetches the latest Bitcoin news using DuckDuckGo Instant Answer API."""
|
| 24 |
-
search_query = "latest Bitcoin news"
|
| 25 |
-
url = f"https://api.duckduckgo.com/?q={search_query}&format=json"
|
| 26 |
-
response = requests.get(url)
|
| 27 |
-
if response.status_code == 200:
|
| 28 |
-
data = response.json()
|
| 29 |
-
related_topics = data.get('RelatedTopics', [])
|
| 30 |
-
news = [{"title": topic['Text'], "url": topic['FirstURL']} for topic in related_topics if 'Text' in topic and 'FirstURL' in topic]
|
| 31 |
-
return {"news": news}
|
| 32 |
-
else:
|
| 33 |
-
return {"error": "Failed to fetch BTC news"}
|
| 34 |
-
@tool
|
| 35 |
-
def analyze_btc_news(news: str) -> str:
|
| 36 |
-
"""Analyzes the provided Bitcoin news content using the Qwen AI model.
|
| 37 |
-
|
| 38 |
-
Args:
|
| 39 |
-
news (str): The Bitcoin news content to analyze.
|
| 40 |
-
|
| 41 |
-
Returns:
|
| 42 |
-
str: The analysis result of the provided Bitcoin news.
|
| 43 |
-
"""
|
| 44 |
-
model = HfApiModel(
|
| 45 |
-
max_tokens=1048,
|
| 46 |
-
temperature=0.5,
|
| 47 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 48 |
-
custom_role_conversions=None,
|
| 49 |
-
)
|
| 50 |
-
analysis = model.generate(f"Analyze the following Bitcoin news: {news}")
|
| 51 |
-
return analysis
|
| 52 |
-
|
| 53 |
|
| 54 |
final_answer = FinalAnswerTool()
|
| 55 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
@@ -59,7 +27,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 59 |
|
| 60 |
agent = CodeAgent(
|
| 61 |
model=model,
|
| 62 |
-
tools=[
|
| 63 |
max_steps=6,
|
| 64 |
verbosity_level=1,
|
| 65 |
grammar=None,
|
|
|
|
| 18 |
if price is None:
|
| 19 |
return '{"error": "Bitcoin price not found"}'
|
| 20 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
final_answer = FinalAnswerTool()
|
| 23 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 27 |
|
| 28 |
agent = CodeAgent(
|
| 29 |
model=model,
|
| 30 |
+
tools=[get_btc_price, final_answer],
|
| 31 |
max_steps=6,
|
| 32 |
verbosity_level=1,
|
| 33 |
grammar=None,
|