Skip to content

An AI-powered search engine with a generative UI

SUPPORT OPENAI_API_BASE

Li Zhe68cb4bd25e5b
diff --git a/lib/agents/inquire.tsx b/lib/agents/inquire.tsx
index 82254168..1ef9136b 100644
--- a/lib/agents/inquire.tsx
+++ b/lib/agents/inquire.tsx
@@ -1,4 +1,4 @@
-import { openai } from 'ai/openai'
+import { OpenAI } from 'ai/openai'
import { Copilot } from '@/components/copilot'
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import { ExperimentalMessage, experimental_streamObject } from 'ai'
@@ -8,6 +8,11 @@ export async function inquire(
uiStream: ReturnType<typeof createStreamableUI>,
messages: ExperimentalMessage[]
) {
+ const openai = new OpenAI({
+ baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
+ apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY
+ organization: '' // optional organization
+ })
const objectStream = createStreamableValue<PartialInquiry>()
uiStream.update(<Copilot inquiry={objectStream.value} />)
diff --git a/lib/agents/query-suggestor.tsx b/lib/agents/query-suggestor.tsx
index 59dc4f39..a7ed7abd 100644
--- a/lib/agents/query-suggestor.tsx
+++ b/lib/agents/query-suggestor.tsx
@@ -3,12 +3,17 @@ import { ExperimentalMessage, experimental_streamObject } from 'ai'
import { PartialRelated, relatedSchema } from '@/lib/schema/related'
import { Section } from '@/components/section'
import SearchRelated from '@/components/search-related'
-import { openai } from 'ai/openai'
+import { OpenAI } from 'ai/openai'
export async function querySuggestor(
uiStream: ReturnType<typeof createStreamableUI>,
messages: ExperimentalMessage[]
) {
+ const openai = new OpenAI({
+ baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
+ apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY
+ organization: '' // optional organization
+ })
const objectStream = createStreamableValue<PartialRelated>()
uiStream.append(
<Section title="Related" separator={true}>
diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsx
index 0de094cc..8b2c5694 100644
--- a/lib/agents/researcher.tsx
+++ b/lib/agents/researcher.tsx
@@ -7,7 +7,7 @@ import {
} from 'ai'
import { searchSchema } from '@/lib/schema/search'
import { Section } from '@/components/section'
-import { openai } from 'ai/openai'
+import { OpenAI } from 'ai/openai'
import { ToolBadge } from '@/components/tool-badge'
import { SearchSkeleton } from '@/components/search-skeleton'
import { SearchResults } from '@/components/search-results'
@@ -20,6 +20,12 @@ export async function researcher(
streamText: ReturnType<typeof createStreamableValue<string>>,
messages: ExperimentalMessage[]
) {
+ const openai = new OpenAI({
+ baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
+ apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY
+ organization: '' // optional organization
+ })
+
const searchAPI: 'tavily' | 'exa' = 'tavily'
let fullResponse = ''
diff --git a/lib/agents/task-manager.tsx b/lib/agents/task-manager.tsx
index 2bbf5b4e..b7ca3736 100644
--- a/lib/agents/task-manager.tsx
+++ b/lib/agents/task-manager.tsx
@@ -1,9 +1,15 @@
import { ExperimentalMessage, experimental_generateObject } from 'ai'
-import { openai } from 'ai/openai'
+import { OpenAI } from 'ai/openai'
import { nextActionSchema } from '../schema/next-action'
// Decide whether inquiry is required for the user input
export async function taskManager(messages: ExperimentalMessage[]) {
+ const openai = new OpenAI({
+ baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
+ apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY
+ organization: '' // optional organization
+ })
+
const result = await experimental_generateObject({
model: openai.chat('gpt-3.5-turbo'),
system: `As a professional web researcher, your primary objective is to fully comprehend the user's query, conduct thorough web searches to gather the necessary information, and provide an appropriate response.