bitflicker64 commented on code in PR #378:
URL: https://github.com/apache/hugegraph-ai/pull/378#discussion_r4185465189
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py:
##########
@@ -779,6 +795,31 @@ def vector_engine_settings(engine):
apply_faiss_button = gr.Button("Apply Configuration")
apply_faiss_button.click(lambda: apply_vector_engine(engine))
+ def refresh_llm_config(revision):
+ with runtime_config_lock:
+ llm_settings.__init__() # type: ignore[misc] # pylint:
disable=C2801
Review Comment:
Important: If `.env` holds any value `LLMConfig` rejects, the page loads
with every provider form missing. With explicit `triggers`, gradio 5.20 no
longer adds the implicit page-load trigger to `@gr.render`
(`gradio/renderable.py`, lines 137-150). The five forms now render only when
`config_revision` changes, and that happens only when this function returns.
When `llm_settings.__init__()` raises, the load event fails, `config_revision`
stays at 0, and Chat, mini_tasks, text2gql, Embedding and Reranker show no
fields and no Apply button. Before this PR, those renders also ran on load and
showed the in-memory values.
Reproduced on this head with gradio 5.20.1: I wrote a `.env` that differs
only by `CHAT_LLM_TYPE=ollama` (the valid value is `ollama/local`) and replayed
the load event the way `test_demo_config_refresh.py` does. `refresh_llm_config`
raised a pydantic `literal_error`, and the only render that fired was
`vector_engine_settings`. A mistyped `Literal` value or a non-integer token or
port count is a likely mistake in the edit-then-refresh workflow this PR adds,
and it now removes the config UI instead of leaving the old values editable.
Please keep the renders firing when the reload fails and tell the user why,
for example:
```python
def refresh_llm_config(revision):
with runtime_config_lock:
try:
llm_settings.__init__() # type: ignore[misc] # pylint:
disable=C2801
except Exception as e: # pylint: disable=broad-except
log.error("Failed to reload LLM settings from %s: %s",
env_path, e)
gr.Warning(f"Could not reload {env_path}, keeping the
current settings: {e}")
return (
```
Also add a case to `test_demo_config_refresh.py` with an invalid value, and
assert that the provider textboxes still render.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]