fix(openai-embedding): enhance stability, empty query handling, and SiliconFlow domain compatibility#8547
Conversation
…tively for SiliconFlow embedding models
There was a problem hiding this comment.
Code Review
This pull request updates the SiliconFlow API base check in openai_embedding_source.py to be more flexible by checking if 'siliconflow' is present in the lowercase API base URL, rather than strictly matching the start of the URL. There are no review comments to address, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
"siliconflow" in provider_api_base.lower()condition is quite broad and could trigger on non-SiliconFlow URLs that happen to contain that string; consider parsing and checking the hostname (e.g. viaurlparse) instead of a raw substring match. - The previous code used
provider_api_base.strip()while the new code does not; if leading/trailing whitespace is still possible in this value, consider applying.strip().lower()to preserve the original robustness.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `"siliconflow" in provider_api_base.lower()` condition is quite broad and could trigger on non-SiliconFlow URLs that happen to contain that string; consider parsing and checking the hostname (e.g. via `urlparse`) instead of a raw substring match.
- The previous code used `provider_api_base.strip()` while the new code does not; if leading/trailing whitespace is still possible in this value, consider applying `.strip().lower()` to preserve the original robustness.
## Individual Comments
### Comment 1
<location path="astrbot/core/provider/sources/openai_embedding_source.py" line_range="82" />
<code_context>
provider_api_base
# Hard-code SiliconFlow API Base Prefix and Model Name, as it's just a temporary workaround.
- and provider_api_base.strip().startswith("https://api.siliconflow.cn")
+ and "siliconflow" in provider_api_base.lower()
and not self.model.lower().startswith("qwen")
):
</code_context>
<issue_to_address>
**issue (bug_risk):** The broadened SiliconFlow check may now match unintended API bases.
Previously this only matched `https://api.siliconflow.cn`; now any base containing `"siliconflow"` (e.g., `https://foo-siliconflow-proxy.com`) will match. If you need to support more official SiliconFlow endpoints, consider a stricter host/domain check (e.g., URL parsing or matching explicit allowed prefixes) instead of a simple substring, to avoid affecting unrelated third‑party endpoints.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…l domains strictly and preserve strip()
…n handling and empty validation from 1.md
This PR introduces several robustness and stability improvements to the
openai_text_embeddingprovider to prevent crashes, handle empty queries gracefully, and correctly support both SiliconFlow domain configurations.Key Changes
.cnand.comdomains case-insensitively (usingurlparseto safely extract the hostname) to prevent 400 Bad Request errors (code 20015).embedding_api_keyis configured, failing fast with a descriptive error instead of throwing a generic error later.timeoutparsing in atry-exceptblock to fall back to20if the value is empty or invalid, avoidingValueErrorcrashes.openai.OpenAIErrorblocks to print descriptive logs during network or API request failures.getattr(self, 'client', None)insideterminate()to avoid attribute error exceptions during teardown.