Spaces:
Runtime error
Runtime error
Shrikrishna
commited on
Commit
•
b9a1d0e
1
Parent(s):
101288c
Update app.py
Browse files
app.py
CHANGED
@@ -1,80 +1,69 @@
|
|
1 |
-
#user_query = """
|
2 |
-
#which stock in the market has the highest price movement today?
|
3 |
-
#Summarise the latest news to analyse the potential cause and add it to my airtable data.
|
4 |
-
#"""
|
5 |
-
|
6 |
import openai
|
7 |
import os
|
8 |
-
import json
|
9 |
from dotenv import load_dotenv
|
10 |
-
from pyairtable import Table
|
11 |
-
import requests
|
12 |
-
import streamlit as st
|
13 |
|
14 |
load_dotenv()
|
15 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
16 |
-
|
17 |
-
#airtable_api_key = os.getenv("AIRTABLE_API_KEY")
|
18 |
-
#table = Table(airtable_api_key, "appHojHIE4y8gVBgc", "tbldUUKZFngr78ogg")
|
19 |
|
20 |
function_descriptions = [
|
21 |
{
|
22 |
-
"name": "
|
23 |
-
"description": "
|
24 |
-
"parameters": {
|
25 |
-
"type": "object",
|
26 |
-
"properties": {
|
27 |
-
},
|
28 |
-
}
|
29 |
-
},
|
30 |
-
{
|
31 |
-
"name": "get_stock_news",
|
32 |
-
"description": "Get the latest news for a stock",
|
33 |
"parameters": {
|
34 |
"type": "object",
|
35 |
"properties": {
|
36 |
-
"
|
|
|
|
|
|
|
|
|
37 |
"type": "string",
|
38 |
-
"description": "
|
39 |
},
|
40 |
-
|
41 |
-
"required": ["performanceId"]
|
42 |
-
}
|
43 |
-
},
|
44 |
-
{
|
45 |
-
"name": "add_stock_news_airtable",
|
46 |
-
"description": "Add the stock, news summary & price move to Airtable",
|
47 |
-
"parameters": {
|
48 |
-
"type": "object",
|
49 |
-
"properties": {
|
50 |
-
"stock": {
|
51 |
"type": "string",
|
52 |
-
"description": "
|
53 |
},
|
54 |
-
"
|
55 |
"type": "string",
|
56 |
-
"description": "
|
57 |
},
|
58 |
-
"
|
59 |
"type": "string",
|
60 |
-
"description": "
|
61 |
},
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
-
}
|
65 |
]
|
66 |
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
response = openai.ChatCompletion.create(
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
|
77 |
print(response)
|
78 |
-
|
79 |
-
st.header("Start:")
|
80 |
-
st.header(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import openai
|
2 |
import os
|
|
|
3 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
4 |
|
5 |
load_dotenv()
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
+
|
|
|
|
|
8 |
|
9 |
function_descriptions = [
|
10 |
{
|
11 |
+
"name": "extract_info_from_email",
|
12 |
+
"description": "categorise & extract key info from an email, such as use case, company name, contact details, etc.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"parameters": {
|
14 |
"type": "object",
|
15 |
"properties": {
|
16 |
+
"companyName": {
|
17 |
+
"type": "string",
|
18 |
+
"description": "the name of the company that sent the email"
|
19 |
+
},
|
20 |
+
"product": {
|
21 |
"type": "string",
|
22 |
+
"description": "Try to identify which product the client is interested in, if any"
|
23 |
},
|
24 |
+
"amount":{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
"type": "string",
|
26 |
+
"description": "Try to identify the amount of products the client wants to purchase, if any"
|
27 |
},
|
28 |
+
"category": {
|
29 |
"type": "string",
|
30 |
+
"description": "Try to categorise this email into categories like those: 1. Sales 2. customer support; 3. consulting; 4. partnership; etc."
|
31 |
},
|
32 |
+
"nextStep":{
|
33 |
"type": "string",
|
34 |
+
"description": "What is the suggested next step to move this forward?"
|
35 |
},
|
36 |
+
"priority": {
|
37 |
+
"type": "string",
|
38 |
+
"description": "Try to give a priority score to this email based on how likely this email will leads to a good business opportunity, from 0 to 10; 10 most important"
|
39 |
+
},
|
40 |
+
},
|
41 |
+
"required": ["companyName", "amount", "product", "priority", "category", "nextStep"]
|
42 |
}
|
43 |
+
}
|
44 |
]
|
45 |
|
46 |
+
email = """
|
47 |
+
Dear Jason
|
48 |
+
I hope this message finds you well. I'm Shirley from Gucci;
|
49 |
+
|
50 |
+
I'm looking to purchase some company T-shirt for my team, we are a team of 100k people, and we want to get 2 t-shirt per personl
|
51 |
+
|
52 |
+
Please let me know the price and timeline you can work with;
|
53 |
+
|
54 |
+
Looking forward
|
55 |
+
|
56 |
+
Shirley Lou
|
57 |
+
"""
|
58 |
+
|
59 |
+
prompt = f"Please extract key information from this email: {email} "
|
60 |
+
message = [{"role": "user", "content": prompt}]
|
61 |
|
62 |
response = openai.ChatCompletion.create(
|
63 |
+
model="gpt-3.5-turbo",
|
64 |
+
messages=message,
|
65 |
+
functions = function_descriptions,
|
66 |
+
function_call="auto"
|
67 |
+
)
|
68 |
|
69 |
print(response)
|
|
|
|
|
|