Skip to content

An AI-powered search engine with a generative UI

changed deprecated imports(ExperimentalMessage and experimental_streamObject)

Dhrish Parekhf7e776001662
diff --git a/app/actions.tsx b/app/actions.tsx
index 9ee6db02..a5d68c50 100644
--- a/app/actions.tsx
+++ b/app/actions.tsx
@@ -6,7 +6,7 @@ import {
getAIState,
getMutableAIState
} from 'ai/rsc'
-import { ExperimentalMessage, nanoid, ToolResultPart } from 'ai'
+import { CoreMessage, nanoid, ToolResultPart } from 'ai'
import { Spinner } from '@/components/ui/spinner'
import { Section } from '@/components/section'
import { FollowupPanel } from '@/components/followup-panel'
@@ -29,9 +29,7 @@ async function submit(formData?: FormData, skip?: boolean) {
const isGenerating = createStreamableValue(true)
const isCollapsed = createStreamableValue(false)
// Get the messages from the state, filter out the tool messages
- const messages: ExperimentalMessage[] = [
- ...(aiState.get().messages as any[])
- ].filter(
+ const messages: CoreMessage[] = [...(aiState.get().messages as any[])].filter(
message =>
message.role !== 'tool' &&
message.type !== 'followup' &&
@@ -168,7 +166,7 @@ async function submit(formData?: FormData, skip?: boolean) {
type: 'tool'
}
: msg
- ) as ExperimentalMessage[]
+ ) as CoreMessage[]
answer = await writer(uiStream, streamText, modifiedMessages)
} else {
streamText.done()
diff --git a/lib/agents/inquire.tsx b/lib/agents/inquire.tsx
index 192ccc5f..e83e1d71 100644
--- a/lib/agents/inquire.tsx
+++ b/lib/agents/inquire.tsx
@@ -1,12 +1,12 @@
import { OpenAI } from '@ai-sdk/openai'
import { Copilot } from '@/components/copilot'
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
-import { ExperimentalMessage, experimental_streamObject } from 'ai'
+import { CoreMessage, streamObject } from 'ai'
import { PartialInquiry, inquirySchema } from '@/lib/schema/inquiry'
export async function inquire(
uiStream: ReturnType<typeof createStreamableUI>,
- messages: ExperimentalMessage[]
+ messages: CoreMessage[]
) {
const openai = new OpenAI({
baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
@@ -17,7 +17,7 @@ export async function inquire(
uiStream.update(<Copilot inquiry={objectStream.value} />)
let finalInquiry: PartialInquiry = {}
- await experimental_streamObject({
+ await streamObject({
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
system: `As a professional web researcher, your role is to deepen your understanding of the user's input by conducting further inquiries when necessary.
After receiving an initial response from the user, carefully assess whether additional questions are absolutely essential to provide a comprehensive and accurate answer. Only proceed with further inquiries if the available information is insufficient or ambiguous.
diff --git a/lib/agents/query-suggestor.tsx b/lib/agents/query-suggestor.tsx
index c7e7b4f4..d64c920f 100644
--- a/lib/agents/query-suggestor.tsx
+++ b/lib/agents/query-suggestor.tsx
@@ -1,5 +1,5 @@
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
-import { ExperimentalMessage, experimental_streamObject } from 'ai'
+import { CoreMessage, streamObject } from 'ai'
import { PartialRelated, relatedSchema } from '@/lib/schema/related'
import { Section } from '@/components/section'
import SearchRelated from '@/components/search-related'
@@ -7,7 +7,7 @@ import { OpenAI } from '@ai-sdk/openai'
export async function querySuggestor(
uiStream: ReturnType<typeof createStreamableUI>,
- messages: ExperimentalMessage[]
+ messages: CoreMessage[]
) {
const openai = new OpenAI({
baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
@@ -22,7 +22,7 @@ export async function querySuggestor(
)
let finalRelatedQueries: PartialRelated = {}
- await experimental_streamObject({
+ await streamObject({
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
system: `As a professional web researcher, your task is to generate a set of three queries that explore the subject matter more deeply, building upon the initial query and the information uncovered in its search results.
diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsx
index 3a01bfaa..c42edf60 100644
--- a/lib/agents/researcher.tsx
+++ b/lib/agents/researcher.tsx
@@ -1,6 +1,6 @@
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import {
- ExperimentalMessage,
+ CoreMessage,
ToolCallPart,
ToolResultPart,
experimental_streamText
@@ -16,7 +16,7 @@ import { SearchSection } from '@/components/search-section'
export async function researcher(
uiStream: ReturnType<typeof createStreamableUI>,
streamText: ReturnType<typeof createStreamableValue<string>>,
- messages: ExperimentalMessage[],
+ messages: CoreMessage[],
useSpecificModel?: boolean
) {
const openai = new OpenAI({
diff --git a/lib/agents/task-manager.tsx b/lib/agents/task-manager.tsx
index eb9e9cb5..4d8c4c6f 100644
--- a/lib/agents/task-manager.tsx
+++ b/lib/agents/task-manager.tsx
@@ -1,9 +1,9 @@
-import { ExperimentalMessage, experimental_generateObject } from 'ai'
+import { CoreMessage, experimental_generateObject } from 'ai'
import { OpenAI } from '@ai-sdk/openai'
import { nextActionSchema } from '../schema/next-action'
// Decide whether inquiry is required for the user input
-export async function taskManager(messages: ExperimentalMessage[]) {
+export async function taskManager(messages: CoreMessage[]) {
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
diff --git a/lib/agents/writer.tsx b/lib/agents/writer.tsx
index 43109482..e56ef757 100644
--- a/lib/agents/writer.tsx
+++ b/lib/agents/writer.tsx
@@ -1,19 +1,19 @@
import { OpenAI } from '@ai-sdk/openai'
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
-import { ExperimentalMessage, experimental_streamText } from 'ai'
+import { CoreMessage, experimental_streamText } from 'ai'
import { Section } from '@/components/section'
import { BotMessage } from '@/components/message'
-import { createAnthropic } from '@ai-sdk/anthropic';
+import { createAnthropic } from '@ai-sdk/anthropic'
export async function writer(
uiStream: ReturnType<typeof createStreamableUI>,
streamText: ReturnType<typeof createStreamableValue<string>>,
- messages: ExperimentalMessage[]
+ messages: CoreMessage[]
) {
- var openai, anthropic;
+ var openai, anthropic
if (process.env.SPECIFIC_PROVIDER === 'anthropic') {
anthropic = createAnthropic({
baseUrl: process.env.SPECIFIC_API_BASE,
- apiKey: process.env.SPECIFIC_API_KEY,
+ apiKey: process.env.SPECIFIC_API_KEY
})
} else {
openai = new OpenAI({
@@ -31,9 +31,12 @@ export async function writer(
uiStream.append(answerSection)
await experimental_streamText({
- model: process.env.SPECIFIC_PROVIDER === 'anthropic' ?
- anthropic!(process.env.SPECIFIC_API_MODEL || 'claude-3-haiku-20240307') :
- openai!.chat(process.env.SPECIFIC_API_MODEL || 'llama3-70b-8192'),
+ model:
+ process.env.SPECIFIC_PROVIDER === 'anthropic'
+ ? anthropic!(
+ process.env.SPECIFIC_API_MODEL || 'claude-3-haiku-20240307'
+ )
+ : openai!.chat(process.env.SPECIFIC_API_MODEL || 'llama3-70b-8192'),
maxTokens: 2500,
system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.