Skip to content

Commit

Permalink
default cross region
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspar09 committed Jan 15, 2025
1 parent 6c23a8a commit b253132
Show file tree
Hide file tree
Showing 3 changed files with 5,097 additions and 4,670 deletions.
31 changes: 27 additions & 4 deletions lib/ai/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import { openai } from '@ai-sdk/openai';
import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai';
import { openai } from "@ai-sdk/openai";
import { experimental_wrapLanguageModel as wrapLanguageModel } from "ai";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
import { customMiddleware } from "./custom-middleware";
import { NodeHttpHandler } from "@smithy/node-http-handler";
import https from "https";

import { customMiddleware } from './custom-middleware';
export function createCustomBedrock() {
const bedrock = createAmazonBedrock({
bedrockOptions: {
requestHandler: new NodeHttpHandler({
httpsAgent: new https.Agent({
keepAlive: true,
maxSockets: 200, // default is 50 per client.
}),

// time limit (ms) for receiving response.
requestTimeout: 60_000_000,

// time limit (ms) for establishing connection.
connectionTimeout: 60_000_000,
}),
},
});
return bedrock;
}

export const customModel = (apiIdentifier: string) => {
const bedrock = createCustomBedrock();
return wrapLanguageModel({
model: openai(apiIdentifier),
model: bedrock("us.anthropic.claude-3-5-sonnet-20240620-v1:0"),
middleware: customMiddleware,
});
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"db:up": "drizzle-kit up"
},
"dependencies": {
"@ai-sdk/amazon-bedrock": "^1.0.8",
"@ai-sdk/openai": "1.0.6",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-python": "^6.1.6",
Expand All @@ -34,6 +35,7 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.3",
"@radix-ui/react-visually-hidden": "^1.1.0",
"@smithy/node-http-handler": "^4.0.1",
"@vercel/analytics": "^1.3.1",
"@vercel/blob": "^0.24.1",
"@vercel/postgres": "^0.10.0",
Expand Down
Loading

0 comments on commit b253132

Please sign in to comment.