amitpuri commited on
Commit
ca87f20
1 Parent(s): 432e214

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -17
app.py CHANGED
@@ -6,20 +6,14 @@ import google.generativeai as palm
6
  llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
7
  TEST_MESSAGE = "Write an introductory paragraph to explain Generative AI to the reader of this content."
8
  openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo",
9
-
10
- "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
11
  "text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
12
 
13
  google_palm_models = ["models/text-bison-001", "models/chat-bison-001","models/embedding-gecko-001"]
14
 
15
- azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
16
- azure_deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
17
- google_palm_key = os.getenv("GOOGLE_PALM_AI_API_KEY")
18
- openai_api_key = os.getenv("OPENAI_API_KEY")
19
- azure_openai_api_key = os.getenv("AZURE_OPENAI_KEY")
20
  temperature = 0.7
21
 
22
- def openai_text_completion(prompt: str, model: str):
23
  try:
24
  system_prompt: str = "Explain in detail to help student understand the concept.",
25
  assistant_prompt: str = None,
@@ -42,7 +36,7 @@ def openai_text_completion(prompt: str, model: str):
42
  print(exception)
43
  return f" openai_text_completion Error - {exception}", ""
44
 
45
- def azure_openai_text_completion(prompt: str, model: str):
46
  try:
47
  system_prompt: str = "Explain in detail to help student understand the concept.",
48
  assistant_prompt: str = None,
@@ -69,7 +63,7 @@ def azure_openai_text_completion(prompt: str, model: str):
69
  return f" azure_openai_text_completion Error - {exception}", ""
70
 
71
 
72
- def palm_text_completion(prompt: str, model: str):
73
  try:
74
  candidate_count = 1
75
  top_k = 40
@@ -97,16 +91,24 @@ def palm_text_completion(prompt: str, model: str):
97
  print(exception)
98
  return f" palm_text_completion Error - {exception}", ""
99
 
100
- def test_handler(optionSelection, prompt: str = TEST_MESSAGE, openai_model_name: str ="gpt-4", google_model_name: str ="models/text-bison-001"):
 
 
 
 
 
 
 
 
101
  match optionSelection:
102
  case "OpenAI API":
103
- message, response = openai_text_completion(prompt,openai_model_name)
104
  return message, response
105
  case "Azure OpenAI API":
106
- message, response = azure_openai_text_completion(prompt,openai_model_name)
107
  return message, response
108
  case "Google PaLM API":
109
- message, response = palm_text_completion(prompt,google_model_name)
110
  return message, response
111
  case "Llama 2":
112
  return f"{optionSelection} is not yet implemented!", ""
@@ -128,13 +130,30 @@ with gr.Blocks() as LLMDemoTabbedScreen:
128
  with gr.Tab("API Settings"):
129
  with gr.Tab("Open AI"):
130
  openai_model = gr.Dropdown(openai_models, value="gpt-4", label="Model", info="Select one, for Natural language")
 
 
 
 
 
 
 
131
  with gr.Tab("Google PaLM API"):
132
- google_model_name = gr.Dropdown(google_palm_models,
133
- value="models/text-bison-001", label="Model", info="Select one, for Natural language")
 
 
134
 
135
  test_button.click(
136
  fn=test_handler,
137
- inputs=[llm_options, test_string, openai_model, google_model_name],
 
 
 
 
 
 
 
 
138
  outputs=[test_string_output_info, test_string_response]
139
  )
140
 
 
6
  llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
7
  TEST_MESSAGE = "Write an introductory paragraph to explain Generative AI to the reader of this content."
8
  openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo",
9
+ "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
 
10
  "text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
11
 
12
  google_palm_models = ["models/text-bison-001", "models/chat-bison-001","models/embedding-gecko-001"]
13
 
 
 
 
 
 
14
  temperature = 0.7
15
 
16
+ def openai_text_completion(openai_api_key: str, prompt: str, model: str):
17
  try:
18
  system_prompt: str = "Explain in detail to help student understand the concept.",
19
  assistant_prompt: str = None,
 
36
  print(exception)
37
  return f" openai_text_completion Error - {exception}", ""
38
 
39
+ def azure_openai_text_completion(azure_openai_api_key: str, azure_endpoint: str, azure_deployment_name: str, prompt: str, model: str):
40
  try:
41
  system_prompt: str = "Explain in detail to help student understand the concept.",
42
  assistant_prompt: str = None,
 
63
  return f" azure_openai_text_completion Error - {exception}", ""
64
 
65
 
66
+ def palm_text_completion(google_palm_key: str, prompt: str, model: str):
67
  try:
68
  candidate_count = 1
69
  top_k = 40
 
91
  print(exception)
92
  return f" palm_text_completion Error - {exception}", ""
93
 
94
+ def test_handler(optionSelection,
95
+ openai_key,
96
+ azure_openai_key,
97
+ azure_openai_api_base,
98
+ azure_openai_deployment_name,
99
+ google_generative_api_key,
100
+ prompt: str = TEST_MESSAGE,
101
+ openai_model_name: str ="gpt-4",
102
+ google_model_name: str ="models/text-bison-001"):
103
  match optionSelection:
104
  case "OpenAI API":
105
+ message, response = openai_text_completion(openai_key, prompt,openai_model_name)
106
  return message, response
107
  case "Azure OpenAI API":
108
+ message, response = azure_openai_text_completion(azure_openai_key, azure_openai_api_base, azure_openai_deployment_name, prompt,openai_model_name)
109
  return message, response
110
  case "Google PaLM API":
111
+ message, response = palm_text_completion(google_generative_api_key, prompt,google_model_name)
112
  return message, response
113
  case "Llama 2":
114
  return f"{optionSelection} is not yet implemented!", ""
 
130
  with gr.Tab("API Settings"):
131
  with gr.Tab("Open AI"):
132
  openai_model = gr.Dropdown(openai_models, value="gpt-4", label="Model", info="Select one, for Natural language")
133
+ openai_key = gr.Textbox(label="Azure OpenAI API Key", type="password")
134
+ with gr.Tab("Azure Open AI"):
135
+ with gr.Row():
136
+ with gr.Column():
137
+ azure_openai_key = gr.Textbox(label="Azure OpenAI API Key", type="password")
138
+ azure_openai_api_base = gr.Textbox(label="Azure OpenAI API Endpoint")
139
+ azure_openai_deployment_name = gr.Textbox(label="Azure OpenAI API Deployment Name")
140
  with gr.Tab("Google PaLM API"):
141
+ with gr.Row():
142
+ with gr.Column():
143
+ google_model_name = gr.Dropdown(google_palm_models, value="models/text-bison-001", label="Model", info="Select one, for Natural language")
144
+ google_generative_api_key = gr.Textbox(label="Google Generative AI API Key", type="password")
145
 
146
  test_button.click(
147
  fn=test_handler,
148
+ inputs=[llm_options,
149
+ openai_key,
150
+ azure_openai_key,
151
+ azure_openai_api_base,
152
+ azure_openai_deployment_name,
153
+ google_generative_api_key,
154
+ test_string,
155
+ openai_model,
156
+ google_model_name],
157
  outputs=[test_string_output_info, test_string_response]
158
  )
159