diff --git a/src/pai_rag/app/web/event_listeners.py b/src/pai_rag/app/web/event_listeners.py index 943b3302..b8a39e3d 100644 --- a/src/pai_rag/app/web/event_listeners.py +++ b/src/pai_rag/app/web/event_listeners.py @@ -114,13 +114,13 @@ def change_llm(value): eas_visible = value.lower() == "paieas" api_visible = value.lower() != "paieas" model_options = LLM_MODEL_KEY_DICT.get(value, []) - cur_model = model_options[0] if model_options else "" return [ gr.update(visible=eas_visible), gr.update(visible=eas_visible), gr.update(visible=eas_visible), gr.update(choices=model_options, value=cur_model, visible=api_visible), + gr.update(visible=api_visible), ] @@ -133,6 +133,7 @@ def change_mllm(value): gr.update(visible=eas_visible), gr.update(visible=api_visible), gr.update(choices=model_options, value=cur_model), + gr.update(visible=api_visible), ] diff --git a/src/pai_rag/app/web/tabs/data_analysis_tab.py b/src/pai_rag/app/web/tabs/data_analysis_tab.py index 4bbf962e..3712c87a 100644 --- a/src/pai_rag/app/web/tabs/data_analysis_tab.py +++ b/src/pai_rag/app/web/tabs/data_analysis_tab.py @@ -1,4 +1,3 @@ -import os from typing import Dict, Any, List import gradio as gr import pandas as pd @@ -10,7 +9,7 @@ ) -DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true") +DEFAULT_IS_INTERACTIVE = True def upload_file_fn(input_file): diff --git a/src/pai_rag/app/web/tabs/settings_tab.py b/src/pai_rag/app/web/tabs/settings_tab.py index a6d2ad44..1a1ef36d 100644 --- a/src/pai_rag/app/web/tabs/settings_tab.py +++ b/src/pai_rag/app/web/tabs/settings_tab.py @@ -4,10 +4,9 @@ from pai_rag.app.web.utils import components_to_dict from pai_rag.app.web.index_utils import index_related_component_keys from pai_rag.app.web.tabs.vector_db_panel import create_vector_db_panel -import os import pai_rag.app.web.event_listeners as ev_listeners -DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true") +DEFAULT_IS_INTERACTIVE = True def create_setting_tab() -> Dict[str, Any]: @@ -153,7 +152,7 @@ def create_setting_tab() -> Dict[str, Any]: with gr.Row(): _ = gr.Markdown(value="\N{WHITE MEDIUM STAR} **Large Language Model**") llm = gr.Radio( - ["paieas", "dashscope", "openai"], + ["paieas", "dashscope"], label="LLM Model Source", elem_id="llm", interactive=DEFAULT_IS_INTERACTIVE.lower() != "false", @@ -179,6 +178,12 @@ def create_setting_tab() -> Dict[str, Any]: label="LLM Model Name", elem_id="llm_api_model_name", ) + llm_api_key = gr.Textbox( + label="LLM API Key", + elem_id="llm_api_key", + type="password", + interactive=True, + ) with gr.Column(variant="panel"): _ = gr.Markdown( value="\N{WHITE MEDIUM STAR} **(Optional) Multi-Modal Large Language Model**" @@ -222,6 +227,12 @@ def create_setting_tab() -> Dict[str, Any]: label="LLM Model Name", elem_id="mllm_api_model_name", ) + mllm_api_key = gr.Textbox( + label="MultiModal-LLM API Key", + elem_id="mllm_api_key", + type="password", + interactive=True, + ) with gr.Column(scale=5, variant="panel"): _ = gr.Markdown( @@ -264,12 +275,14 @@ def create_setting_tab() -> Dict[str, Any]: llm_eas_token, llm_eas_model_name, llm_api_model_name, + llm_api_key, use_mllm, mllm, mllm_eas_url, mllm_eas_token, mllm_eas_model_name, mllm_api_model_name, + mllm_api_key, use_oss, oss_ak, oss_sk, @@ -293,13 +306,14 @@ def create_setting_tab() -> Dict[str, Any]: llm_eas_token, llm_eas_model_name, llm_api_model_name, + llm_api_key, ], ) mllm.input( fn=ev_listeners.change_mllm, inputs=mllm, - outputs=[m_eas_col, api_mllm_col, mllm_api_model_name], + outputs=[m_eas_col, api_mllm_col, mllm_api_model_name, mllm_api_key], ) save_btn = gr.Button("Save Llm Setting", variant="primary") diff --git a/src/pai_rag/app/web/tabs/vector_db_panel.py b/src/pai_rag/app/web/tabs/vector_db_panel.py index 3fc447bf..e01f140d 100644 --- a/src/pai_rag/app/web/tabs/vector_db_panel.py +++ b/src/pai_rag/app/web/tabs/vector_db_panel.py @@ -1,10 +1,9 @@ import gradio as gr from typing import Any, Dict from pai_rag.app.web.utils import components_to_dict -import os import pai_rag.app.web.event_listeners as ev_listeners -DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true") +DEFAULT_IS_INTERACTIVE = True def create_vector_db_panel() -> Dict[str, Any]: diff --git a/src/pai_rag/app/web/view_model.py b/src/pai_rag/app/web/view_model.py index 3cf3017c..9af4c462 100644 --- a/src/pai_rag/app/web/view_model.py +++ b/src/pai_rag/app/web/view_model.py @@ -21,7 +21,7 @@ PandasAnalysisConfig, SqliteAnalysisConfig, ) -from pai_rag.integrations.llms.pai.llm_config import PaiEasLlmConfig +from pai_rag.integrations.llms.pai.llm_config import DashScopeLlmConfig, PaiEasLlmConfig from pai_rag.integrations.postprocessor.pai.pai_postprocessor import ( SimilarityPostProcessorConfig, ) @@ -43,7 +43,7 @@ class ViewModel(BaseModel): llm: str = "PaiEas" llm_eas_url: str = None llm_eas_token: str = None - llm_eas_model_name: str = "model" + llm_eas_model_name: str = "default" llm_api_key: str = None llm_api_model_name: str = None llm_temperature: float = 0.1 @@ -53,7 +53,7 @@ class ViewModel(BaseModel): mllm: str = None mllm_eas_url: str = None mllm_eas_token: str = None - mllm_eas_model_name: str = "model" + mllm_eas_model_name: str = "default" mllm_api_key: str = None mllm_api_model_name: str = None @@ -145,7 +145,7 @@ def from_app_config(config: RagConfig): view_model.llm_eas_model_name = config.llm.model view_model.llm_eas_url = config.llm.endpoint view_model.llm_eas_token = config.llm.token - else: + elif isinstance(config.llm, DashScopeLlmConfig): view_model.llm_api_key = config.llm.api_key view_model.llm_api_model_name = config.llm.model @@ -434,8 +434,12 @@ def to_component_settings(self) -> Dict[str, Dict[str, Any]]: "value": self.llm_eas_token, "visible": self.llm.lower() == "paieas", } + settings["llm_api_key"] = { + "value": self.llm_api_key, + "visible": self.llm.lower() != "paieas", + } if self.llm.lower() == "paieas" and not self.llm_eas_model_name: - self.llm_eas_model_name = "model" + self.llm_eas_model_name = "default" settings["llm_eas_model_name"] = { "value": self.llm_eas_model_name, @@ -459,6 +463,10 @@ def to_component_settings(self) -> Dict[str, Dict[str, Any]]: "choices": MLLM_MODEL_KEY_DICT.get(self.mllm, []), "visible": self.mllm.lower() != "paieas", } + settings["mllm_api_key"] = { + "value": self.mllm_api_key, + "visible": self.mllm.lower() != "paieas", + } settings["m_eas_col"] = {"visible": self.mllm == "paieas"} settings["api_mllm_col"] = {"visible": self.mllm == "dashscope"} diff --git a/src/pai_rag/app/web/webui.py b/src/pai_rag/app/web/webui.py index 166301cb..6e23a0f5 100644 --- a/src/pai_rag/app/web/webui.py +++ b/src/pai_rag/app/web/webui.py @@ -1,6 +1,5 @@ from fastapi import FastAPI import gradio as gr -import os from pai_rag.app.web import event_listeners from pai_rag.app.web.index_utils import index_to_components_settings from pai_rag.app.web.tabs.agent_tab import create_agent_tab @@ -22,7 +21,7 @@ from loguru import logger -DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true") +DEFAULT_IS_INTERACTIVE = True def resume_ui():