Skip to content

fix: respect OPENAI_BASE_URL for openai embedding provider#464

Open
paralizeer wants to merge 2 commits intoplastic-labs:mainfrom
paralizeer:fix/openai-embedding-base-url
Open

fix: respect OPENAI_BASE_URL for openai embedding provider#464
paralizeer wants to merge 2 commits intoplastic-labs:mainfrom
paralizeer:fix/openai-embedding-base-url

Conversation

@paralizeer
Copy link
Copy Markdown

@paralizeer paralizeer commented Mar 30, 2026

Problem

The openai embedding provider hardcodes the base URL to OpenAI's default endpoint:

self.client = AsyncOpenAI(api_key=api_key)  # always hits api.openai.com

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 as base_url to AsyncOpenAI, enabling any OpenAI-compatible endpoint
  • OPENAI_EMBEDDING_MODEL: override the model name (e.g. nomic-embed-text for Ollama)

Example usage

# config.toml — use Ollama for embeddings
[llm]
OPENAI_API_KEY = "ollama"
OPENAI_BASE_URL = "http://localhost:11434/v1"
OPENAI_EMBEDDING_MODEL = "nomic-embed-text"  # 768-dim model

Testing

Tested with Ollama + nomic-embed-text (768 dims) producing correct embeddings stored in pgvector.

Summary by CodeRabbit

  • New Features
    • Added optional configuration for a custom OpenAI API base URL to support alternate endpoints.
    • Added optional configuration to choose the OpenAI embedding model, with a sensible default used when not specified.
…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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: be446fe7-6e2e-4a4e-8277-6bf3469df8dc

📥 Commits

Reviewing files that changed from the base of the PR and between b75e0ea and 02f9f45.

📒 Files selected for processing (1)
  • src/embedding_client.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/embedding_client.py

Walkthrough

Adds two optional LLM settings—OPENAI_BASE_URL and OPENAI_EMBEDDING_MODEL—and updates the OpenAI embedding client to use these settings for client initialization and default embedding model selection.

Changes

Cohort / File(s) Summary
Configuration Settings
src/config.py
Added optional fields OPENAI_BASE_URL and OPENAI_EMBEDDING_MODEL to LLMSettings.
Embedding Client Initialization
src/embedding_client.py
OpenAI branch now reads settings.LLM.OPENAI_BASE_URL and passes it as base_url to AsyncOpenAI; selects embedding model from settings.LLM.OPENAI_EMBEDDING_MODEL with fallback to "text-embedding-3-small".

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble configs with a twitch and twirl,
New URLs and models set my whiskers in a whirl,
Embeddings choose their path, neat and small,
I hop away delighted—happy changes for all! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding support for custom OPENAI_BASE_URL in the OpenAI embedding provider, which aligns with the core problem and fix described in the PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/embedding_client.py (1)

67-67: Prefer direct attribute access over getattr.

Since OPENAI_EMBEDDING_MODEL is now a defined field in LLMSettings with a default of None, 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

📥 Commits

Reviewing files that changed from the base of the PR and between a5423b5 and b75e0ea.

📒 Files selected for processing (2)
  • src/config.py
  • src/embedding_client.py
Co-authored-by: CodeRabbit <coderabbit@coderabbit.ai>
@paralizeer
Copy link
Copy Markdown
Author

Applied the suggestion from @coderabbitai — replaced getattr with direct attribute access since OPENAI_EMBEDDING_MODEL is already a defined field in LLMSettings. Cleaner and consistent with the rest of the file.

Context: this fix came out of integrating Honcho with an Ollama-compatible embedding endpoint (nomic-embed-text). The OPENAI_BASE_URL override is what makes it work with non-OpenAI providers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

Tip

For best results, initiate chat on the files or code changes.

@paralizeer: Thanks for applying the change and for the helpful context! Direct attribute access is indeed cleaner here since OPENAI_EMBEDDING_MODEL is a first-class field on LLMSettings. The Ollama + nomic-embed-text use-case is a great motivating example for this fix — good to have OPENAI_BASE_URL as the primary lever for pointing at any OpenAI-compatible endpoint.


✏️ Learnings added
Learnt from: paralizeer
URL: https://github.com/plastic-labs/honcho/pull/464

Timestamp: 2026-03-30T17:35:06.547Z
Learning: In the Honcho codebase (src/embedding_client.py and src/config.py), `OPENAI_BASE_URL` and `OPENAI_EMBEDDING_MODEL` are first-class fields defined on `LLMSettings`. Access them via direct attribute access (e.g., `settings.LLM.OPENAI_BASE_URL`) rather than `getattr`. `OPENAI_BASE_URL` is the key override for using OpenAI-compatible embedding providers such as Ollama (e.g., base_url="http://localhost:11434/v1"), and `OPENAI_EMBEDDING_MODEL` allows specifying a custom model name (e.g., "nomic-embed-text") instead of the default "text-embedding-3-small".

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant