feat: update research pipeline with Tavily search and progress stages
This commit is contained in:
@@ -3,7 +3,9 @@ import type {
|
|||||||
ComparisonResult,
|
ComparisonResult,
|
||||||
ResearchProgress,
|
ResearchProgress,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { generateComparison } from "./providers/openai";
|
import { searchItem, type SearchResult } from "./providers/tavily";
|
||||||
|
import { generateComparisonWithResearch } from "./providers/openai";
|
||||||
|
import { getActiveProvider } from "./providers";
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
ComparisonRequest,
|
ComparisonRequest,
|
||||||
@@ -24,6 +26,28 @@ export async function* runResearch(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const provider = getActiveProvider();
|
||||||
|
const searchResults: Record<string, SearchResult[]> = {};
|
||||||
|
|
||||||
|
if (provider.hasSearch) {
|
||||||
|
for (let i = 0; i < request.items.length; i++) {
|
||||||
|
const item = request.items[i];
|
||||||
|
const results = await searchItem(item, request.query);
|
||||||
|
searchResults[item] = results;
|
||||||
|
|
||||||
|
yield {
|
||||||
|
stage: "searching",
|
||||||
|
item,
|
||||||
|
results: results.length,
|
||||||
|
};
|
||||||
|
|
||||||
|
yield {
|
||||||
|
stage: "researching",
|
||||||
|
item,
|
||||||
|
progress: Math.round(((i + 1) / request.items.length) * 50),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (let i = 0; i < request.items.length; i++) {
|
for (let i = 0; i < request.items.length; i++) {
|
||||||
yield {
|
yield {
|
||||||
stage: "researching",
|
stage: "researching",
|
||||||
@@ -31,14 +55,15 @@ export async function* runResearch(
|
|||||||
progress: Math.round(((i + 0.5) / request.items.length) * 80),
|
progress: Math.round(((i + 0.5) / request.items.length) * 80),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
stage: "synthesizing",
|
stage: "synthesizing",
|
||||||
message: "Synthesizing research into structured comparison...",
|
message: `Synthesizing research into structured comparison using ${provider.name}...`,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await generateComparison(request);
|
const result = await provider.synthesize(request, searchResults);
|
||||||
yield { stage: "complete", result };
|
yield { stage: "complete", result };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
yield {
|
yield {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export interface ComparisonResult {
|
|||||||
|
|
||||||
export type ResearchProgress =
|
export type ResearchProgress =
|
||||||
| { stage: "parsing"; message: string }
|
| { stage: "parsing"; message: string }
|
||||||
|
| { stage: "searching"; item: string; results: number }
|
||||||
| { stage: "researching"; item: string; progress: number }
|
| { stage: "researching"; item: string; progress: number }
|
||||||
| { stage: "synthesizing"; message: string }
|
| { stage: "synthesizing"; message: string }
|
||||||
| { stage: "complete"; result: ComparisonResult }
|
| { stage: "complete"; result: ComparisonResult }
|
||||||
|
|||||||
Reference in New Issue
Block a user