-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(web): unify AI providers behind OpenAI-compatible config (Ollama, Whisper, etc.) #1877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kovashikawa
wants to merge
7
commits into
CapSoftware:main
Choose a base branch
from
kovashikawa:feat/openai-compatible-ai-providers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+491
−213
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4023507
feat(env): add AI_*/STT_* env vars for OpenAI-compatible providers
kovashikawa 92c9f51
refactor(web): unify chat AI behind OpenAI-compatible client
kovashikawa ba17a06
feat(web): OpenAI-compatible STT + widen self-host AI gates
kovashikawa 4347a39
chore(docker): expose AI/STT env vars through compose files
kovashikawa 0b0f372
fix(env): require AI_API_KEY/AI_MODEL with AI_BASE_URL; validate URL …
kovashikawa e46a8cb
fix(web): harden ai-provider client, tighten STT/JSON handling, dedup…
kovashikawa 24e45ec
fix(web): restore Groq -> OpenAI failover when both keys configured
kovashikawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import "server-only"; | ||
|
|
||
| import { serverEnv } from "@cap/env"; | ||
| import OpenAI from "openai"; | ||
|
|
||
| const GROQ_DEFAULT_BASE_URL = "https://api.groq.com/openai/v1"; | ||
| const GROQ_DEFAULT_MODEL = "openai/gpt-oss-120b"; | ||
| const OPENAI_DEFAULT_MODEL = "gpt-4o-mini"; | ||
| const STT_DEFAULT_MODEL = "whisper-1"; | ||
|
|
||
| let aiClient: OpenAI | null = null; | ||
| let sttClient: OpenAI | null = null; | ||
|
|
||
| export function getAiClient(): OpenAI | null { | ||
| if (aiClient) return aiClient; | ||
|
|
||
| const env = serverEnv(); | ||
| if (env.AI_BASE_URL) { | ||
| aiClient = new OpenAI({ | ||
| baseURL: env.AI_BASE_URL, | ||
|
kovashikawa marked this conversation as resolved.
|
||
| apiKey: | ||
| env.AI_API_KEY ?? env.GROQ_API_KEY ?? env.OPENAI_API_KEY ?? "none", | ||
| }); | ||
| } else if (env.GROQ_API_KEY) { | ||
| aiClient = new OpenAI({ | ||
| baseURL: GROQ_DEFAULT_BASE_URL, | ||
| apiKey: env.GROQ_API_KEY, | ||
| }); | ||
| } else if (env.OPENAI_API_KEY) { | ||
| aiClient = new OpenAI({ apiKey: env.OPENAI_API_KEY }); | ||
| } | ||
|
|
||
| return aiClient; | ||
| } | ||
|
|
||
| export function getAiModel(): string { | ||
| const env = serverEnv(); | ||
| if (env.AI_MODEL) return env.AI_MODEL; | ||
| if (!env.AI_BASE_URL && env.GROQ_API_KEY) return GROQ_DEFAULT_MODEL; | ||
| return OPENAI_DEFAULT_MODEL; | ||
| } | ||
|
|
||
| export function getSttClient(): OpenAI | null { | ||
| if (sttClient) return sttClient; | ||
|
|
||
| const env = serverEnv(); | ||
| if (!env.STT_BASE_URL) return null; | ||
|
|
||
| sttClient = new OpenAI({ | ||
| baseURL: env.STT_BASE_URL, | ||
| apiKey: env.STT_API_KEY ?? "none", | ||
| }); | ||
|
|
||
| return sttClient; | ||
| } | ||
|
|
||
| export function getSttModel(): string { | ||
| return serverEnv().STT_MODEL ?? STT_DEFAULT_MODEL; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.