Simon Strandgaard
commited on
Commit
·
a375e12
1
Parent(s):
61db3dc
show error message if the user hasn't provided any openrouter_api_key
Browse files- src/plan/app_text2plan.py +22 -0
src/plan/app_text2plan.py
CHANGED
@@ -382,10 +382,16 @@ def initialize_settings(session_state: SessionState):
|
|
382 |
session_state.speedvsdetail,
|
383 |
session_state)
|
384 |
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
# Build the Gradio UI using Blocks.
|
387 |
with gr.Blocks(title="PlanExe") as demo_text2plan:
|
388 |
gr.Markdown("# PlanExe: crack open pandora’s box of ideas", visible=CONFIG.visible_top_header)
|
|
|
389 |
with gr.Tab("Main"):
|
390 |
with gr.Row():
|
391 |
with gr.Column(scale=2, min_width=300):
|
@@ -451,11 +457,19 @@ with gr.Blocks(title="PlanExe") as demo_text2plan:
|
|
451 |
fn=run_planner,
|
452 |
inputs=[submit_btn, prompt_input, session_state],
|
453 |
outputs=[output_markdown, download_output, session_state]
|
|
|
|
|
|
|
|
|
454 |
)
|
455 |
retry_btn.click(
|
456 |
fn=run_planner,
|
457 |
inputs=[retry_btn, prompt_input, session_state],
|
458 |
outputs=[output_markdown, download_output, session_state]
|
|
|
|
|
|
|
|
|
459 |
)
|
460 |
# The Stop button uses the state to terminate the running process.
|
461 |
stop_btn.click(
|
@@ -474,6 +488,10 @@ with gr.Blocks(title="PlanExe") as demo_text2plan:
|
|
474 |
fn=update_openrouter_api_key,
|
475 |
inputs=[openrouter_api_key_text, session_state],
|
476 |
outputs=[openrouter_api_key_text, session_state]
|
|
|
|
|
|
|
|
|
477 |
)
|
478 |
model_radio.change(
|
479 |
fn=update_model_radio,
|
@@ -491,6 +509,10 @@ with gr.Blocks(title="PlanExe") as demo_text2plan:
|
|
491 |
fn=initialize_settings,
|
492 |
inputs=[session_state],
|
493 |
outputs=[openrouter_api_key_text, model_radio, speedvsdetail_radio, session_state]
|
|
|
|
|
|
|
|
|
494 |
)
|
495 |
|
496 |
def run_app_text2plan():
|
|
|
382 |
session_state.speedvsdetail,
|
383 |
session_state)
|
384 |
|
385 |
+
def check_api_key(session_state: SessionState):
|
386 |
+
"""Checks if the API key is provided and returns a warning if not."""
|
387 |
+
if CONFIG.visible_openrouter_api_key_textbox and (not session_state.openrouter_api_key or len(session_state.openrouter_api_key) == 0):
|
388 |
+
return "<div style='background-color: #FF7777; color: black; border: 1px solid red; padding: 10px;'>Welcome to PlanExe. Please provide an OpenRouter API key in the <b>Settings</b> tab to start using PlanExe.</div>"
|
389 |
+
return "" # No warning
|
390 |
|
391 |
# Build the Gradio UI using Blocks.
|
392 |
with gr.Blocks(title="PlanExe") as demo_text2plan:
|
393 |
gr.Markdown("# PlanExe: crack open pandora’s box of ideas", visible=CONFIG.visible_top_header)
|
394 |
+
api_key_warning = gr.Markdown()
|
395 |
with gr.Tab("Main"):
|
396 |
with gr.Row():
|
397 |
with gr.Column(scale=2, min_width=300):
|
|
|
457 |
fn=run_planner,
|
458 |
inputs=[submit_btn, prompt_input, session_state],
|
459 |
outputs=[output_markdown, download_output, session_state]
|
460 |
+
).then(
|
461 |
+
fn=check_api_key, # Check after submitting.
|
462 |
+
inputs=[session_state],
|
463 |
+
outputs=[api_key_warning]
|
464 |
)
|
465 |
retry_btn.click(
|
466 |
fn=run_planner,
|
467 |
inputs=[retry_btn, prompt_input, session_state],
|
468 |
outputs=[output_markdown, download_output, session_state]
|
469 |
+
).then(
|
470 |
+
fn=check_api_key, # Check after retrying.
|
471 |
+
inputs=[session_state],
|
472 |
+
outputs=[api_key_warning]
|
473 |
)
|
474 |
# The Stop button uses the state to terminate the running process.
|
475 |
stop_btn.click(
|
|
|
488 |
fn=update_openrouter_api_key,
|
489 |
inputs=[openrouter_api_key_text, session_state],
|
490 |
outputs=[openrouter_api_key_text, session_state]
|
491 |
+
).then(
|
492 |
+
fn=check_api_key, # Check when the API key changes.
|
493 |
+
inputs=[session_state],
|
494 |
+
outputs=[api_key_warning]
|
495 |
)
|
496 |
model_radio.change(
|
497 |
fn=update_model_radio,
|
|
|
509 |
fn=initialize_settings,
|
510 |
inputs=[session_state],
|
511 |
outputs=[openrouter_api_key_text, model_radio, speedvsdetail_radio, session_state]
|
512 |
+
).then(
|
513 |
+
fn=check_api_key, # Check on initial load.
|
514 |
+
inputs=[session_state],
|
515 |
+
outputs=[api_key_warning]
|
516 |
)
|
517 |
|
518 |
def run_app_text2plan():
|