Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/db/src/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,19 +875,22 @@ export const CustomLlmExtraHeadersSchema = z.record(z.string(), z.string());

export type CustomLlmExtraHeaders = z.infer<typeof CustomLlmExtraHeadersSchema>;

export const CustomLlmDefinitionSchema = z.object({
internal_id: z.string(),
display_name: z.string(),
context_length: z.number(),
max_completion_tokens: z.number(),
base_url: z.string(),
api_key: z.string(),
organization_ids: z.array(z.string()),
supports_image_input: z.boolean().optional(),
extra_headers: CustomLlmExtraHeadersSchema.optional(),
extra_body: CustomLlmExtraBodySchema.optional(),
opencode_settings: OpenCodeSettingsSchema.optional(),
});
export const CustomLlmDefinitionSchema = z
.object({
internal_id: z.string(),
display_name: z.string(),
context_length: z.number(),
max_completion_tokens: z.number(),
base_url: z.string(),
api_key: z.string(),
organization_ids: z.array(z.string()),
supports_image_input: z.boolean().optional(),
extra_headers: CustomLlmExtraHeadersSchema.optional(),
extra_body: CustomLlmExtraBodySchema.optional(),
remove_from_body: z.array(z.string()).optional(),
opencode_settings: OpenCodeSettingsSchema.optional(),
})
.strict();
Comment thread
chrarnoldus marked this conversation as resolved.

export type CustomLlmDefinition = z.infer<typeof CustomLlmDefinitionSchema>;

Expand Down
14 changes: 10 additions & 4 deletions src/lib/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,18 @@ export async function getProvider(
id: 'custom',
apiUrl: customLlm.base_url,
apiKey: customLlm.api_key,
supportedChatApis: ['chat_completions', 'messages', 'responses'],
supportedChatApis: inferSupportedChatApis(
customLlm.opencode_settings?.ai_sdk_provider ?? 'openrouter'
),
transformRequest(context) {
Object.assign(context.request.body, customLlm.extra_body ?? {});
for (const [key, value] of Object.entries(customLlm.extra_headers ?? {})) {
context.extraHeaders[key] = value;
if (customLlm.remove_from_body) {
const body = context.request.body as Record<string, unknown>;
for (const key of customLlm.remove_from_body ?? []) {
delete body[key];
}
}
Object.assign(context.request.body, customLlm.extra_body ?? {});
Object.assign(context.extraHeaders, customLlm.extra_headers ?? {});
context.request.body.model = customLlm.internal_id;
},
},
Expand Down
Loading