File size: 966 Bytes
2bf5d9d
6d7dbcd
2bf5d9d
3c1ac4e
2bf5d9d
3c1ac4e
2bf5d9d
3c1ac4e
 
 
 
 
 
6d7dbcd
2bf5d9d
3c1ac4e
 
 
2bf5d9d
 
 
b4eff0d
2bf5d9d
 
 
 
6d821b7
 
 
3c1ac4e
 
 
6d821b7
 
 
 
 
 
3708b8e
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
import openai
import streamlit as st

# from dotenv import dotenv_values

# config = dotenv_values(".env")

# if config:
#     openai.organization = config.get('OPENAI_ORGANIZATION')
#     openai.api_key = config.get('OPENAI_API_KEY')
# else:
#     openai.organization = st.secrets['OPENAI_ORGANIZATION']
#     openai.api_key = st.secrets['OPENAI_API_KEY']


def gpt_call(api_key, prompt, role="user"):

    openai.api_key = api_key
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
                    {"role": role, "content": prompt},
                ]
    )
    output_text = response["choices"][0]["message"]["content"]

    return output_text


def gpt_call_context(api_key, messages):
    
    openai.api_key = api_key
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages
    )
    output_text = response["choices"][0]["message"]["content"]

    return output_text