-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Gatewayz provider support #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { ProviderHelper, CommonRequest, CommonResponse, CommonChunk } from "./provider" | ||
|
|
||
| type Usage = { | ||
| prompt_tokens?: number | ||
| completion_tokens?: number | ||
| total_tokens?: number | ||
| prompt_tokens_details?: { | ||
| cached_tokens?: number | ||
| } | ||
| completion_tokens_details?: { | ||
| reasoning_tokens?: number | ||
| } | ||
| } | ||
|
|
||
| export const gatewayzHelper = { | ||
| format: "oa-compat", | ||
| modifyUrl: (providerApi: string) => providerApi + "/v1/chat/completions", | ||
| modifyHeaders: (headers: Headers, body: Record<string, any>, apiKey: string) => { | ||
| headers.set("authorization", `Bearer ${apiKey}`) | ||
| }, | ||
| modifyBody: (body: Record<string, any>) => { | ||
| return { | ||
| ...body, | ||
| ...(body.stream ? { stream_options: { include_usage: true } } : {}), | ||
| } | ||
| }, | ||
| streamSeparator: "\n\n", | ||
| createUsageParser: () => { | ||
| let usage: Usage | ||
|
|
||
| return { | ||
| parse: (chunk: string) => { | ||
| if (!chunk.startsWith("data: ")) return | ||
|
|
||
| let json | ||
| try { | ||
| json = JSON.parse(chunk.slice(6)) as { usage?: Usage } | ||
| } catch (e) { | ||
| return | ||
| } | ||
|
|
||
| if (!json.usage) return | ||
| usage = json.usage | ||
| }, | ||
| retrieve: () => usage, | ||
| } | ||
| }, | ||
| normalizeUsage: (usage: Usage) => { | ||
| const inputTokens = usage.prompt_tokens ?? 0 | ||
| const outputTokens = usage.completion_tokens ?? 0 | ||
| const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? undefined | ||
| const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? undefined | ||
| return { | ||
| inputTokens: inputTokens - (cacheReadTokens ?? 0), | ||
| outputTokens, | ||
| reasoningTokens, | ||
| cacheReadTokens, | ||
| cacheWrite5mTokens: undefined, | ||
| cacheWrite1hTokens: undefined, | ||
| } | ||
| }, | ||
| } satisfies ProviderHelper |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import { | |
| toOaCompatibleRequest, | ||
| toOaCompatibleResponse, | ||
| } from "./openai-compatible" | ||
| import { gatewayzHelper } from "./gatewayz" | ||
|
|
||
|
Comment on lines
23
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new helper is imported but never used, so Useful? React with 👍 / 👎. |
||
| export type ProviderHelper = { | ||
| format: ZenData.Format | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Gatewayz helper imported but never used
The
gatewayzHelperis imported but never used or exported, meaning Gatewayz providers will incorrectly fall back tooaCompatHelperin the handler. This causes Gatewayz API calls to use the wrong endpoint path (/chat/completionsinstead of/v1/chat/completions), resulting in failed requests since Gatewayz requires the/v1prefix according to the PR description.