2025-09-03 07:20:39 +08:00
|
|
|
import { createGateway } from '@ai-sdk/gateway';
|
|
|
|
import { wrapLanguageModel } from 'ai';
|
|
|
|
import { BraintrustMiddleware } from 'braintrust';
|
|
|
|
|
2025-09-03 11:21:33 +08:00
|
|
|
export const DEFAULT_ANTHROPIC_OPTIONS = {
|
|
|
|
gateway: {
|
2025-09-10 04:22:44 +08:00
|
|
|
order: ['anthropic', 'bedrock', 'vertex'],
|
2025-09-03 11:21:33 +08:00
|
|
|
},
|
2025-09-03 11:49:00 +08:00
|
|
|
headers: {},
|
2025-09-10 04:12:42 +08:00
|
|
|
anthropic: { cacheControl: { type: 'ephemeral' } },
|
2025-09-03 11:21:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const DEFAULT_OPENAI_OPTIONS = {
|
|
|
|
gateway: {
|
|
|
|
order: ['openai'],
|
2025-09-25 02:31:57 +08:00
|
|
|
},
|
|
|
|
openai: {
|
|
|
|
parallelToolCalls: false,
|
|
|
|
reasoningEffort: 'minimal',
|
|
|
|
verbosity: 'low',
|
2025-09-03 11:21:33 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2025-09-10 01:52:01 +08:00
|
|
|
// Create gateway instance
|
2025-09-03 07:20:39 +08:00
|
|
|
const gateway = createGateway({
|
|
|
|
...(process.env.AI_GATEWAY_API_KEY && { apiKey: process.env.AI_GATEWAY_API_KEY }),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Export a function that creates wrapped models with Braintrust middleware
|
|
|
|
export const gatewayModel = (modelId: string) => {
|
|
|
|
return wrapLanguageModel({
|
|
|
|
model: gateway(modelId),
|
|
|
|
middleware: BraintrustMiddleware({ debug: true }),
|
|
|
|
});
|
|
|
|
};
|