Spaces:
Runtime error
Runtime error
Commit
·
17678fc
1
Parent(s):
847e58c
test another way to make gpt optional
Browse files
app.py
CHANGED
|
@@ -89,31 +89,30 @@ def llama_respond(tab_name, message, chat_history):
|
|
| 89 |
time.sleep(2)
|
| 90 |
return tab_name, "", chat_history
|
| 91 |
|
| 92 |
-
def gpt_strategies_respond(
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
if (
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
formatted_system_prompt = f'''Chunk the following sentence in CoNLL 2000 format with BIO tags without outputing any additional text: {message}'''
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
def vicuna_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history):
|
| 119 |
formatted_prompt = ""
|
|
@@ -246,7 +245,7 @@ def interface():
|
|
| 246 |
task_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
|
| 247 |
with gr.Row():
|
| 248 |
have_key = gr.Dropdown(["Yes", "No"], label="Do you own an API Key?", scale=0)
|
| 249 |
-
task_apikey_input = gr.Textbox(label="Open AI Key", placeholder="Enter your OpenAI key here", type="password", visible=
|
| 250 |
task = gr.Dropdown(["POS Tagging", "Chunking"], label="Task")
|
| 251 |
task_linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity For Strategy 1")
|
| 252 |
task_btn = gr.Button(value="Submit")
|
|
@@ -276,15 +275,16 @@ def interface():
|
|
| 276 |
vicuna_S3_chatbot, llama_S3_chatbot, gpt_S3_chatbot])
|
| 277 |
|
| 278 |
# Event Handler for API Key
|
| 279 |
-
def toggle_api_key_input(value):
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
|
| 286 |
-
have_key.input(toggle_api_key_input, inputs=have_key)
|
| 287 |
-
task_apikey_input.input(update_api_key, inputs=task_apikey_input)
|
|
|
|
| 288 |
|
| 289 |
# vicuna_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history):
|
| 290 |
# Event Handlers for Vicuna Chatbot POS/Chunk
|
|
@@ -306,12 +306,13 @@ def interface():
|
|
| 306 |
# Event Handler for GPT 3.5 Chatbot POS/Chunk, user must submit api key before submitting the prompt
|
| 307 |
# Will activate after getting API key
|
| 308 |
# task_apikey_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
| 315 |
|
| 316 |
|
| 317 |
|
|
|
|
| 89 |
time.sleep(2)
|
| 90 |
return tab_name, "", chat_history
|
| 91 |
|
| 92 |
+
def gpt_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history, max_convo_length = 10):
|
| 93 |
+
formatted_system_prompt = ""
|
| 94 |
+
if (task_name == "POS Tagging"):
|
| 95 |
+
if (strategy == "S1"):
|
| 96 |
+
formatted_system_prompt = f'''Generate the output only for the assistant. Output any {task_ling_ent} in the following sentence one per line without any additional text: {message}'''
|
| 97 |
+
elif (strategy == "S2"):
|
| 98 |
+
formatted_system_prompt = f'''POS tag the following sentence using Universal POS tag set without generating any additional text: {message}'''
|
| 99 |
+
elif (strategy == "S3"):
|
| 100 |
+
formatted_system_prompt = f'''POS tag the following sentence using Universal POS tag set without generating any additional text: {message}'''
|
| 101 |
+
elif (task_name == "Chunking"):
|
| 102 |
+
if (strategy == "S1"):
|
| 103 |
+
formatted_system_prompt = f'''Generate the output only for the assistant. Output any {task_ling_ent} in the following sentence one per line without any additional text: {message}'''
|
| 104 |
+
elif (strategy == "S2"):
|
| 105 |
+
formatted_system_prompt = f'''Chunk the following sentence in CoNLL 2000 format with BIO tags without outputing any additional text: {message}'''
|
| 106 |
+
elif (strategy == "S3"):
|
| 107 |
+
formatted_system_prompt = f'''Chunk the following sentence in CoNLL 2000 format with BIO tags without outputing any additional text: {message}'''
|
|
|
|
| 108 |
|
| 109 |
+
formatted_prompt = format_chat_prompt(message, chat_history, max_convo_length)
|
| 110 |
+
print('Prompt + Context:')
|
| 111 |
+
print(formatted_prompt)
|
| 112 |
+
bot_message = chat(system_prompt = formatted_system_prompt,
|
| 113 |
+
user_prompt = formatted_prompt)
|
| 114 |
+
chat_history.append((message, bot_message))
|
| 115 |
+
return "", chat_history
|
| 116 |
|
| 117 |
def vicuna_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history):
|
| 118 |
formatted_prompt = ""
|
|
|
|
| 245 |
task_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
|
| 246 |
with gr.Row():
|
| 247 |
have_key = gr.Dropdown(["Yes", "No"], label="Do you own an API Key?", scale=0)
|
| 248 |
+
task_apikey_input = gr.Textbox(label="Open AI Key", placeholder="Enter your OpenAI key here", type="password", visible=True)
|
| 249 |
task = gr.Dropdown(["POS Tagging", "Chunking"], label="Task")
|
| 250 |
task_linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity For Strategy 1")
|
| 251 |
task_btn = gr.Button(value="Submit")
|
|
|
|
| 275 |
vicuna_S3_chatbot, llama_S3_chatbot, gpt_S3_chatbot])
|
| 276 |
|
| 277 |
# Event Handler for API Key
|
| 278 |
+
# def toggle_api_key_input(value):
|
| 279 |
+
# print("toggle_api_key_input ran")
|
| 280 |
+
# if value == "Yes":
|
| 281 |
+
# task_apikey_input.visible = True
|
| 282 |
+
# else:
|
| 283 |
+
# task_apikey_input.visible = False
|
| 284 |
|
| 285 |
+
# have_key.input(toggle_api_key_input, inputs=have_key)
|
| 286 |
+
# task_apikey_input.input(update_api_key, inputs=task_apikey_input)
|
| 287 |
+
task_btn.click(update_api_key, inputs=task_apikey_input)
|
| 288 |
|
| 289 |
# vicuna_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history):
|
| 290 |
# Event Handlers for Vicuna Chatbot POS/Chunk
|
|
|
|
| 306 |
# Event Handler for GPT 3.5 Chatbot POS/Chunk, user must submit api key before submitting the prompt
|
| 307 |
# Will activate after getting API key
|
| 308 |
# task_apikey_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
| 309 |
+
if (have_key.value == "Yes"):
|
| 310 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy1, task, task_linguistic_entities, task_prompt, gpt_S1_chatbot],
|
| 311 |
+
outputs=[task, task_prompt, gpt_S1_chatbot])
|
| 312 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy1, task, task_linguistic_entities, task_prompt, gpt_S2_chatbot],
|
| 313 |
+
outputs=[task, task_prompt, gpt_S2_chatbot])
|
| 314 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy1, task, task_linguistic_entities, task_prompt, gpt_S3_chatbot],
|
| 315 |
+
outputs=[task, task_prompt, gpt_S3_chatbot])
|
| 316 |
|
| 317 |
|
| 318 |
|