Skip to content

Commit

Permalink
Merge pull request elizaOS#515 from ai16z/fix/trim
Browse files Browse the repository at this point in the history
fix: lint
  • Loading branch information
ponderingdemocritus authored Nov 22, 2024
2 parents 02b5145 + 8d32603 commit e31e666
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
22 changes: 12 additions & 10 deletions docs/docs/guides/template-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Here are all the template options you can configure:
```json
{
"templates": {
"goalsTemplate": "", // Define character goals
"factsTemplate": "", // Specify character knowledge
"messageHandlerTemplate": "", // Handle general messages
"shouldRespondTemplate": "", // Control response triggers
"goalsTemplate": "", // Define character goals
"factsTemplate": "", // Specify character knowledge
"messageHandlerTemplate": "", // Handle general messages
"shouldRespondTemplate": "", // Control response triggers
"continueMessageHandlerTemplate": "", // Manage conversation flow
"evaluationTemplate": "", // Handle response evaluation
"twitterSearchTemplate": "", // Process Twitter searches
"twitterPostTemplate": "", // Format Twitter posts
"evaluationTemplate": "", // Handle response evaluation
"twitterSearchTemplate": "", // Process Twitter searches
"twitterPostTemplate": "", // Format Twitter posts
"twitterMessageHandlerTemplate": "", // Handle Twitter messages
"twitterShouldRespondTemplate": "", // Control Twitter responses
"telegramMessageHandlerTemplate": "", // Handle Telegram messages
Expand Down Expand Up @@ -60,11 +60,11 @@ Configure platform-specific behaviors for your character, such as handling direc
"clientConfig": {
"telegram": {
"shouldIgnoreDirectMessages": true, // Ignore DMs
"shouldIgnoreBotMessages": true // Ignore bot messages
"shouldIgnoreBotMessages": true // Ignore bot messages
},
"discord": {
"shouldIgnoreBotMessages": true, // Ignore bot messages
"shouldIgnoreDirectMessages": true // Ignore DMs
"shouldIgnoreBotMessages": true, // Ignore bot messages
"shouldIgnoreDirectMessages": true // Ignore DMs
}
}
}
Expand All @@ -73,11 +73,13 @@ Configure platform-specific behaviors for your character, such as handling direc
## Best Practices

1. **Template Management**

- Keep templates focused and specific
- Use clear, consistent formatting
- Document custom template behavior

2. **Client Configuration**

- Configure per platform as needed
- Test behavior in development
- Monitor interaction patterns
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getRemoteEmbedding(
: {}),
},
body: JSON.stringify({
input: trimTokens(input, 8191, "gpt-4o-mini"),
input: trimTokens(input, 8000, "gpt-4o-mini"),
model: options.model,
length: options.length || 384,
}),
Expand Down Expand Up @@ -160,9 +160,11 @@ async function getLocalEmbedding(input: string): Promise<number[]> {
return await import("fastembed");
} catch (error) {
elizaLogger.error("Failed to load fastembed.");
throw new Error("fastembed import failed, falling back to remote embedding");
throw new Error(
"fastembed import failed, falling back to remote embedding"
);
}
})()
})(),
]);

const [fs, { fileURLToPath }, fastEmbed] = moduleImports;
Expand Down Expand Up @@ -190,11 +192,13 @@ async function getLocalEmbedding(input: string): Promise<number[]> {
cacheDir: cacheDir,
});

const trimmedInput = trimTokens(input, 8191, "gpt-4o-mini");
const trimmedInput = trimTokens(input, 8000, "gpt-4o-mini");
const embedding = await embeddingModel.queryEmbed(trimmedInput);
return embedding;
} catch (error) {
elizaLogger.warn("Local embedding not supported in browser, falling back to remote embedding.");
elizaLogger.warn(
"Local embedding not supported in browser, falling back to remote embedding."
);
throw new Error("Local embedding not supported in browser");
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ export function trimTokens(
encoding.free();
}
}

/**
* Sends a message to the model to determine if it should respond to the given context.
* @param opts - The options for the generateText request
Expand Down

0 comments on commit e31e666

Please sign in to comment.