Update source code and remove runtime data from tracking
Add gitignore rules for browser session data, SQLite databases, media downloads, and build artifacts. Remove previously tracked runtime files from the repository. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e90213d1ff
commit
dfa0580859
23 files changed
+5324
-347
No files matched your search
@@ -2,6 +2,7 @@ import type { RedditApiClient, RedditPost } from '../reddit/api.js';
|
||||
import type { OpenRouterClient, DetectedGender } from '../ai/openrouter.js';
|
||||
import type { Logger } from '../utils/logger.js';
|
||||
import type { Config } from '../config/index.js';
|
||||
import type { StrategySelector, SelectedStrategy } from './strategy-selector.js';
|
||||
import { downloadImage, bufferToBase64, isValidImageMimeType } from '../utils/image.js';
|
||||
|
||||
export interface ProcessedPost {
|
||||
@@ -9,10 +10,12 @@ export interface ProcessedPost {
|
||||
imageAnalysis: string;
|
||||
detectedGender: DetectedGender;
|
||||
generatedMessage: string;
|
||||
strategyId: string | null;
|
||||
}
|
||||
|
||||
export class ProcessorService {
|
||||
private successfulExamples: string[] = [];
|
||||
private strategySelector: StrategySelector | null = null;
|
||||
|
||||
constructor(
|
||||
private redditApi: RedditApiClient,
|
||||
@@ -21,6 +24,13 @@ export class ProcessorService {
|
||||
private logger: Logger
|
||||
) {}
|
||||
|
||||
setStrategySelector(selector: StrategySelector): void {
|
||||
this.strategySelector = selector;
|
||||
if (selector.hasStrategies()) {
|
||||
this.logger.info(`Strategy A/B testing enabled with ${this.config.strategies.variants.length} variants`);
|
||||
}
|
||||
}
|
||||
|
||||
setSuccessfulExamples(examples: string[]): void {
|
||||
this.successfulExamples = examples;
|
||||
if (examples.length > 0) {
|
||||
@@ -77,14 +87,34 @@ export class ProcessorService {
|
||||
this.logger.debug(`Gender check passed: ${detectedGender}`);
|
||||
}
|
||||
|
||||
// Select a strategy for A/B testing
|
||||
let selectedStrategy: SelectedStrategy | null = null;
|
||||
if (this.strategySelector) {
|
||||
selectedStrategy = this.strategySelector.selectStrategy();
|
||||
if (selectedStrategy) {
|
||||
this.logger.info(`Using strategy "${selectedStrategy.id}" (${selectedStrategy.reason})`);
|
||||
}
|
||||
}
|
||||
|
||||
// Full analysis and message generation (only for matching posts)
|
||||
const { analysis, message } = await this.aiClient.analyzeAndGenerateMessage(
|
||||
base64,
|
||||
imageData.mimeType,
|
||||
post.title,
|
||||
post.author,
|
||||
this.successfulExamples
|
||||
);
|
||||
let analysis;
|
||||
let message;
|
||||
try {
|
||||
({ analysis, message } = await this.aiClient.analyzeAndGenerateMessage(
|
||||
base64,
|
||||
imageData.mimeType,
|
||||
post.title,
|
||||
post.author,
|
||||
this.successfulExamples,
|
||||
selectedStrategy?.promptOverride
|
||||
));
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.startsWith('AI_REFUSAL')) {
|
||||
this.logger.warn(`AI refused to analyze post ${post.id} by u/${post.author} - skipping`);
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!message || message.length < 10) {
|
||||
this.logger.warn(`Generated message too short or empty for post ${post.id}`);
|
||||
@@ -96,6 +126,7 @@ export class ProcessorService {
|
||||
imageAnalysis: analysis.description,
|
||||
detectedGender: analysis.detectedGender,
|
||||
generatedMessage: message,
|
||||
strategyId: selectedStrategy?.id || null,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user