Spaces:
Runtime error
Runtime error
| #user_query = """ | |
| #which stock in the market has the highest price movement today? | |
| #Summarise the latest news to analyse the potential cause and add it to my airtable data. | |
| #""" | |
| import openai | |
| import os | |
| import json | |
| from dotenv import load_dotenv | |
| from pyairtable import Table | |
| import requests | |
| load_dotenv() | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| #rapid_api_key = os.getenv("X-RapidAPI-Key") | |
| #airtable_api_key = os.getenv("AIRTABLE_API_KEY") | |
| #table = Table(airtable_api_key, "appHojHIE4y8gVBgc", "tbldUUKZFngr78ogg") | |
| function_descriptions = [ | |
| { | |
| "name": "get_stock_movers", | |
| "description": "Get the stocks that has biggest price/volume moves, e.g. actives, gainers, losers, etc.", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| }, | |
| } | |
| }, | |
| { | |
| "name": "get_stock_news", | |
| "description": "Get the latest news for a stock", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "performanceId": { | |
| "type": "string", | |
| "description": "id of the stock, which is referred as performanceID in the API" | |
| }, | |
| }, | |
| "required": ["performanceId"] | |
| } | |
| }, | |
| { | |
| "name": "add_stock_news_airtable", | |
| "description": "Add the stock, news summary & price move to Airtable", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "stock": { | |
| "type": "string", | |
| "description": "stock ticker" | |
| }, | |
| "move": { | |
| "type": "string", | |
| "description": "price move in %" | |
| }, | |
| "news_summary": { | |
| "type": "string", | |
| "description": "news summary of the stock" | |
| }, | |
| } | |
| } | |
| }, | |
| ] | |
| query = "Give me a summary of what happend to the tesla stock today?" | |
| messages = [{"role":"user", "content":query}] | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| messages=messages, | |
| functions = function_descriptions, | |
| function_call="auto" | |
| ) | |
| print(response) | |