feat: add support for Claude LLM integration across multiple modules

- Introduced `useClaude` option in `AnalysisPipelineOptions` to toggle Claude LLM usage.
- Updated `processProductChunk` and `analyzeProducts` functions to accept and handle `useClaude` parameter.
- Modified argument parsing in various scripts (`bestsellers-by-category`, `mid-range-sellers-by-category`, `top-monthly-sold-by-category`, etc.) to include `--claude` flag.
- Enhanced `analyzeProductsInternal` to differentiate between LLM providers and handle requests to Claude API.
- Added error handling for Claude API responses and ensured proper configuration for using Claude.
- Updated documentation and usage messages to reflect the new `--claude` flag.
This commit is contained in:
Victor Noguera
2026-05-21 19:57:46 -04:00
parent 0f256be2be
commit 95cebaa27c
12 changed files with 423 additions and 144 deletions

View File

@@ -22,6 +22,7 @@ export type AnalysisPipelineOptions = {
llmBatchDelayMs?: number;
llmRetryDelayMs?: number;
sellability?: SellabilityFilter;
useClaude?: boolean;
};
export function chunkArray<T>(items: T[], chunkSize: number): T[][] {
@@ -60,6 +61,7 @@ export async function processProductChunk(
const llmBatchDelayMs = Math.max(0, options.llmBatchDelayMs ?? 5_000);
const llmRetryDelayMs = Math.max(0, options.llmRetryDelayMs ?? 10_000);
const sellabilityFilter = options.sellability ?? "available";
const useClaude = options.useClaude === true;
console.log(`\nChecking cache for ${products.length} products...`);
const cached = new Map<string, EnrichedProduct>();
@@ -242,6 +244,7 @@ export async function processProductChunk(
try {
verdicts = await analyzeProducts(batch, {
ignoreSellability: sellabilityFilter === "all",
useClaude,
});
} catch {
if (llmRetryDelayMs > 0) {
@@ -250,6 +253,7 @@ export async function processProductChunk(
try {
verdicts = await analyzeProducts(batch, {
ignoreSellability: sellabilityFilter === "all",
useClaude,
});
} catch {
verdicts = null;