Skip to content

Commit

Permalink
fix webui & remove api_key (#46)
Browse files Browse the repository at this point in the history
* fix webui

* bugfix

---------

Co-authored-by: Yue Fei <[email protected]>
  • Loading branch information
wwxxzz and moria97 authored Jun 4, 2024
1 parent d647d0b commit 81067f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 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
2 changes: 1 addition & 1 deletion src/pai_rag/app/web/view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _transform_to_dict(config):
class ViewModel(BaseModel):
# embedding
embed_source: str = "HuggingFace"
embed_model: str = "bge-large-zh-v1.5"
embed_model: str = "bge-small-zh-v1.5"
embed_dim: int = 1024
embed_api_key: str = None

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 81067f3

Please sign in to comment.