File size: 3,080 Bytes
d2f12bd
 
 
94b4765
d2f12bd
 
 
b9a1d0e
d2f12bd
 
 
b9a1d0e
 
d2f12bd
 
 
b9a1d0e
 
 
 
 
d2f12bd
a4e1535
d2f12bd
594fa93
 
 
 
b9a1d0e
d2f12bd
a4e1535
d2f12bd
b9a1d0e
d2f12bd
a4e1535
d2f12bd
b9a1d0e
d2f12bd
b9a1d0e
d2f12bd
b9a1d0e
 
 
 
 
594fa93
d2f12bd
b9a1d0e
d2f12bd
 
4c8be87
b9a1d0e
 
 
c8f549d
b9a1d0e
 
 
 
 
 
 
 
74499d7
4c8be87
 
 
 
 
 
a2830db
 
4c8be87
f4dfbf6
4c8be87
 
 
 
1879cc3
4c8be87
aaa1443
1879cc3
 
4c8be87
d2f12bd
 
94b4765
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
78
79
80
81
82
83
84
85
86
87
88
import openai
import os
from dotenv import load_dotenv
import streamlit as st

load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")


function_descriptions = [
    {
        "name": "extract_info_from_email",
        "description": "categorise & extract key info from an email, such as use case, company name, contact details, etc.",
        "parameters": {
            "type": "object",
            "properties": {
                "companyName": {
                    "type": "string",
                    "description": "the name of the company that sent the email"
                },                                        
                "product": {
                    "type": "string",
                    "description": "Try to identify which product the client is interested in selling or buying, if any"
                },
                "type": {
                    "type": "string",
                    "description": "Try to identify if the email sender is trying to sell a product or wants to buy a product, if any"
                },
                "amount":{
                    "type": "string",
                    "description": "Try to identify the amount of products the client wants to purchase or sell, if any"
                },
                "category": {
                    "type": "string",
                    "description": "Try to categorise this email into categories like those: 1. Sales; 2. customer support; 3. consulting; 4. partnership; 5. Marketing; etc."
                },
                "nextStep":{
                    "type": "string",
                    "description": "What is the suggested next step to move this forward?"
                },
                "priority": {
                    "type": "string",
                    "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"
                },
            },
            "required": ["companyName", "amount", "product", "type","priority", "category", "nextStep"]
        }
    }
]

test_email = """
Dear Jason 
I hope this message finds you well. I'm Shirley from Gucci;

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 person.

Please let me know the price and timeline you can work with;

Looking forward

Shirley Lou
"""

email = st.text_area("Email:",test_email, height=350)

def extract_data(email,function_descriptions):
    prompt = f"Please extract key information from this email: {email} "
    message = [{"role": "user", "content": prompt}]
    
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0613",
        #model="gpt-4",
        messages=message,
        functions = function_descriptions, 
        function_call="auto"
    )

    print(response)
    return response.choices[0]["message"]["function_call"]["arguments"]

if st.button("Extract Data"):
    arguments = extract_data(email,function_descriptions)
    st.json(arguments)