|
1 |
| -import { openai } from '@ai-sdk/openai'; |
2 |
| -import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai'; |
| 1 | +import { openai } from "@ai-sdk/openai"; |
| 2 | +import { experimental_wrapLanguageModel as wrapLanguageModel } from "ai"; |
| 3 | +import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock"; |
| 4 | +import { customMiddleware } from "./custom-middleware"; |
| 5 | +import { NodeHttpHandler } from "@smithy/node-http-handler"; |
| 6 | +import https from "https"; |
3 | 7 |
|
4 |
| -import { customMiddleware } from './custom-middleware'; |
| 8 | +export function createCustomBedrock() { |
| 9 | + const bedrock = createAmazonBedrock({ |
| 10 | + bedrockOptions: { |
| 11 | + requestHandler: new NodeHttpHandler({ |
| 12 | + httpsAgent: new https.Agent({ |
| 13 | + keepAlive: true, |
| 14 | + maxSockets: 200, // default is 50 per client. |
| 15 | + }), |
| 16 | + |
| 17 | + // time limit (ms) for receiving response. |
| 18 | + requestTimeout: 60_000_000, |
| 19 | + |
| 20 | + // time limit (ms) for establishing connection. |
| 21 | + connectionTimeout: 60_000_000, |
| 22 | + }), |
| 23 | + }, |
| 24 | + }); |
| 25 | + return bedrock; |
| 26 | +} |
5 | 27 |
|
6 | 28 | export const customModel = (apiIdentifier: string) => {
|
| 29 | + const bedrock = createCustomBedrock(); |
7 | 30 | return wrapLanguageModel({
|
8 |
| - model: openai(apiIdentifier), |
| 31 | + model: bedrock("us.anthropic.claude-3-5-sonnet-20240620-v1:0"), |
9 | 32 | middleware: customMiddleware,
|
10 | 33 | });
|
11 | 34 | };
|
0 commit comments