eong commited on
Commit
85021fb
·
verified ·
1 Parent(s): 332e135

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -14
app.py CHANGED
@@ -40,26 +40,85 @@ def get_current_time_in_timezone(timezone: str) -> str:
40
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
41
 
42
  @tool
43
- def find_your_bible_charatcer(subject: str) -> str:
44
- """This tool performs a web search for your favorite bible character and return summary of their life and calling
 
 
45
  Args:
46
- subject: The name of the bible character to summarize their life and calling.
 
 
 
 
47
  """
48
- search_tool = DuckDuckGoSearchTool()
49
- combination = None
 
50
 
 
51
  try:
52
- results = search_tool(f"Summarize the life of the following bible character {subject} and what was their call or mandate. Relate this character with famous figure and show similaries")
 
 
53
 
54
- if results and len(results) > 0:
55
- combination = results
56
- return f"🦋🦋 Here's is the summary of the life and calling of {subject}: {combination}"
57
 
58
- return f"Sorry, I couldn't find any information for {subject}."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- except Exception as e:
61
- return f"Sorry, I couldn't find any information {subject}. Error: {str(e)}"
62
-
63
 
64
  final_answer = FinalAnswerTool()
65
 
@@ -83,7 +142,7 @@ with open("prompts.yaml", 'r') as stream:
83
 
84
  agent = CodeAgent(
85
  model=model,
86
- tools=[final_answer,find_your_bible_charatcer,image_generation_tool], ## add your tools here (don't remove final answer)
87
  max_steps=6,
88
  verbosity_level=1,
89
  grammar=None,
 
40
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
41
 
42
  @tool
43
+ def crypto_analysis(crypto_name: str) -> str:
44
+ """
45
+ Fetches current cryptocurrency data for a given crypto currency name use the data extracted to combine with web search to perform crypto analysis.
46
+
47
  Args:
48
+ crypto_name: The crypto currency id (e.g., 'bitcoin')
49
+
50
+ Returns:
51
+ A JSON-formatted string containing the crypto analysis if successful,
52
+ otherwise an error message
53
  """
54
+ import os
55
+ import json
56
+ import requests
57
 
58
+ url = f"https://rest.coincap.io/v3/assets/{crypto_name}?apiKey={os.getenv(key='coin_api')}"
59
  try:
60
+ response = requests.get(url)
61
+ response.raise_for_status() # Raise exception for bad status codes
62
+ data = response.json()
63
 
64
+ # Search for news related to crypto
65
+ search_tool = DuckDuckGoSearchTool()
 
66
 
67
+ try:
68
+ crypto_info = data['data']
69
+ # Extract key metrics for analysis
70
+ price = float(crypto_info["priceUsd"])
71
+ market_cap = float(crypto_info["marketCapUsd"])
72
+ volume_24h = float(crypto_info["volumeUsd24Hr"])
73
+ change_24h = float(crypto_info["changePercent24Hr"])
74
+
75
+ # Targeted search for information
76
+ queries = [
77
+ f"{crypto_info['name']} price movement reasons",
78
+ f"{crypto_info['name']} market analysis",
79
+ f"{crypto_info['name']} future predictions",
80
+ f"{crypto_info['name']} recent developments"
81
+ ]
82
+
83
+ # Fetch relevant information from search
84
+ search_results = {}
85
+ for query in queries:
86
+ search_results[query] = search_tool(query)
87
+
88
+ # Compile final results
89
+ analysis = {
90
+ "basic_info": {
91
+ "name": crypto_info["name"],
92
+ "symbol": crypto_info["symbol"],
93
+ "current_price_usd": price,
94
+ "market_cap_usd": market_cap,
95
+ "rank": int(crypto_info["rank"]),
96
+ },
97
+ "technical_indicators": {
98
+ "24h_change_percent": change_24h,
99
+ "24h_volume_usd": volume_24h,
100
+ "supply_info": {
101
+ "current_supply": float(crypto_info["supply"]),
102
+ "max_supply": float(crypto_info["maxSupply"]) if crypto_info.get("maxSupply") else None,
103
+ "percent_of_max_issued": (float(crypto_info["supply"]) / float(crypto_info["maxSupply"]) * 100)
104
+ if crypto_info.get("maxSupply") else None
105
+ }
106
+ },
107
+ "market_sentiment": {
108
+ "recent_news": search_results,
109
+ "sentiment_indicator": "positive" if change_24h > 0 else "negative",
110
+ }
111
+ }
112
+
113
+ return json.dumps(analysis)
114
+
115
+ except KeyError as error:
116
+ return f"Error: Failed to parse cryptocurrency data: {str(error)}"
117
+ except ValueError as error:
118
+ return f"Error: Failed to process values in cryptocurrency data: {str(error)}"
119
 
120
+ except requests.exceptions.RequestException as e:
121
+ return f"Error: API request failed: {str(e)}"
 
122
 
123
  final_answer = FinalAnswerTool()
124
 
 
142
 
143
  agent = CodeAgent(
144
  model=model,
145
+ tools=[final_answer,crypto_analysis], ## add your tools here (don't remove final answer)
146
  max_steps=6,
147
  verbosity_level=1,
148
  grammar=None,