Update app.py
Browse files
app.py
CHANGED
|
@@ -12,33 +12,36 @@ openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-
|
|
| 12 |
"gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
|
| 13 |
"text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def test_handler(optionSelection, prompt: str = TEST_MESSAGE, model: str ="gpt-4"):
|
| 16 |
match optionSelection:
|
| 17 |
case "OpenAI API":
|
| 18 |
-
|
| 19 |
-
system_prompt: str = "Explain in detail to help student understand the concept.",
|
| 20 |
-
assistant_prompt: str = None,
|
| 21 |
-
|
| 22 |
-
messages = [
|
| 23 |
-
{"role": "user", "content": f"{prompt}"},
|
| 24 |
-
{"role": "system", "content": f"{system_prompt}"},
|
| 25 |
-
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 29 |
-
openai.api_version = '2020-11-07'
|
| 30 |
-
|
| 31 |
-
completion = openai.ChatCompletion.create(
|
| 32 |
-
model = model,
|
| 33 |
-
messages = messages,
|
| 34 |
-
temperature = 0.7
|
| 35 |
-
)
|
| 36 |
-
response = completion["choices"][0]["message"].content
|
| 37 |
-
return "", response
|
| 38 |
-
except openai.error.ServiceUnavailableError:
|
| 39 |
-
print(f"Exception Name: {type(exception).__name__}")
|
| 40 |
-
print(exception)
|
| 41 |
-
return f" {optionSelection} test_handler Error - {exception}", ""
|
| 42 |
case "Azure OpenAI API":
|
| 43 |
return "", ""
|
| 44 |
case "Google PaLM API":
|
|
|
|
| 12 |
"gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
|
| 13 |
"text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
|
| 14 |
|
| 15 |
+
def openai_text_completion(prompt: str, model: str):
|
| 16 |
+
try:
|
| 17 |
+
system_prompt: str = "Explain in detail to help student understand the concept.",
|
| 18 |
+
assistant_prompt: str = None,
|
| 19 |
+
|
| 20 |
+
messages = [
|
| 21 |
+
{"role": "user", "content": f"{prompt}"},
|
| 22 |
+
{"role": "system", "content": f"{system_prompt}"},
|
| 23 |
+
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 27 |
+
openai.api_version = '2020-11-07'
|
| 28 |
+
|
| 29 |
+
completion = openai.ChatCompletion.create(
|
| 30 |
+
model = model,
|
| 31 |
+
messages = messages,
|
| 32 |
+
temperature = 0.7
|
| 33 |
+
)
|
| 34 |
+
response = completion["choices"][0]["message"].content
|
| 35 |
+
return "", response
|
| 36 |
+
except openai.error.ServiceUnavailableError:
|
| 37 |
+
print(f"Exception Name: {type(exception).__name__}")
|
| 38 |
+
print(exception)
|
| 39 |
+
return f" {optionSelection} test_handler Error - {exception}", ""
|
| 40 |
+
|
| 41 |
def test_handler(optionSelection, prompt: str = TEST_MESSAGE, model: str ="gpt-4"):
|
| 42 |
match optionSelection:
|
| 43 |
case "OpenAI API":
|
| 44 |
+
openai_text_completion(prompt,model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
case "Azure OpenAI API":
|
| 46 |
return "", ""
|
| 47 |
case "Google PaLM API":
|