From 6b01a3f7e7fc0d68c31904a52c1968ce7ec33140 Mon Sep 17 00:00:00 2001 From: Harry Yep Date: Tue, 23 Apr 2024 18:28:39 +0800 Subject: [PATCH] fix: ai sdk --- app/api/search/google/route.ts | 4 ++-- lib/provider/Anthropic.ts | 4 ++-- lib/provider/Google.ts | 4 ++-- lib/provider/OpenAI.ts | 4 ++-- lib/search/challenger.tsx | 4 ++-- lib/search/clarifier.tsx | 4 ++-- lib/search/illustrator.tsx | 4 ++-- lib/search/searcher.tsx | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/api/search/google/route.ts b/app/api/search/google/route.ts index daa53394..26894788 100644 --- a/app/api/search/google/route.ts +++ b/app/api/search/google/route.ts @@ -1,4 +1,4 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; import { experimental_streamText, ExperimentalMessage, StreamingTextResponse, ToolCallPart, ToolResultPart } from 'ai'; import { createStreamableUI, createStreamableValue } from 'ai/rsc'; @@ -28,7 +28,7 @@ export async function POST(req: Request) { const uiStream = createStreamableUI(); - const openai = new OpenAI({ + const openai = createOpenAI({ apiKey: config.provider?.apiKey ?? process.env.OPENAI_API_KEY ?? '', baseUrl: config.provider?.endpoint ?? process.env.OPENAI_API_ENDPOINT ?? 'https://api.openai.com/v1', }); diff --git a/lib/provider/Anthropic.ts b/lib/provider/Anthropic.ts index cb019846..e035c228 100644 --- a/lib/provider/Anthropic.ts +++ b/lib/provider/Anthropic.ts @@ -1,5 +1,5 @@ -import { Anthropic } from '@ai-sdk/anthropic'; +import { createAnthropic } from '@ai-sdk/anthropic'; -export const anthropic = new Anthropic({ +export const anthropic = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY ?? '', }); diff --git a/lib/provider/Google.ts b/lib/provider/Google.ts index c4ab1b7f..9e463009 100644 --- a/lib/provider/Google.ts +++ b/lib/provider/Google.ts @@ -1,6 +1,6 @@ -import { Google } from '@ai-sdk/google'; +import { createGoogleGenerativeAI } from '@ai-sdk/google'; -export const google = new Google({ +export const google = createGoogleGenerativeAI({ apiKey: process.env.GOOGLE_API_KEY ?? '', // baseURL: process.env.OPENAI_API_ENDPOINT ?? '', }); diff --git a/lib/provider/OpenAI.ts b/lib/provider/OpenAI.ts index cd698a5e..c2ae2969 100644 --- a/lib/provider/OpenAI.ts +++ b/lib/provider/OpenAI.ts @@ -1,6 +1,6 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; -export const openai = new OpenAI({ +export const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY ?? '', // baseURL: process.env.OPENAI_API_ENDPOINT ?? '', }); diff --git a/lib/search/challenger.tsx b/lib/search/challenger.tsx index 48d19462..1aae4c68 100644 --- a/lib/search/challenger.tsx +++ b/lib/search/challenger.tsx @@ -1,4 +1,4 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; import { experimental_generateObject, ExperimentalMessage } from 'ai'; import { z } from 'zod'; @@ -13,7 +13,7 @@ export const challengerSchema = z.object({ export const challenger = async (messages: ExperimentalMessage[], model: SimpleModel, currentProviderSettings: ProviderSetting | null) => { 'use server'; - const openai = new OpenAI({ + const openai = createOpenAI({ apiKey: currentProviderSettings?.OpenAI?.apiKey ?? process.env.OPENAI_API_KEY ?? '', // baseURL: currentProviderSettings?.OpenAI?.endpoint ?? process.env.OPENAI_API_ENDPOINT ?? 'https://api.openai.com/v1', }); diff --git a/lib/search/clarifier.tsx b/lib/search/clarifier.tsx index ffb6d58b..ea58a8ff 100644 --- a/lib/search/clarifier.tsx +++ b/lib/search/clarifier.tsx @@ -1,4 +1,4 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; import { experimental_streamObject, ExperimentalMessage } from 'ai'; import { createStreamableUI, createStreamableValue } from 'ai/rsc'; import { z } from 'zod'; @@ -26,7 +26,7 @@ export const clarifier = async (uiStream: ReturnType, let clarifierResponse: TClarifier = {}; - const openai = new OpenAI({ + const openai = createOpenAI({ apiKey: currentProviderSettings?.OpenAI?.apiKey ?? process.env.OPENAI_API_KEY ?? '', // baseURL: currentProviderSettings?.OpenAI?.endpoint ?? process.env.OPENAI_API_ENDPOINT ?? 'https://api.openai.com/v1', }); diff --git a/lib/search/illustrator.tsx b/lib/search/illustrator.tsx index b5e0fcc6..6df8aec9 100644 --- a/lib/search/illustrator.tsx +++ b/lib/search/illustrator.tsx @@ -1,4 +1,4 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; import { experimental_streamObject, ExperimentalMessage } from 'ai'; import { createStreamableUI, createStreamableValue } from 'ai/rsc'; import { z } from 'zod'; @@ -20,7 +20,7 @@ export const illustrator = async (uiStream: ReturnType); - const openai = new OpenAI({ + const openai = createOpenAI({ apiKey: currentProviderSettings?.OpenAI?.apiKey ?? process.env.OPENAI_API_KEY ?? '', // baseURL: currentProviderSettings?.OpenAI?.endpoint ?? process.env.OPENAI_API_ENDPOINT ?? 'https://api.openai.com/v1', }); diff --git a/lib/search/searcher.tsx b/lib/search/searcher.tsx index 48898452..d691b0f8 100644 --- a/lib/search/searcher.tsx +++ b/lib/search/searcher.tsx @@ -1,4 +1,4 @@ -import { OpenAI } from '@ai-sdk/openai'; +import { createOpenAI } from '@ai-sdk/openai'; import { experimental_streamText, ExperimentalMessage, ToolCallPart, ToolResultPart } from 'ai'; import { createStreamableUI, createStreamableValue } from 'ai/rsc'; import { z } from 'zod'; @@ -32,7 +32,7 @@ export const searcher = async ( let fullResponse = ''; - const openai = new OpenAI({ + const openai = createOpenAI({ apiKey: currentProviderSettings?.OpenAI?.apiKey ?? process.env.OPENAI_API_KEY ?? '', // baseURL: currentProviderSettings?.OpenAI?.endpoint ?? process.env.OPENAI_API_ENDPOINT ?? 'https://api.openai.com/v1', });