@plust/datasleuth
Version:
Build LLM-powered research pipelines and output structured data.
110 lines (109 loc) • 4.27 kB
TypeScript
import { createStep } from '../utils/steps.js';
import { z } from 'zod';
import { LanguageModel } from 'ai';
/**
* Schema for analysis results
*
* Defines the structure for analysis output, including insights, confidence score,
* supporting evidence, and recommendations.
*
* @private
*/
declare const analysisResultSchema: z.ZodObject<{
focus: z.ZodString;
insights: z.ZodArray<z.ZodString, "many">;
confidence: z.ZodNumber;
supportingEvidence: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
limitations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
recommendations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
confidence: number;
focus: string;
insights: string[];
supportingEvidence?: string[] | undefined;
limitations?: string[] | undefined;
recommendations?: string[] | undefined;
}, {
confidence: number;
focus: string;
insights: string[];
supportingEvidence?: string[] | undefined;
limitations?: string[] | undefined;
recommendations?: string[] | undefined;
}>;
export type AnalysisResult = z.infer<typeof analysisResultSchema>;
/**
* Options for the analysis step
*/
export interface AnalyzeOptions {
/** Focus area for analysis (e.g., 'market-trends', 'technical-details') */
focus: string;
/** Model to use for analysis (from the AI SDK) */
llm?: LanguageModel;
/** Temperature for the LLM (0.0 to 1.0) */
temperature?: number;
/** Depth of analysis ('basic', 'detailed', 'comprehensive') */
depth?: 'basic' | 'detailed' | 'comprehensive';
/** Whether to include supporting evidence in the analysis */
includeEvidence?: boolean;
/** Whether to include recommendations in the analysis */
includeRecommendations?: boolean;
/** Whether to add the analysis to the final results */
includeInResults?: boolean;
/** Custom prompt for analysis */
customPrompt?: string;
/** Whether to proceed if no content is available */
allowEmptyContent?: boolean;
/** Maximum content size for analysis (in characters) */
maxContentSize?: number;
/** Retry configuration for LLM calls */
retry?: {
/** Maximum number of retries */
maxRetries?: number;
/** Base delay between retries in ms */
baseDelay?: number;
};
}
/**
* Creates an analysis step for the research pipeline
*
* This function creates a step that analyzes research data using AI to extract insights,
* identify patterns, and provide recommendations based on the specified focus area.
* The step will process available data from previous steps, such as extracted content
* and fact-checked statements.
*
* @param options - Configuration options for the analysis step
* @param options.focus - The focus area for analysis (e.g., 'market-trends', 'technical-details')
* @param options.llm - Language model to use (falls back to state.defaultLLM if not provided)
* @param options.temperature - Temperature setting for the LLM (default: 0.3)
* @param options.depth - Depth of analysis: 'basic', 'detailed', or 'comprehensive' (default: 'detailed')
* @param options.includeEvidence - Whether to include supporting evidence (default: true)
* @param options.includeRecommendations - Whether to include recommendations (default: true)
* @param options.includeInResults - Whether to include analysis in final results (default: true)
* @param options.allowEmptyContent - Whether to proceed if no content is available (default: false)
* @param options.maxContentSize - Maximum content size in characters (default: 10000)
*
* @returns A configured analysis step for the research pipeline
*
* @example
* ```typescript
* import { research, analyze } from '@plust/datasleuth';
* import { openai } from '@ai-sdk/openai';
*
* const results = await research({
* query: "Impact of AI on healthcare",
* steps: [
* // Other steps...
* analyze({
* focus: 'ethical-considerations',
* llm: openai('gpt-4o'),
* depth: 'comprehensive',
* includeRecommendations: true
* })
* ],
* outputSchema: outputSchema
* });
* ```
*/
export declare function analyze(options: AnalyzeOptions): ReturnType<typeof createStep>;
export {};