feat(DeepResearch): show URL title in "Visited URLs" if possible

This commit is contained in:
AnotiaWang
2025-02-15 21:48:35 +08:00
parent f8af8b4afc
commit 3830875858
4 changed files with 23 additions and 22 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { import {
deepResearch, deepResearch,
type PartialSearchResult, type PartialProcessedSearchResult,
type ResearchStep, type ResearchStep,
} from '~/lib/deep-research' } from '~/lib/deep-research'
import type { TreeNode } from './Tree.vue' import type { TreeNode } from './Tree.vue'
@ -26,7 +26,7 @@
children: [], children: [],
}) })
const selectedNode = ref<TreeNode>() const selectedNode = ref<TreeNode>()
const searchResults = ref<Record<string, PartialSearchResult>>({}) const searchResults = ref<Record<string, PartialProcessedSearchResult>>({})
const isLoading = ref(false) const isLoading = ref(false)
// Inject global data from index.vue // Inject global data from index.vue
@ -101,7 +101,7 @@
case 'search_complete': { case 'search_complete': {
console.log(`[DeepResearch] node ${nodeId} search complete:`, step) console.log(`[DeepResearch] node ${nodeId} search complete:`, step)
if (node) { if (node) {
node.visitedUrls = step.urls node.searchResults = step.results
} }
break break
} }
@ -278,17 +278,17 @@
</h3> </h3>
<ul class="list-disc list-inside"> <ul class="list-disc list-inside">
<li <li
v-for="(url, index) in selectedNode.visitedUrls" v-for="(item, index) in selectedNode.searchResults"
class="whitespace-pre-wrap break-all" class="whitespace-pre-wrap break-all"
:key="index" :key="index"
> >
<UButton <UButton
class="!p-0 contents" class="!p-0 contents"
variant="link" variant="link"
:href="url" :href="item.url"
target="_blank" target="_blank"
> >
{{ url }} {{ item.title || item.url }}
</UButton> </UButton>
</li> </li>
</ul> </ul>

View File

@ -14,8 +14,9 @@
generateQueriesReasoning?: string generateQueriesReasoning?: string
/** Reasoning content when generating learnings for this iteration. */ /** Reasoning content when generating learnings for this iteration. */
generateLearningsReasoning?: string generateLearningsReasoning?: string
searchResults?: WebSearchResult[]
/** Learnings from search results */
learnings?: string[] learnings?: string[]
visitedUrls?: string[]
status?: TreeNodeStatus status?: TreeNodeStatus
children: TreeNode[] children: TreeNode[]
error?: string error?: string

View File

@ -23,8 +23,8 @@ export interface WriteFinalReportParams {
// Used for streaming response // Used for streaming response
export type SearchQuery = z.infer<typeof searchQueriesTypeSchema>['queries'][0] export type SearchQuery = z.infer<typeof searchQueriesTypeSchema>['queries'][0]
export type PartialSearchQuery = DeepPartial<SearchQuery> export type PartialSearchQuery = DeepPartial<SearchQuery>
export type SearchResult = z.infer<typeof searchResultTypeSchema> export type ProcessedSearchResult = z.infer<typeof searchResultTypeSchema>
export type PartialSearchResult = DeepPartial<SearchResult> export type PartialProcessedSearchResult = DeepPartial<ProcessedSearchResult>
export type ResearchStep = export type ResearchStep =
| { type: 'generating_query'; result: PartialSearchQuery; nodeId: string } | { type: 'generating_query'; result: PartialSearchQuery; nodeId: string }
@ -36,11 +36,11 @@ export type ResearchStep =
nodeId: string nodeId: string
} }
| { type: 'searching'; query: string; nodeId: string } | { type: 'searching'; query: string; nodeId: string }
| { type: 'search_complete'; urls: string[]; nodeId: string } | { type: 'search_complete'; results: WebSearchResult[]; nodeId: string }
| { | {
type: 'processing_serach_result' type: 'processing_serach_result'
query: string query: string
result: PartialSearchResult result: PartialProcessedSearchResult
nodeId: string nodeId: string
} }
| { | {
@ -51,7 +51,7 @@ export type ResearchStep =
| { | {
type: 'processed_search_result' type: 'processed_search_result'
query: string query: string
result: SearchResult result: ProcessedSearchResult
nodeId: string nodeId: string
} }
| { type: 'error'; message: string; nodeId: string } | { type: 'error'; message: string; nodeId: string }
@ -134,13 +134,13 @@ export const searchResultTypeSchema = z.object({
}) })
function processSearchResult({ function processSearchResult({
query, query,
result, results,
numLearnings = 3, numLearnings = 3,
numFollowUpQuestions = 3, numFollowUpQuestions = 3,
language, language,
}: { }: {
query: string query: string
result: WebSearchResult[] results: WebSearchResult[]
language: string language: string
numLearnings?: number numLearnings?: number
numFollowUpQuestions?: number numFollowUpQuestions?: number
@ -156,7 +156,7 @@ function processSearchResult({
), ),
}) })
const jsonSchema = JSON.stringify(zodToJsonSchema(schema)) const jsonSchema = JSON.stringify(zodToJsonSchema(schema))
const contents = result.map((item) => trimPrompt(item.content, 25_000)) const contents = results.map((item) => trimPrompt(item.content, 25_000))
const prompt = [ 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.`, `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 `<contents>${contents
@ -319,19 +319,19 @@ export async function deepResearch({
}) })
try { try {
// Use Tavily to search the web // Use Tavily to search the web
const result = await useWebSearch()(searchQuery.query, { const results = await useWebSearch()(searchQuery.query, {
maxResults: 5, maxResults: 5,
lang: languageCode, lang: languageCode,
}) })
console.log( console.log(
`Ran ${searchQuery.query}, found ${result.length} contents`, `Ran ${searchQuery.query}, found ${results.length} contents`,
) )
// Collect URLs from this search // Collect URLs from this search
const newUrls = result.map((item) => item.url).filter(Boolean) const newUrls = results.map((item) => item.url).filter(Boolean)
onProgress({ onProgress({
type: 'search_complete', type: 'search_complete',
urls: newUrls, results,
nodeId: childNodeId(nodeId, i), nodeId: childNodeId(nodeId, i),
}) })
// Breadth for the next search is half of the current breadth // Breadth for the next search is half of the current breadth
@ -339,11 +339,11 @@ export async function deepResearch({
const searchResultGenerator = processSearchResult({ const searchResultGenerator = processSearchResult({
query: searchQuery.query, query: searchQuery.query,
result, results,
numFollowUpQuestions: nextBreadth, numFollowUpQuestions: nextBreadth,
language, language,
}) })
let searchResult: PartialSearchResult = {} let searchResult: PartialProcessedSearchResult = {}
for await (const chunk of parseStreamingJson( for await (const chunk of parseStreamingJson(
searchResultGenerator.fullStream, searchResultGenerator.fullStream,

View File

@ -1,3 +1,3 @@
{ {
"version": "1.0.5" "version": "1.0.7"
} }