amitpuri commited on
Commit
6786405
1 Parent(s): cb5be95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -13,9 +13,13 @@ openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-
13
  "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
14
  "text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
15
 
 
 
 
16
  def openai_text_completion(prompt: str, model: str):
17
  try:
18
- system_prompt: str = "Explain in detail to help student understand the concept.",
 
19
  assistant_prompt: str = None,
20
 
21
  messages = [
@@ -39,6 +43,37 @@ def openai_text_completion(prompt: str, model: str):
39
  print(exception)
40
  return f" {optionSelection} test_handler Error - {exception}", ""
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def test_handler(optionSelection, prompt: str = TEST_MESSAGE, model: str ="gpt-4"):
43
  match optionSelection:
44
  case "OpenAI API":
 
13
  "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
14
  "text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
15
 
16
+ azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
17
+ azure_deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
18
+
19
  def openai_text_completion(prompt: str, model: str):
20
  try:
21
+ system_prompt: str = "Explain in detail to help student understand the concept.",
22
+
23
  assistant_prompt: str = None,
24
 
25
  messages = [
 
43
  print(exception)
44
  return f" {optionSelection} test_handler Error - {exception}", ""
45
 
46
+ def azure_openai_text_completion(prompt: str, model: str):
47
+ try:
48
+ system_prompt: str = "Explain in detail to help student understand the concept.",
49
+
50
+ assistant_prompt: str = None,
51
+
52
+ messages = [
53
+ {"role": "user", "content": f"{prompt}"},
54
+ {"role": "system", "content": f"{system_prompt}"},
55
+ {"role": "assistant", "content": f"{assistant_prompt}"}
56
+ ]
57
+
58
+ openai.api_key = os.getenv("AZURE_OPENAI_KEY")
59
+ openai.api_type = "azure"
60
+ openai.api_version = "2023-05-15"
61
+ openai.api_base = f"https://{azure_endpoint}.openai.azure.com"
62
+
63
+ completion = openai.ChatCompletion.create(
64
+ model = model,
65
+ engine = azure_deployment_name,
66
+ messages = messages,
67
+ temperature = 0.7
68
+ )
69
+ response = completion["choices"][0]["message"].content
70
+ return "", response
71
+ except openai.error.ServiceUnavailableError:
72
+ print(f"Exception Name: {type(exception).__name__}")
73
+ print(exception)
74
+ return f" {optionSelection} test_handler Error - {exception}", ""
75
+
76
+
77
  def test_handler(optionSelection, prompt: str = TEST_MESSAGE, model: str ="gpt-4"):
78
  match optionSelection:
79
  case "OpenAI API":