fix: respect OPENAI_BASE_URL for openai embedding provider#464
fix: respect OPENAI_BASE_URL for openai embedding provider#464paralizeer wants to merge 2 commits intoplastic-labs:mainfrom
Conversation
…nai provider The openai embedding provider hardcoded the base URL to OpenAI's default endpoint, making it impossible to use OpenAI-compatible servers (Ollama, local inference servers, etc.) for embeddings. This adds two new LLMSettings fields: - OPENAI_BASE_URL: passed as base_url to AsyncOpenAI, enabling any OpenAI-compatible embedding endpoint (default: None = use OpenAI) - OPENAI_EMBEDDING_MODEL: override the default model name when using a custom endpoint (e.g. 'nomic-embed-text' for Ollama, default: None falls back to 'text-embedding-3-small') Example config.toml for Ollama: [llm] OPENAI_API_KEY = 'ollama' OPENAI_BASE_URL = 'http://localhost:11434/v1' OPENAI_EMBEDDING_MODEL = 'nomic-embed-text' Fixes: embedding provider ignores OPENAI_BASE_URL, always hits api.openai.com
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds two optional LLM settings— Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/embedding_client.py (1)
67-67: Prefer direct attribute access overgetattr.Since
OPENAI_EMBEDDING_MODELis now a defined field inLLMSettingswith a default ofNone, you can use direct attribute access for consistency with line 63.Suggested change
- self.model = getattr(settings.LLM, "OPENAI_EMBEDDING_MODEL", None) or "text-embedding-3-small" + self.model = settings.LLM.OPENAI_EMBEDDING_MODEL or "text-embedding-3-small"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/embedding_client.py` at line 67, Replace the getattr usage with direct attribute access: set self.model = settings.LLM.OPENAI_EMBEDDING_MODEL or "text-embedding-3-small" so the code uses the defined LLMSettings field (consistent with the access pattern on line 63); update the assignment where self.model is initialized (in the Embedding client constructor or the method that sets self.model) to use settings.LLM.OPENAI_EMBEDDING_MODEL instead of getattr(settings.LLM, "OPENAI_EMBEDDING_MODEL", None).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/embedding_client.py`:
- Line 67: Replace the getattr usage with direct attribute access: set
self.model = settings.LLM.OPENAI_EMBEDDING_MODEL or "text-embedding-3-small" so
the code uses the defined LLMSettings field (consistent with the access pattern
on line 63); update the assignment where self.model is initialized (in the
Embedding client constructor or the method that sets self.model) to use
settings.LLM.OPENAI_EMBEDDING_MODEL instead of getattr(settings.LLM,
"OPENAI_EMBEDDING_MODEL", None).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0071fb87-3145-466b-933a-30545274468d
📒 Files selected for processing (2)
src/config.pysrc/embedding_client.py
Co-authored-by: CodeRabbit <coderabbit@coderabbit.ai>
|
Applied the suggestion from @coderabbitai — replaced Context: this fix came out of integrating Honcho with an Ollama-compatible embedding endpoint (nomic-embed-text). The |
|
Tip For best results, initiate chat on the files or code changes.
✏️ Learnings added
|
Problem
The
openaiembedding provider hardcodes the base URL to OpenAI's default endpoint:This makes it impossible to use OpenAI-compatible embedding servers like Ollama, local inference servers, or self-hosted models.
Fix
Add two new fields to
LLMSettings:OPENAI_BASE_URL: passed asbase_urltoAsyncOpenAI, enabling any OpenAI-compatible endpointOPENAI_EMBEDDING_MODEL: override the model name (e.g.nomic-embed-textfor Ollama)Example usage
Testing
Tested with Ollama + nomic-embed-text (768 dims) producing correct embeddings stored in pgvector.
Summary by CodeRabbit