Skip to content

Commit

Permalink
fix: ducky (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucrypto authored Feb 21, 2025
1 parent 3ba21b7 commit 9825957
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/core/managers/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,29 +360,6 @@ export class ConversationManager {
return false;
}

// Check for direct greetings
const lowerContent = messageContent.toLowerCase();
const greetings = [
"hey ducky",
"hi ducky",
"hello ducky",
"yo ducky",
"hey @duckyai_ai_bot",
"hi @duckyai_ai_bot",
"hello @duckyai_ai_bot",
"yo @duckyai_ai_bot",
];

console.log("[ResponseDecision] Checking greetings...");
for (const greeting of greetings) {
if (lowerContent.includes(greeting)) {
console.log(
`[ResponseDecision] Responding due to greeting: ${greeting}`
);
return true;
}
}

// Check if Ducky recently participated in the conversation
if (state.lastDuckyMessage) {
const timeSinceLastDuckyMessage =
Expand All @@ -399,7 +376,9 @@ export class ConversationManager {
// Only respond to important messages or questions
try {
console.log("[ResponseDecision] Analyzing message importance...");
const importance = await this.llm.analyzeImportance(messageContent);
const importance = await this.llm.analyzeImportanceTelegram(
messageContent
);
console.log(`[ResponseDecision] Message importance score: ${importance}`);
return importance > 0.7;
} catch (error) {
Expand Down
43 changes: 43 additions & 0 deletions src/core/managers/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,49 @@ Base instruction: ${systemMessage.content}
}
}

async analyzeImportanceTelegram(
content: string,
context: Record<string, any> = {}
): Promise<number> {
const prompt = `Analyze this message's importance (0.0 to 1.0):
Content: "${content}"
Consider:
1. Is the message directed at Ducky? (Direct mentions, variations like "duck", questions/commands to AI, informal addressing)
- If clearly directed at Ducky, score should be 0.9 or higher
2. Long-term significance
3. Emotional weight
4. Knowledge value
5. Relationship importance
6. Direct reference to Ducky such as hey ducky or duck, Ducky, Ducky!
Context provided:
${Object.entries(context)
.map(([key, value]) => `${key}: ${value}`)
.join("\n")}
Return only a number between 0 and 1.`;

try {
const response = await this.openai.chat.completions.create({
model: this.config.analyzer.model,
temperature: this.config.analyzer.temperature,
messages: [{ role: "user", content: prompt }],
});

const importance = parseFloat(response.choices[0].message.content ?? "0");
if (isNaN(importance) || importance < 0 || importance > 1) {
throw new Error("Invalid importance value received");
}

return importance;
} catch (error) {
console.error("Error analyzing importance:", error);
throw error;
}
}

async analyzeImportance(
content: string,
context: Record<string, any> = {}
Expand Down

0 comments on commit 9825957

Please sign in to comment.