Skip to content

Multi-provider support via OpenAI-compatible API + defensive markdown-fence stripping#7

Merged
robisim74 merged 2 commits into
robisim74:mainfrom
QualyHQ:feat/multi-provider-and-md-fence-fix
Apr 27, 2026
Merged

Multi-provider support via OpenAI-compatible API + defensive markdown-fence stripping#7
robisim74 merged 2 commits into
robisim74:mainfrom
QualyHQ:feat/multi-provider-and-md-fence-fix

Conversation

@raphaelarias
Copy link
Copy Markdown
Contributor

@raphaelarias raphaelarias commented Apr 25, 2026

Summary

Two small, independent improvements we've been running on a fork:

  1. Multi-provider support — adds an optional baseURL option (also --baseURL on the CLI) that gets passed through to the OpenAI client constructor. Lets users point the tool at any OpenAI-compatible endpoint (Gemini, OpenRouter, local Ollama, Azure OpenAI, etc.) without code changes. No behavior change when baseURL is omitted — defaults to OpenAI as before.

  2. Defensive markdown-fence stripping — some providers (notably Gemini via its OpenAI-compatible endpoint) wrap JSON responses in ```json ... ``` markers despite the prompt instruction added in Error when using 4o but works with 4? #5, causing JSON.parse to fail. This adds a defensive strip at the parse site so the existing prompt-level fix still wins on OpenAI but other providers don't break.

Why these together

The md-fence fix isn't strictly required for OpenAI — it surfaced once we started using non-OpenAI providers via the new baseURL option, which is why they're bundled. Happy to split into two PRs if preferred.

Test plan

  • npm run lint passes
  • npm run build passes
  • npm test — all 3 existing tests pass
  • Manually verified translation works end-to-end against OpenAI (default) and against a Gemini OpenAI-compatible endpoint via baseURL

raphaelarias and others added 2 commits April 25, 2026 18:03
Introduce a provider registry so the package can target different
AI backends (OpenAI, Gemini) through their OpenAI-compatible
endpoints. New providers can be added by extending the registry
in src/providers.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Some providers (e.g. Gemini via OpenAI-compatible endpoints) wrap JSON
responses in ```json ... ``` markers despite the prompt instruction,
causing JSON.parse to fail. Strip these defensively at the parse site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@robisim74 robisim74 merged commit 5b56a54 into robisim74:main Apr 27, 2026
2 checks passed
@robisim74
Copy link
Copy Markdown
Owner

@raphaelarias Thanks for this pr! I like the idea of ​​being able to use other providers.

But I don't understand one thing: in the description you say (Claude says?) that the new option is baseURL, while in the code the new option is provider and the baseURL is hardcoded: passing the provider name is easier, but to use a new URL, a code change and a new release will be needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants