amitpuri commited on
Commit
7676b1c
1 Parent(s): 7f1cae9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -25
app.py CHANGED
@@ -8,31 +8,36 @@ import openai
8
 
9
  llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
10
  TEST_MESSAGE = "My favorite TV shows are The Mentalist, The Blacklist, Designated Survivor, and Unforgettable. What are ten series that I should watch next?"
 
 
 
11
 
12
  def test_handler(optionSelection, prompt: str = "Write an introductory paragraph to explain Generative AI to the reader of this content."):
13
  match optionSelection:
14
  case "OpenAI API":
15
- #model = "gpt-35-turbo"
16
- model = "gpt-4"
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
  case "Azure OpenAI API":
37
  return "", ""
38
  case "Google PaLM API":
@@ -48,10 +53,15 @@ def test_handler(optionSelection, prompt: str = "Write an introductory paragraph
48
  with gr.Blocks() as LLMDemoTabbedScreen:
49
  with gr.Tab("Text-to-Text (Text Completion)"):
50
  llm_options = gr.Radio(llm_api_options, label="Select one", info="Which service do you want to use?", value="OpenAI API")
51
- test_string = gr.Textbox(label="Try String", value=TEST_MESSAGE, lines=2)
52
- test_string_response = gr.Textbox(label="Response")
53
- test_string_output_info = gr.Label(value="Output Info", label="Info")
54
- test_button = gr.Button("Try it")
 
 
 
 
 
55
 
56
 
57
  test_button.click(
 
8
 
9
  llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
10
  TEST_MESSAGE = "My favorite TV shows are The Mentalist, The Blacklist, Designated Survivor, and Unforgettable. What are ten series that I should watch next?"
11
+ openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo",
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 = "Write an introductory paragraph to explain Generative AI to the reader of this content."):
16
  match optionSelection:
17
  case "OpenAI API":
18
+ try:
19
+ #model = "gpt-35-turbo"
20
+ model = "gpt-4"
21
+ system_prompt: str = "Explain in detail to help student understand the concept.",
22
+ assistant_prompt: str = None,
23
+
24
+ messages = [
25
+ {"role": "user", "content": f"{prompt}"},
26
+ {"role": "system", "content": f"{system_prompt}"},
27
+ {"role": "assistant", "content": f"{assistant_prompt}"}
28
+ ]
29
+
30
+ openai.api_key = os.getenv("OPENAI_API_KEY")
31
+ openai.api_version = '2020-11-07'
32
+
33
+ completion = openai.ChatCompletion.create(
34
+ model = model,
35
+ messages = messages,
36
+ temperature = 0.7
37
+ )
38
+ response = completion["choices"][0]["message"].content
39
+ return "", response
40
+ except openai.error.ServiceUnavailableError:
41
  case "Azure OpenAI API":
42
  return "", ""
43
  case "Google PaLM API":
 
53
  with gr.Blocks() as LLMDemoTabbedScreen:
54
  with gr.Tab("Text-to-Text (Text Completion)"):
55
  llm_options = gr.Radio(llm_api_options, label="Select one", info="Which service do you want to use?", value="OpenAI API")
56
+ with gr.Tab("Open AI"):
57
+ openai_model = gr.Dropdown(openai_models, value="gpt-4", label="Model", info="Select one, for Natural language")
58
+
59
+ with gr.Row():
60
+ with gr.Column():
61
+ test_string = gr.Textbox(label="Try String", value=TEST_MESSAGE, lines=2)
62
+ test_string_response = gr.Textbox(label="Response")
63
+ test_string_output_info = gr.Label(value="Output Info", label="Info")
64
+ test_button = gr.Button("Try it")
65
 
66
 
67
  test_button.click(