Spaces:
Runtime error
Runtime error
Commit
·
b0da33a
1
Parent(s):
8438112
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
#from pyairtable import Table
|
| 6 |
+
import requests
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
+
rapid_api_key = os.getenv("X-RapidAPI-Key")
|
| 12 |
+
#airtable_api_key = os.getenv("AIRTABLE_API_KEY")
|
| 13 |
+
#table = Table(airtable_api_key, "appHojHIE4y8gVBgc", "tbldUUKZFngr78ogg")
|
| 14 |
+
|
| 15 |
+
function_descriptions = [
|
| 16 |
+
{
|
| 17 |
+
"name": "get_stock_movers",
|
| 18 |
+
"description": "Get the stocks that has biggest price/volume moves, e.g. actives, gainers, losers, etc.",
|
| 19 |
+
"parameters": {
|
| 20 |
+
"type": "object",
|
| 21 |
+
"properties": {
|
| 22 |
+
},
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "get_stock_news",
|
| 27 |
+
"description": "Get the latest news for a stock",
|
| 28 |
+
"parameters": {
|
| 29 |
+
"type": "object",
|
| 30 |
+
"properties": {
|
| 31 |
+
"performanceId": {
|
| 32 |
+
"type": "string",
|
| 33 |
+
"description": "id of the stock, which is referred as performanceID in the API"
|
| 34 |
+
},
|
| 35 |
+
},
|
| 36 |
+
"required": ["performanceId"]
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"name": "add_stock_news_airtable",
|
| 41 |
+
"description": "Add the stock, news summary & price move to Airtable",
|
| 42 |
+
"parameters": {
|
| 43 |
+
"type": "object",
|
| 44 |
+
"properties": {
|
| 45 |
+
"stock": {
|
| 46 |
+
"type": "string",
|
| 47 |
+
"description": "stock ticker"
|
| 48 |
+
},
|
| 49 |
+
"move": {
|
| 50 |
+
"type": "string",
|
| 51 |
+
"description": "price move in %"
|
| 52 |
+
},
|
| 53 |
+
"news_summary": {
|
| 54 |
+
"type": "string",
|
| 55 |
+
"description": "news summary of the stock"
|
| 56 |
+
},
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
query = "Give me a summary of what happend to the tesla stocks today?"
|
| 63 |
+
messages = [{"role":"user","content":query}]
|
| 64 |
+
|
| 65 |
+
response = openai.ChatCompletion.create(
|
| 66 |
+
model="gpt-3.5-turbo-0613",
|
| 67 |
+
messages=messages,
|
| 68 |
+
functions = function_descriptions,
|
| 69 |
+
function_call="auto"
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
st.subheader(response)
|