Add varied messaging experiments
This commit is contained in:
1 parent
43f459a024
commit
23d4c3a320
12 files changed
+217
-72
No files matched your search
+40
-17
@@ -256,6 +256,7 @@ ${this.config.openrouter.imageAnalysisPrompt}`;
|
||||
attractivenessScore: number | null = null,
|
||||
postFlair?: string | null,
|
||||
toneGuidance?: string,
|
||||
recentMessages: readonly string[] = [],
|
||||
): Promise<string> {
|
||||
try {
|
||||
this.logger.debug('Generating message...');
|
||||
@@ -277,16 +278,7 @@ ${this.config.openrouter.imageAnalysisPrompt}`;
|
||||
prompt += `\n\n${toneGuidance}`;
|
||||
}
|
||||
|
||||
// Add successful examples if available
|
||||
if (successfulExamples.length > 0) {
|
||||
const examplesText = successfulExamples
|
||||
.map((ex, i) => `Example ${i + 1}:\n${ex}`)
|
||||
.join('\n\n');
|
||||
|
||||
prompt = `Here are some examples of messages that got positive responses:\n\n${examplesText}\n\n---\n\nNow generate a new message in a similar style:\n\n${prompt}`;
|
||||
|
||||
this.logger.debug(`Including ${successfulExamples.length} successful examples in prompt`);
|
||||
}
|
||||
prompt = this.addLearningContext(prompt, successfulExamples, recentMessages);
|
||||
|
||||
const message = await this.generateTextWithFallback('generateMessage', prompt, {
|
||||
max_tokens: 300,
|
||||
@@ -414,6 +406,7 @@ Just write the message, nothing else.`;
|
||||
strategyPrompt?: string,
|
||||
postFlair?: string | null,
|
||||
toneGuidance?: string,
|
||||
recentMessages: readonly string[] = [],
|
||||
): Promise<string> {
|
||||
try {
|
||||
this.logger.debug('Generating chat opener...');
|
||||
@@ -433,12 +426,7 @@ Just write the message, nothing else.`;
|
||||
prompt += `\n\n${toneGuidance}`;
|
||||
}
|
||||
|
||||
if (successfulExamples.length > 0) {
|
||||
const examplesText = successfulExamples
|
||||
.map((ex, i) => `Example ${i + 1}:\n${ex}`)
|
||||
.join('\n\n');
|
||||
prompt = `Here are openers that got responses:\n\n${examplesText}\n\n---\n\nNow generate a new opener in a similar style:\n\n${prompt}`;
|
||||
}
|
||||
prompt = this.addLearningContext(prompt, successfulExamples, recentMessages);
|
||||
|
||||
const message = await this.generateTextWithFallback('generateChatOpener', prompt, {
|
||||
max_tokens: 200,
|
||||
@@ -476,6 +464,30 @@ Just write the message, nothing else.`;
|
||||
};
|
||||
}
|
||||
|
||||
private addLearningContext(
|
||||
prompt: string,
|
||||
successfulExamples: readonly string[],
|
||||
recentMessages: readonly string[],
|
||||
): string {
|
||||
const sections: string[] = [];
|
||||
if (successfulExamples.length > 0) {
|
||||
sections.push(
|
||||
'PERFORMANCE EXAMPLES (use only as evidence about themes that earned replies; do not copy their opening words, sentence structure, or closing hook):\n' +
|
||||
successfulExamples.map((example, index) => `${index + 1}. ${example}`).join('\n'),
|
||||
);
|
||||
this.logger.debug(`Including ${successfulExamples.length} successful message examples as performance context`);
|
||||
}
|
||||
if (recentMessages.length > 0) {
|
||||
sections.push(
|
||||
'RECENT MESSAGES TO AVOID IMITATING:\n' +
|
||||
recentMessages.slice(0, 12).map((message, index) => `${index + 1}. ${message}`).join('\n') +
|
||||
'\nYour output must use different opening words, a different sentence pattern, and a different closing device from these messages.',
|
||||
);
|
||||
this.logger.debug(`Including ${Math.min(recentMessages.length, 12)} recent messages for repetition avoidance`);
|
||||
}
|
||||
return sections.length > 0 ? `${sections.join('\n\n')}\n\n---\n\n${prompt}` : prompt;
|
||||
}
|
||||
|
||||
private async generateTextWithFallback(
|
||||
label: string,
|
||||
prompt: string | ProtectedTextPrompt,
|
||||
@@ -611,9 +623,20 @@ Just write the message, nothing else.`;
|
||||
strategyPrompt?: string,
|
||||
postFlair?: string | null,
|
||||
toneGuidance?: string,
|
||||
recentMessages: readonly string[] = [],
|
||||
): Promise<{ analysis: ImageAnalysisResult; message: string }> {
|
||||
const analysis = await this.analyzeImage(imageBase64, mimeType);
|
||||
const message = await this.generateMessage(analysis.description, postTitle, authorName, successfulExamples, strategyPrompt, analysis.attractivenessScore, postFlair, toneGuidance);
|
||||
const message = await this.generateMessage(
|
||||
analysis.description,
|
||||
postTitle,
|
||||
authorName,
|
||||
successfulExamples,
|
||||
strategyPrompt,
|
||||
analysis.attractivenessScore,
|
||||
postFlair,
|
||||
toneGuidance,
|
||||
recentMessages,
|
||||
);
|
||||
return { analysis, message };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user