From 70dad2f4b4064aac0a4e67f1976802774c20ce39 Mon Sep 17 00:00:00 2001 From: fabri Date: Sat, 28 Dec 2024 12:41:12 -0300 Subject: [PATCH] discord fix --- packages/client-discord/package.json | 2 +- .../src/actions/chat_with_attachments.ts | 5 ++- packages/client-discord/src/templates.ts | 34 +++++++++---------- packages/client-discord/src/voice.ts | 3 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/client-discord/package.json b/packages/client-discord/package.json index be4ace088f..f7e08d93e5 100644 --- a/packages/client-discord/package.json +++ b/packages/client-discord/package.json @@ -1,6 +1,6 @@ { "name": "@elizaos/client-discord", - "version": "0.1.7-alpha.1", + "version": "0.1.7-alpha.2", "main": "dist/index.js", "type": "module", "types": "dist/index.d.ts", diff --git a/packages/client-discord/src/actions/chat_with_attachments.ts b/packages/client-discord/src/actions/chat_with_attachments.ts index 607955fb67..61163651d9 100644 --- a/packages/client-discord/src/actions/chat_with_attachments.ts +++ b/packages/client-discord/src/actions/chat_with_attachments.ts @@ -1,5 +1,6 @@ import { composeContext } from "@elizaos/core"; import { generateText, trimTokens } from "@elizaos/core"; +import type { TiktokenModel } from "js-tiktoken"; import { models } from "@elizaos/core"; import { parseJSONObjectFromText } from "@elizaos/core"; import { @@ -194,10 +195,12 @@ const summarizeAction = { const context = composeContext({ state, // make sure it fits, we can pad the tokens a bit + // Get the model's tokenizer based on the current model being used template: trimTokens( summarizationTemplate, chunkSize + 500, - "gpt-4o-mini" // TODO: make this dynamic and generic + (model.model[ModelClass.SMALL] || + "gpt-4o-mini") as TiktokenModel // Use the same model as generation; Fallback if no SMALL model configured ), }); diff --git a/packages/client-discord/src/templates.ts b/packages/client-discord/src/templates.ts index 0fea262016..46d3f2333a 100644 --- a/packages/client-discord/src/templates.ts +++ b/packages/client-discord/src/templates.ts @@ -8,48 +8,48 @@ About {{agentName}}: # INSTRUCTIONS: Determine if {{agentName}} should respond to the message and participate in the conversation. Do not comment. Just respond with "RESPOND" or "IGNORE" or "STOP". # RESPONSE EXAMPLES -: I just saw a really great movie -: Oh? Which movie? +{{user1}}: I just saw a really great movie +{{user2}}: Oh? Which movie? Result: [IGNORE] {{agentName}}: Oh, this is my favorite scene -: sick -: wait, why is it your favorite scene +{{user1}}: sick +{{user2}}: wait, why is it your favorite scene Result: [RESPOND] -: stfu bot +{{user1}}: stfu bot Result: [STOP] -: Hey {{agent}}, can you help me with something +{{user1}}: Hey {{agent}}, can you help me with something Result: [RESPOND] -: {{agentName}} stfu plz +{{user1}}: {{agentName}} stfu plz Result: [STOP] -: i need help +{{user1}}: i need help {{agentName}}: how can I help you? -: no. i need help from someone else +{{user1}}: no. i need help from someone else Result: [IGNORE] -: Hey {{agent}}, can I ask you a question +{{user1}}: Hey {{agent}}, can I ask you a question {{agentName}}: Sure, what is it -: can you ask claude to create a basic react module that demonstrates a counter +{{user1}}: can you ask claude to create a basic react module that demonstrates a counter Result: [RESPOND] -: {{agentName}} can you tell me a story -: {about a girl named elara +{{user1}}: {{agentName}} can you tell me a story +{{user1}}: about a girl named elara {{agentName}}: Sure. {{agentName}}: Once upon a time, in a quaint little village, there was a curious girl named Elara. {{agentName}}: Elara was known for her adventurous spirit and her knack for finding beauty in the mundane. -: I'm loving it, keep going +{{user1}}: I'm loving it, keep going Result: [RESPOND] -: {{agentName}} stop responding plz +{{user1}}: {{agentName}} stop responding plz Result: [STOP] -: okay, i want to test something. can you say marco? +{{user1}}: okay, i want to test something. can you say marco? {{agentName}}: marco -: great. okay, now do it again +{{user1}}: great. okay, now do it again Result: [RESPOND] Response options are [RESPOND], [IGNORE] and [STOP]. diff --git a/packages/client-discord/src/voice.ts b/packages/client-discord/src/voice.ts index 85c14c03ed..036806f610 100644 --- a/packages/client-discord/src/voice.ts +++ b/packages/client-discord/src/voice.ts @@ -8,6 +8,7 @@ import { State, UUID, composeContext, + composeRandomUser, elizaLogger, getEmbeddingZeroVector, generateMessageResponse, @@ -840,7 +841,7 @@ export class VoiceManager extends EventEmitter { this.runtime.character.templates ?.discordShouldRespondTemplate || this.runtime.character.templates?.shouldRespondTemplate || - discordShouldRespondTemplate, + composeRandomUser(discordShouldRespondTemplate, 2), }); const response = await generateShouldRespond({