Shrikrishna commited on
Commit
53f2ac0
1 Parent(s): b0da33a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -59,6 +59,48 @@ function_descriptions = [
59
  },
60
  ]
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  query = "Give me a summary of what happend to the tesla stocks today?"
63
  messages = [{"role":"user","content":query}]
64
 
 
59
  },
60
  ]
61
 
62
+ def get_stock_news(performanceId):
63
+ url = "https://morning-star.p.rapidapi.com/news/list"
64
+
65
+ querystring = {"performanceId":performanceId}
66
+
67
+ headers = {
68
+ "X-RapidAPI-Key": rapid_api_key,
69
+ "X-RapidAPI-Host": "morning-star.p.rapidapi.com"
70
+ }
71
+
72
+ response = requests.get(url, headers=headers, params=querystring)
73
+
74
+ short_news_list = response.json()[:5]
75
+
76
+ print("response:", response, " json response:", short_news_list)
77
+
78
+ return short_news_list
79
+
80
+ def get_stock_movers():
81
+ url = "https://morning-star.p.rapidapi.com/market/v2/get-movers"
82
+
83
+ headers = {
84
+ "X-RapidAPI-Key": rapid_api_key,
85
+ "X-RapidAPI-Host": "morning-star.p.rapidapi.com"
86
+ }
87
+
88
+ response = requests.get(url, headers=headers)
89
+
90
+ return response.json()
91
+
92
+ def function_call(ai_response):
93
+ function_call = ai_response["choices"][0]["message"]["function_call"]
94
+ function_name = function_call["name"]
95
+ arguments = function_call["arguments"]
96
+ if function_name == "get_stock_movers":
97
+ return get_stock_movers()
98
+ elif function_name == "get_stock_news":
99
+ performanceId = eval(arguments).get("performanceId")
100
+ return get_stock_news(performanceId)
101
+ else:
102
+ return
103
+
104
  query = "Give me a summary of what happend to the tesla stocks today?"
105
  messages = [{"role":"user","content":query}]
106