amitpuri commited on
Commit
c3fc45d
1 Parent(s): df68234

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import gradio as gr
3
  import openai
4
 
@@ -9,9 +10,6 @@ llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
9
  TEST_MESSAGE = "My favorite TV shows are The Mentalist, The Blacklist, Designated Survivor, and Unforgettable. What are ten series that I should watch next?"
10
 
11
  def test_handler(optionSelection, prompt: str = "Write an introductory paragraph to explain Generative AI to the reader of this content."):
12
- if optionSelection not in llm_api_options:
13
- raise ValueError("Invalid choice!")
14
-
15
  match optionSelection:
16
  case "OpenAI API":
17
  #model = "gpt-35-turbo"
@@ -21,7 +19,6 @@ def test_handler(optionSelection, prompt: str = "Write an introductory paragraph
21
 
22
  messages = [
23
  {"role": "user", "content": f"{prompt}"},
24
-
25
  {"role": "system", "content": f"{system_prompt}"},
26
  {"role": "assistant", "content": f"{assistant_prompt}"}
27
  ]
@@ -30,20 +27,23 @@ def test_handler(optionSelection, prompt: str = "Write an introductory paragraph
30
  openai.api_version = '2020-11-07'
31
 
32
  completion = openai.ChatCompletion.create(
33
- model = model
34
- ,
35
  messages = messages,
36
  temperature = 0.7
37
  )
38
  response = completion["choices"][0]["message"].content
39
- return completion, response
40
  case "Azure OpenAI API":
41
  return "", ""
42
  case "Google PaLM API":
43
  return "", ""
44
  case "Llama 2":
45
  return "", ""
 
 
 
46
 
 
47
 
48
  with gr.Blocks() as LLMDemoTabbedScreen:
49
  with gr.Tab("Text-to-Text (Text Completion)"):
 
1
  import os
2
+
3
  import gradio as gr
4
  import openai
5
 
 
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"
 
19
 
20
  messages = [
21
  {"role": "user", "content": f"{prompt}"},
 
22
  {"role": "system", "content": f"{system_prompt}"},
23
  {"role": "assistant", "content": f"{assistant_prompt}"}
24
  ]
 
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":
39
  return "", ""
40
  case "Llama 2":
41
  return "", ""
42
+ else:
43
+ if optionSelection not in llm_api_options:
44
+ return ValueError("Invalid choice!"), ""
45
 
46
+
47
 
48
  with gr.Blocks() as LLMDemoTabbedScreen:
49
  with gr.Tab("Text-to-Text (Text Completion)"):