From 7a77f61ee6d6740448fb1afd633fe0bb09f165f2 Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Mon, 7 Apr 2025 00:28:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E6=B7=BB=E5=8A=A0=20API=20Pr?= =?UTF-8?q?ovider=20=E7=9A=84=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/setting_page.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/frontend/setting_page.py b/frontend/setting_page.py index 2739930..5f5863b 100644 --- a/frontend/setting_page.py +++ b/frontend/setting_page.py @@ -17,19 +17,47 @@ def setting_page(): for p in providers ] + def add_provider(model_id, base_url, api_key): + with Session(engine) as session: + new_provider = APIProvider( + model_id=model_id, + base_url=base_url, + api_key=api_key if api_key else None + ) + session.add(new_provider) + session.commit() + session.refresh(new_provider) + return get_providers() + with gr.Blocks() as demo: gr.Markdown("## API Provider 管理") with gr.Row(): + with gr.Column(scale=1): + model_id_input = gr.Textbox(label="Model ID") + base_url_input = gr.Textbox(label="Base URL") + api_key_input = gr.Textbox(label="API Key") + add_button = gr.Button("添加新API") + # API Provider列表 - with gr.Column(scale=2): + with gr.Column(scale=3): provider_table = gr.DataFrame( - headers=["id" , "model id", "URL", "API Key"], + headers=["id" , "model id", "base URL", "API Key"], datatype=["number","str", "str", "str"], interactive=True, value=get_providers(), wrap=True, - col_count=(4, "fixed") + col_count=(4, "auto") ) - + with gr.Row(): + edit_button = gr.Button("编辑选中行") + delete_button = gr.Button("删除选中行") + + + add_button.click( + fn=add_provider, + inputs=[model_id_input, base_url_input, api_key_input], + outputs=provider_table + ) + return demo \ No newline at end of file