Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import RetrieveSection from '@/components/retrieve-section'
import { VideoSearchSection } from '@/components/video-search-section'
import { MapQueryHandler } from '@/components/map/map-query-handler'
import { getCurrentUserIdOnServer } from '@/lib/auth/get-current-user'
import { PartialRelated } from '@/lib/schema/related'

// Define the type for related queries
type RelatedQueries = {
Expand Down Expand Up @@ -461,14 +462,18 @@ async function submit(formData?: FormData, skip?: boolean) {
}

if (!errorOccurred) {
const relatedQueries = await querySuggestor(uiStream, messages)
let relatedQueries: PartialRelated = {}
try {
relatedQueries = await querySuggestor(uiStream, messages)
} catch (err) {
console.error('querySuggestor failed, continuing without related queries:', err)
}
uiStream.append(
<Section title="Follow-up">
<FollowupPanel />
</Section>
)


aiState.done({
...aiState.get(),
messages: [
Expand Down
4 changes: 2 additions & 2 deletions components/empty-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function EmptyScreen({
className?: string;
}) {
return (
<div className={`mx-auto w-full transition-all text-center ${className}`}>
<div className={`mx-auto w-full transition-all ${className}`}>
<div className="bg-background p-2">
<div className="mt-4 flex flex-col items-center space-y-2 mb-4">
<div className="mt-4 flex flex-col items-start space-y-2 mb-4">
{exampleMessages.map((item) => {
const Icon = item.icon;
return (
Expand Down
26 changes: 15 additions & 11 deletions lib/agents/query-suggestor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export async function querySuggestor(
)

let finalRelatedQueries: PartialRelated = {}
const result = await streamObject({
model: (await getModel(false, "auxiliary")) as LanguageModel,
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.
try {
const result = await streamObject({
model: (await getModel(false, "auxiliary")) as LanguageModel,
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.

For instance, if the original query was "Starship's third test flight key milestones", your output should follow this format:

Expand All @@ -33,15 +34,18 @@ export async function querySuggestor(

Aim to create queries that progressively delve into more specific aspects, implications, or adjacent topics related to the initial query. The goal is to anticipate the user's potential information needs and guide them towards a more comprehensive understanding of the subject matter.
Please match the language of the response to the user's language.`,
messages,
schema: relatedSchema
})

for await (const obj of result.partialObjectStream) {
if (obj && typeof obj === 'object' && 'items' in obj) {
objectStream.update(obj as PartialRelated)
finalRelatedQueries = obj as PartialRelated
messages,
schema: relatedSchema
})

for await (const obj of result.partialObjectStream) {
if (obj && typeof obj === 'object' && 'items' in obj) {
objectStream.update(obj as PartialRelated)
finalRelatedQueries = obj as PartialRelated
}
}
} catch (err) {
console.error('querySuggestor: model call failed, returning empty queries:', err)
}

objectStream.done()
Expand Down