Skip to content

Commit

Permalink
Merge pull request #1455 from peersky/patch-2
Browse files Browse the repository at this point in the history
feat: Add ModelConfiguration to Character to enable adjusting temperature, response length & penalties
  • Loading branch information
shakkernerd authored Dec 26, 2024
2 parents 99f4eca + c19ee96 commit 8fb2734
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ export async function generateText({

elizaLogger.info("Selected model:", model);

const temperature = models[provider].settings.temperature;
const frequency_penalty = models[provider].settings.frequency_penalty;
const presence_penalty = models[provider].settings.presence_penalty;
const max_context_length = models[provider].settings.maxInputTokens;
const max_response_length = models[provider].settings.maxOutputTokens;
const modelConfiguration = runtime.character?.settings?.modelConfig;
const temperature =
modelConfiguration?.temperature ||
models[provider].settings.temperature;
const frequency_penalty =
modelConfiguration?.frequency_penalty ||
models[provider].settings.frequency_penalty;
const presence_penalty =
modelConfiguration?.presence_penalty ||
models[provider].settings.presence_penalty;
const max_context_length =
modelConfiguration?.maxInputTokens ||
models[provider].settings.maxInputTokens;
const max_response_length =
modelConfiguration.max_response_length ||
models[provider].settings.maxOutputTokens;

const apiKey = runtime.token;

Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ export interface IAgentConfig {
[key: string]: string;
}

export interface ModelConfiguration {
temperature?: number;
max_response_length?: number;
frequency_penalty?: number;
presence_penalty?: number;
maxInputTokens?: number;
}

/**
* Configuration for an agent character
*/
Expand Down Expand Up @@ -738,6 +746,7 @@ export type Character = {
};
};
model?: string;
modelConfig?: ModelConfiguration;
embeddingModel?: string;
chains?: {
evm?: any[];
Expand Down

0 comments on commit 8fb2734

Please sign in to comment.