File size: 1,525 Bytes
2872c06
b69e49a
2872c06
f5cb579
2872c06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import streamlit as st

openai.api_key = st.secrets['OPENAI_API_KEY']

class gpt_api:

    @staticmethod
    def set_use_model_name(use_model_name):
        if not ('global_gpt_model_name' in locals() or 'global_gpt_model_name' in globals()):
            global global_gpt_model_name
        global_gpt_model_name=use_model_name

    #####################################################
    # GPT call
    #####################################################
    @staticmethod
    def gpt_call(
            system_prompt,
            user_prompt
        ):
        if not ('global_gpt_model_name' in locals() or 'global_gpt_model_name' in globals()):
            global global_gpt_model_name
            
            # global_gpt_model_name = "gpt-3.5-turbo"
            global_gpt_model_name = "gpt-4"

        response = openai.ChatCompletion.create(
            model=global_gpt_model_name,
            messages=[
                        {
                            "role": "system",
                            "content": system_prompt
                        },
                        {
                            "role": "user",
                            "content": user_prompt
                        }
            ],
            # temperature=1.5,
            # top_p=0.4,
            # presence_penalty=1.5,
            # frequency_penalty=1.5
        )
        output_text = response["choices"][0]["message"]["content"]

        # print("output_text", output_text)

        return output_text