Skip to content

Commit

Permalink
fix webui
Browse files Browse the repository at this point in the history
  • Loading branch information
wwxxzz committed Jun 4, 2024
1 parent 447f014 commit ec886af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
44 changes: 18 additions & 26 deletions src/pai_rag/app/web/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"""

DEFAULT_EMBED_SIZE = 1536
DEFAULT_HF_EMBED_MODEL = "bge-small-zh-v1.5"

embedding_dim_dict = {
"bge-small-zh-v1.5": 1024,
Expand Down Expand Up @@ -163,14 +164,6 @@ def create_ui():
elem_id="embed_model",
visible=(view_model.embed_source == "HuggingFace"),
)
embed_api_key = gr.Textbox(
visible=view_model.embed_source != "HuggingFace",
label="Embedding API Key",
value=view_model.embed_api_key,
type="password",
interactive=True,
elem_id="embed_api_key",
)
embed_dim = gr.Textbox(
label="Embedding Dimension",
value=embedding_dim_dict.get(
Expand All @@ -181,16 +174,24 @@ def create_ui():

def change_emb_source(source):
view_model.embed_source = source
view_model.embed_model = (
DEFAULT_HF_EMBED_MODEL
if source == "HuggingFace"
else source
)
_embed_dim = (
embedding_dim_dict.get(
view_model.embed_model, DEFAULT_EMBED_SIZE
)
if source == "HuggingFace"
else DEFAULT_EMBED_SIZE
)
return {
embed_model: gr.update(
visible=(source == "HuggingFace")
),
embed_dim: embedding_dim_dict.get(
view_model.embed_model, DEFAULT_EMBED_SIZE
),
embed_api_key: gr.update(
visible=(source != "HuggingFace")
visible=(source == "HuggingFace"),
value=view_model.embed_model,
),
embed_dim: _embed_dim,
}

def change_emb_model(model):
Expand All @@ -199,20 +200,17 @@ def change_emb_model(model):
embed_dim: embedding_dim_dict.get(
view_model.embed_model, DEFAULT_EMBED_SIZE
),
embed_api_key: gr.update(
visible=(view_model.embed_source != "HuggingFace")
),
}

embed_source.change(
fn=change_emb_source,
inputs=embed_source,
outputs=[embed_model, embed_dim, embed_api_key],
outputs=[embed_model, embed_dim],
)
embed_model.change(
fn=change_emb_model,
inputs=embed_model,
outputs=[embed_dim, embed_api_key],
outputs=[embed_dim],
)

with gr.Column():
Expand Down Expand Up @@ -242,11 +240,6 @@ def change_emb_model(model):
with gr.Column(
visible=(view_model.llm != "PaiEas")
) as api_llm_col:
llm_api_key = gr.Textbox(
label="API Key",
value=view_model.llm_api_key,
elem_id="llm_api_key",
)
llm_api_model_name = gr.Dropdown(
llm_model_key_dict.get(view_model.llm, []),
label="LLM Model Name",
Expand Down Expand Up @@ -297,7 +290,6 @@ def change_llm_src(value):
embed_source,
embed_model,
embed_dim,
llm_api_key,
llm_api_model_name,
},
connect_vector_func=connect_vector_db,
Expand Down
1 change: 0 additions & 1 deletion src/pai_rag/config/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type = "SimpleDirectoryReader"

[rag.embedding]
source = "DashScope"
model_name = "qwen-turbo"

[rag.evaluation]
retrieval = ["mrr", "hit_rate"]
Expand Down

0 comments on commit ec886af

Please sign in to comment.