feat: add support for Firecrawl
This commit is contained in:
@ -6,9 +6,8 @@ import { parseStreamingJson, type DeepPartial } from '~/utils/json'
|
||||
import { trimPrompt } from './ai/providers'
|
||||
import { languagePrompt, systemPrompt } from './prompt'
|
||||
import zodToJsonSchema from 'zod-to-json-schema'
|
||||
import { type TavilySearchResponse } from '@tavily/core'
|
||||
import { useTavily } from '~/composables/useTavily'
|
||||
import { useAiModel } from '~/composables/useAiProvider'
|
||||
import type { Locale } from '~/components/LangSwitcher.vue'
|
||||
|
||||
export type ResearchResult = {
|
||||
learnings: string[]
|
||||
@ -141,7 +140,7 @@ function processSearchResult({
|
||||
language,
|
||||
}: {
|
||||
query: string
|
||||
result: TavilySearchResponse
|
||||
result: WebSearchResult[]
|
||||
language: string
|
||||
numLearnings?: number
|
||||
numFollowUpQuestions?: number
|
||||
@ -157,10 +156,7 @@ function processSearchResult({
|
||||
),
|
||||
})
|
||||
const jsonSchema = JSON.stringify(zodToJsonSchema(schema))
|
||||
const contents = result.results
|
||||
.map((item) => item.content)
|
||||
.filter(Boolean)
|
||||
.map((content) => trimPrompt(content, 25_000))
|
||||
const contents = result.map((item) => trimPrompt(item.content, 25_000))
|
||||
const prompt = [
|
||||
`Given the following contents from a SERP search for the query <query>${query}</query>, generate a list of learnings from the contents. Return a maximum of ${numLearnings} learnings, but feel free to return less if the contents are clear. Make sure each learning is unique and not similar to each other. The learnings should be concise and to the point, as detailed and information dense as possible. Make sure to include any entities like people, places, companies, products, things, etc in the learnings, as well as any exact metrics, numbers, or dates. The learnings will be used to research the topic further.`,
|
||||
`<contents>${contents
|
||||
@ -219,7 +215,7 @@ export async function deepResearch({
|
||||
query,
|
||||
breadth,
|
||||
maxDepth,
|
||||
language,
|
||||
languageCode,
|
||||
learnings = [],
|
||||
visitedUrls = [],
|
||||
onProgress,
|
||||
@ -230,7 +226,8 @@ export async function deepResearch({
|
||||
query: string
|
||||
breadth: number
|
||||
maxDepth: number
|
||||
language: string
|
||||
/** Language code */
|
||||
languageCode: Locale
|
||||
learnings?: string[]
|
||||
visitedUrls?: string[]
|
||||
onProgress: (step: ResearchStep) => void
|
||||
@ -240,6 +237,7 @@ export async function deepResearch({
|
||||
searchLanguage?: string
|
||||
}): Promise<ResearchResult> {
|
||||
const { t } = useNuxtApp().$i18n
|
||||
const language = t('language', {}, { locale: languageCode })
|
||||
|
||||
try {
|
||||
const searchQueriesResult = generateSearchQueries({
|
||||
@ -321,17 +319,16 @@ export async function deepResearch({
|
||||
})
|
||||
try {
|
||||
// Use Tavily to search the web
|
||||
const result = await useTavily().search(searchQuery.query, {
|
||||
const result = await useWebSearch()(searchQuery.query, {
|
||||
maxResults: 5,
|
||||
lang: languageCode,
|
||||
})
|
||||
console.log(
|
||||
`Ran ${searchQuery.query}, found ${result.results.length} contents`,
|
||||
`Ran ${searchQuery.query}, found ${result.length} contents`,
|
||||
)
|
||||
|
||||
// Collect URLs from this search
|
||||
const newUrls = result.results
|
||||
.map((item) => item.url)
|
||||
.filter(Boolean)
|
||||
const newUrls = result.map((item) => item.url).filter(Boolean)
|
||||
onProgress({
|
||||
type: 'search_complete',
|
||||
urls: newUrls,
|
||||
@ -429,7 +426,7 @@ export async function deepResearch({
|
||||
onProgress,
|
||||
currentDepth: nextDepth,
|
||||
nodeId: childNodeId(nodeId, i),
|
||||
language,
|
||||
languageCode,
|
||||
})
|
||||
} else {
|
||||
return {
|
||||
|
Reference in New Issue
Block a user