mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-12 20:49:53 +08:00
refactor(providers): drop the transitional tables, document how to add a provider
Step 6 of the provider refactor plan. FIXED_CRED_PROVIDERS, PROVIDER_LOGO_MAP,
OPTIONS_OPEN and NO_KEY_NEEDED had no readers left and are gone; the record's
fields are read where they were used. The fixture that compared the derived
tables with their old literal values is gone with them; tests/unit/providers.test.ts
keeps the record's own rules (21 providers in auto-detection, every note in
every UI language, https defaults only, fixed-credential providers, the
picker's order) and a new check that env.example names every record's
variables. docs/{en,cn,ja}/ai-providers.md end with a section on adding a
provider: one record, two env.example lines, one docs paragraph.
This commit is contained in:
@@ -446,3 +446,26 @@ When unset, the model uses its default behavior.
|
||||
- **Budget-friendly**: DeepSeek offers competitive pricing
|
||||
- **Privacy**: Use Ollama for fully local, offline operation (requires powerful hardware)
|
||||
- **Flexibility**: OpenRouter provides access to many models through a single API
|
||||
|
||||
## Adding a Provider
|
||||
|
||||
Every fact about a provider lives in one record in `lib/providers.ts`: which AI SDK runs it (`sdk`), what it signs in with (`credential`), the prefix of its `<PREFIX>_API_KEY` / `<PREFIX>_BASE_URL` variables (`envPrefix`), its official URL, the picker group, and optional notes. The settings UI, the connection test, the chat route and the admin panel all read that record, so adding an OpenAI-compatible provider is:
|
||||
|
||||
1. Add a record to `lib/providers.ts`, for example:
|
||||
|
||||
```ts
|
||||
acme: {
|
||||
label: "Acme AI",
|
||||
sdk: "openai-compatible",
|
||||
credential: "apiKey",
|
||||
group: "aggregators",
|
||||
envPrefix: "ACME",
|
||||
defaultBaseUrl: "https://api.acme.example/v1",
|
||||
apiKeyUrl: "https://acme.example/keys",
|
||||
modelList: "openai",
|
||||
},
|
||||
```
|
||||
|
||||
A provider that needs a hint under its base URL field, or a note in the picker, gets a `baseUrlHint` or `note` object with all four UI languages (`en`, `zh`, `ja`, `zh-Hant`). Providers that cannot list their models online keep a short `models` list instead of `modelList`.
|
||||
2. Add `ACME_API_KEY` and `ACME_BASE_URL` to `env.example` (a unit test checks that every record's variables appear there).
|
||||
3. Add a section for it to this document in `docs/en`, `docs/cn` and `docs/ja`.
|
||||
|
||||
Reference in New Issue
Block a user