feat(providers): add openai provider with custom base_url support#385
feat(providers): add openai provider with custom base_url support#385liuhaibin0528 wants to merge 1 commit into
Conversation
Add OPENAI_API_KEY as a first-class LLM provider option for summary/compression. Uses OpenRouterProvider under the hood with OPENAI_BASE_URL for custom endpoints. Environment variables: OPENAI_API_KEY — required API key OPENAI_BASE_URL — optional, defaults to api.openai.com/v1/chat/completions OPENAI_MODEL — optional, defaults to gpt-4o-mini Changes: - src/types.ts: add 'openai' to ProviderType union - src/config.ts: detectProvider() openai branch + detectLlmProviderKind() + VALID_PROVIDERS - src/providers/index.ts: createBaseProvider() case 'openai' - src/providers/openrouter.ts: name detection from ternary to multi-branch - src/functions/summarize.ts: error message includes OPENAI
|
@liuhaibin0528 is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis PR adds OpenAI API key support to the agent memory system. The changes span type definitions, environment detection, provider factory wiring, and provider identification to enable OpenAI as a first-class LLM provider alongside Anthropic, Gemini, and OpenRouter. ChangesOpenAI provider integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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/providers/index.ts (1)
68-79: ⚡ Quick winConsider respecting config.baseURL for consistency.
The current implementation re-reads
OPENAI_BASE_URLfrom the environment, ignoringconfig.baseURL. This differs from theanthropiccase (line 85) which usesconfig.baseURL. While re-reading env works for fallback providers, it prevents programmatic baseURL configuration from being respected.♻️ Proposed refactor to align with anthropic pattern
case "openai": { const openaiKey = requireEnvVar("OPENAI_API_KEY"); - const openaiBase = - getEnvVar("OPENAI_BASE_URL") || - "https://api.openai.com/v1/chat/completions"; + const openaiBase = + config.baseURL || + getEnvVar("OPENAI_BASE_URL") || + "https://api.openai.com/v1/chat/completions"; return new OpenRouterProvider( openaiKey, config.model, config.maxTokens, openaiBase, ); }This preserves fallback support while respecting
config.baseURLwhen set.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/providers/index.ts` around lines 68 - 79, The OpenAI provider branch currently ignores config.baseURL and re-reads OPENAI_BASE_URL from the environment; change the base URL selection in the case "openai" branch so it prefers config.baseURL first, then falls back to getEnvVar("OPENAI_BASE_URL"), then the hardcoded default (same approach used in the anthropic branch). Update the OpenRouterProvider constructor call to pass this computed base URL (refer to the case "openai" block, OpenRouterProvider, requireEnvVar, getEnvVar, and config.baseURL).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/providers/index.ts`:
- Around line 68-79: The OpenAI provider branch currently ignores config.baseURL
and re-reads OPENAI_BASE_URL from the environment; change the base URL selection
in the case "openai" branch so it prefers config.baseURL first, then falls back
to getEnvVar("OPENAI_BASE_URL"), then the hardcoded default (same approach used
in the anthropic branch). Update the OpenRouterProvider constructor call to pass
this computed base URL (refer to the case "openai" block, OpenRouterProvider,
requireEnvVar, getEnvVar, and config.baseURL).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b46c8e08-07e9-4148-9a30-c3e6e01123bb
📒 Files selected for processing (5)
src/config.tssrc/functions/summarize.tssrc/providers/index.tssrc/providers/openrouter.tssrc/types.ts
Problem
agentmemory currently does not support as a summary/compression LLM provider. Users who want to use OpenAI-compatible endpoints (including self-hosted proxies like Ollama, vLLM, etc.) have no way to configure a custom base URL for the summary LLM.
The embedding provider already supports — but the summary LLM provider does not.
Solution
Add as a first-class provider type that reuses the existing implementation (which already handles OpenAI-compatible chat completions API).
Environment Variables
OPENAI_API_KEYOPENAI_BASE_URLhttps://api.openai.com/v1/chat/completionsOPENAI_MODELgpt-4o-miniFiles Changed
'openai'toProviderTypeuniondetectProvider()openai branch +detectLlmProviderKind()+VALID_PROVIDERScreateBaseProvider()case 'openai'Testing
Usage Example
Summary by CodeRabbit
OPENAI_API_KEYenvironment variable. You can optionally customize the API endpoint withOPENAI_BASE_URL; if not set, it defaults to OpenAI's official Chat Completions endpoint. System error messages have been updated to list OpenAI among available LLM provider options.