eong commited on
Commit
ba5e858
·
verified ·
1 Parent(s): 2744ebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -52
app.py CHANGED
@@ -42,7 +42,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
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')
@@ -57,65 +57,65 @@ def crypto_analysis(crypto_name: str) -> str:
57
  response = requests.get(url)
58
  response.raise_for_status() # Raise exception for bad status codes
59
  data = response.json()
 
 
 
 
 
60
 
61
- # Search for news related to crypto
62
- search_tool = DuckDuckGoSearchTool()
63
 
64
- try:
65
- crypto_info = data['data']
66
- # Extract key metrics for analysis
67
- price = float(crypto_info["priceUsd"])
68
- market_cap = float(crypto_info["marketCapUsd"])
69
- volume_24h = float(crypto_info["volumeUsd24Hr"])
70
- change_24h = float(crypto_info["changePercent24Hr"])
71
 
72
- # Targeted search for information
73
- queries = [
74
- f"{crypto_info['name']} price movement reasons",
75
- f"{crypto_info['name']} market analysis",
76
- f"{crypto_info['name']} future predictions",
77
- f"{crypto_info['name']} recent developments"
78
- ]
79
 
80
- # Fetch relevant information from search
81
- search_results = {}
82
- for query in queries:
83
- search_results[query] = search_tool(query)
84
 
85
- # Compile final results
86
- analysis = {
87
- "basic_info": {
88
- "name": crypto_info["name"],
89
- "symbol": crypto_info["symbol"],
90
- "current_price_usd": price,
91
- "market_cap_usd": market_cap,
92
- "rank": int(crypto_info["rank"]),
93
- },
94
- "technical_indicators": {
95
- "24h_change_percent": change_24h,
96
- "24h_volume_usd": volume_24h,
97
- "supply_info": {
98
- "current_supply": float(crypto_info["supply"]),
99
- "max_supply": float(crypto_info["maxSupply"]) if crypto_info.get("maxSupply") else None,
100
- "percent_of_max_issued": (float(crypto_info["supply"]) / float(crypto_info["maxSupply"]) * 100)
101
- if crypto_info.get("maxSupply") else None
102
- }
103
- },
104
- "market_sentiment": {
105
- "recent_news": search_results,
106
- "sentiment_indicator": "positive" if change_24h > 0 else "negative",
107
- }
108
- }
109
 
110
- return json.dumps(analysis)
111
 
112
- except KeyError as error:
113
- return f"Error: Failed to parse cryptocurrency data: {str(error)}"
114
- except ValueError as error:
115
- return f"Error: Failed to process values in cryptocurrency data: {str(error)}"
116
 
117
- except requests.exceptions.RequestException as e:
118
- return f"Error: API request failed: {str(e)}"
119
 
120
  final_answer = FinalAnswerTool()
121
 
 
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 perform crypto analysis.
46
 
47
  Args:
48
  crypto_name: The crypto currency id (e.g., 'bitcoin')
 
57
  response = requests.get(url)
58
  response.raise_for_status() # Raise exception for bad status codes
59
  data = response.json()
60
+ return data
61
+
62
+ except requests.exceptions.RequestException as e:
63
+ raise f"Error: {str(e)}"
64
+
65
 
 
 
66
 
67
+ # crypto_info = data['data']
68
+ # # Extract key metrics for analysis
69
+ # price = float(crypto_info["priceUsd"])
70
+ # market_cap = float(crypto_info["marketCapUsd"])
71
+ # volume_24h = float(crypto_info["volumeUsd24Hr"])
72
+ # change_24h = float(crypto_info["changePercent24Hr"])
 
73
 
74
+ # # Targeted search for information
75
+ # queries = [
76
+ # f"{crypto_info['name']} price movement reasons",
77
+ # f"{crypto_info['name']} market analysis",
78
+ # f"{crypto_info['name']} future predictions",
79
+ # f"{crypto_info['name']} recent developments"
80
+ # ]
81
 
82
+ # # Fetch relevant information from search
83
+ # search_results = {}
84
+ # for query in queries:
85
+ # search_results[query] = search_tool(query)
86
 
87
+ # # Compile final results
88
+ # analysis = {
89
+ # "basic_info": {
90
+ # "name": crypto_info["name"],
91
+ # "symbol": crypto_info["symbol"],
92
+ # "current_price_usd": price,
93
+ # "market_cap_usd": market_cap,
94
+ # "rank": int(crypto_info["rank"]),
95
+ # },
96
+ # "technical_indicators": {
97
+ # "24h_change_percent": change_24h,
98
+ # "24h_volume_usd": volume_24h,
99
+ # "supply_info": {
100
+ # "current_supply": float(crypto_info["supply"]),
101
+ # "max_supply": float(crypto_info["maxSupply"]) if crypto_info.get("maxSupply") else None,
102
+ # "percent_of_max_issued": (float(crypto_info["supply"]) / float(crypto_info["maxSupply"]) * 100)
103
+ # if crypto_info.get("maxSupply") else None
104
+ # }
105
+ # },
106
+ # "market_sentiment": {
107
+ # "recent_news": search_results,
108
+ # "sentiment_indicator": "positive" if change_24h > 0 else "negative",
109
+ # }
110
+ # }
111
 
112
+ # return json.dumps(analysis)
113
 
114
+ # except ValueError as error:
115
+ # return f"Error: Failed to process values in cryptocurrency data: {str(error)}"
 
 
116
 
117
+ # except requests.exceptions.RequestException as e:
118
+ # return f"Error: API request failed: {str(e)}"
119
 
120
  final_answer = FinalAnswerTool()
121