Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,15 +28,12 @@ client = InferenceClient(
|
|
| 28 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
| 32 |
############################################
|
| 33 |
|
| 34 |
-
|
| 35 |
VERBOSE = True
|
| 36 |
MAX_HISTORY = 100
|
| 37 |
#MODEL = "gpt-3.5-turbo" # "gpt-4"
|
| 38 |
|
| 39 |
-
|
| 40 |
def format_prompt(message, history):
|
| 41 |
prompt = "<s>"
|
| 42 |
for user_prompt, bot_response in history:
|
|
@@ -45,8 +42,6 @@ def format_prompt(message, history):
|
|
| 45 |
prompt += f"[INST] {message} [/INST]"
|
| 46 |
return prompt
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
def run_gpt(
|
| 51 |
prompt_template,
|
| 52 |
stop_tokens,
|
|
@@ -87,7 +82,6 @@ def run_gpt(
|
|
| 87 |
print(LOG_RESPONSE.format(resp))
|
| 88 |
return resp
|
| 89 |
|
| 90 |
-
|
| 91 |
def compress_history(purpose, task, history, directory):
|
| 92 |
resp = run_gpt(
|
| 93 |
COMPRESS_HISTORY_PROMPT,
|
|
@@ -155,7 +149,6 @@ def call_main(purpose, task, history, directory, action_input):
|
|
| 155 |
#assert False, "unknown action: {}".format(line)
|
| 156 |
return "MAIN", None, history, task
|
| 157 |
|
| 158 |
-
|
| 159 |
def call_set_task(purpose, task, history, directory, action_input):
|
| 160 |
task = run_gpt(
|
| 161 |
TASK_PROMPT,
|
|
@@ -243,8 +236,6 @@ def run(purpose,history):
|
|
| 243 |
return (history)
|
| 244 |
#return ("", [(purpose,history)])
|
| 245 |
|
| 246 |
-
|
| 247 |
-
|
| 248 |
################################################
|
| 249 |
|
| 250 |
def format_prompt(message, history):
|
|
@@ -295,7 +286,6 @@ def generate(
|
|
| 295 |
yield output
|
| 296 |
return output
|
| 297 |
|
| 298 |
-
|
| 299 |
additional_inputs=[
|
| 300 |
gr.Dropdown(
|
| 301 |
label="Agents",
|
|
@@ -346,7 +336,6 @@ additional_inputs=[
|
|
| 346 |
info="Penalize repeated tokens",
|
| 347 |
),
|
| 348 |
|
| 349 |
-
|
| 350 |
]
|
| 351 |
|
| 352 |
examples=[["What are the biggest news stories today?", None, None, None, None, None, ],
|
|
@@ -359,32 +348,22 @@ examples=[["What are the biggest news stories today?", None, None, None, None, N
|
|
| 359 |
["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
|
| 360 |
]
|
| 361 |
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
).launch()
|
| 373 |
with gr.Blocks() as iface:
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
msg = gr.Textbox()
|
| 377 |
with gr.Row():
|
| 378 |
-
submit_b = gr.Button()
|
| 379 |
clear = gr.ClearButton([msg, chatbot])
|
| 380 |
-
submit_b.click(
|
| 381 |
-
msg.submit(
|
| 382 |
-
iface.launch()
|
| 383 |
-
'''
|
| 384 |
-
gr.ChatInterface(
|
| 385 |
-
fn=run,
|
| 386 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel"),
|
| 387 |
-
title="Mixtral 46.7B\nMicro-Agent\nInternet Search <br> development test",
|
| 388 |
-
examples=examples,
|
| 389 |
-
concurrency_limit=50,
|
| 390 |
-
).launch(show_api=True)
|
|
|
|
| 28 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 29 |
)
|
| 30 |
|
|
|
|
| 31 |
############################################
|
| 32 |
|
|
|
|
| 33 |
VERBOSE = True
|
| 34 |
MAX_HISTORY = 100
|
| 35 |
#MODEL = "gpt-3.5-turbo" # "gpt-4"
|
| 36 |
|
|
|
|
| 37 |
def format_prompt(message, history):
|
| 38 |
prompt = "<s>"
|
| 39 |
for user_prompt, bot_response in history:
|
|
|
|
| 42 |
prompt += f"[INST] {message} [/INST]"
|
| 43 |
return prompt
|
| 44 |
|
|
|
|
|
|
|
| 45 |
def run_gpt(
|
| 46 |
prompt_template,
|
| 47 |
stop_tokens,
|
|
|
|
| 82 |
print(LOG_RESPONSE.format(resp))
|
| 83 |
return resp
|
| 84 |
|
|
|
|
| 85 |
def compress_history(purpose, task, history, directory):
|
| 86 |
resp = run_gpt(
|
| 87 |
COMPRESS_HISTORY_PROMPT,
|
|
|
|
| 149 |
#assert False, "unknown action: {}".format(line)
|
| 150 |
return "MAIN", None, history, task
|
| 151 |
|
|
|
|
| 152 |
def call_set_task(purpose, task, history, directory, action_input):
|
| 153 |
task = run_gpt(
|
| 154 |
TASK_PROMPT,
|
|
|
|
| 236 |
return (history)
|
| 237 |
#return ("", [(purpose,history)])
|
| 238 |
|
|
|
|
|
|
|
| 239 |
################################################
|
| 240 |
|
| 241 |
def format_prompt(message, history):
|
|
|
|
| 286 |
yield output
|
| 287 |
return output
|
| 288 |
|
|
|
|
| 289 |
additional_inputs=[
|
| 290 |
gr.Dropdown(
|
| 291 |
label="Agents",
|
|
|
|
| 336 |
info="Penalize repeated tokens",
|
| 337 |
),
|
| 338 |
|
|
|
|
| 339 |
]
|
| 340 |
|
| 341 |
examples=[["What are the biggest news stories today?", None, None, None, None, None, ],
|
|
|
|
| 348 |
["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
|
| 349 |
]
|
| 350 |
|
| 351 |
+
def process_input(user_input, history, chatbot):
|
| 352 |
+
"""Processes user input and updates the chatbot."""
|
| 353 |
+
purpose = "General"
|
| 354 |
+
history = history + [(user_input, "")]
|
| 355 |
+
chatbot.append(user_input, "")
|
| 356 |
+
|
| 357 |
+
for response in run(purpose, history):
|
| 358 |
+
chatbot.append("", response)
|
| 359 |
+
yield chatbot
|
| 360 |
+
|
|
|
|
| 361 |
with gr.Blocks() as iface:
|
| 362 |
+
chatbot = gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel")
|
| 363 |
+
msg = gr.Textbox(label="Enter your message")
|
|
|
|
| 364 |
with gr.Row():
|
| 365 |
+
submit_b = gr.Button("Submit")
|
| 366 |
clear = gr.ClearButton([msg, chatbot])
|
| 367 |
+
submit_b.click(process_input, [msg, chatbot, chatbot], chatbot)
|
| 368 |
+
msg.submit(process_input, [msg, chatbot, chatbot], chatbot)
|
| 369 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|