File size: 2,266 Bytes
d2f12bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#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)