Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add DeepSeek API to modelProviders #1636

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,10 @@ CRONOSZKEVM_PRIVATE_KEY=

# Fuel Ecosystem (FuelVM)
FUEL_WALLET_PRIVATE_KEY=

# DeepSeek Configuration
DEEPSEEK_API_KEY=
SMALL_DEEPSEEK_MODEL= # Default deepseek-chat
MEDIUM_DEEPSEEK_MODEL= # Default deepseek-chat
LARGE_DEEPSEEK_MODEL= # Default deepseek-chat

5 changes: 5 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ export function getTokenForProvider(
character.settings?.secrets?.GOOGLE_GENERATIVE_AI_API_KEY ||
settings.GOOGLE_GENERATIVE_AI_API_KEY
);
case ModelProviderName.DEEPSEEK:
return (
character.settings?.secrets?.DEEPSEEK_API_KEY ||
settings.DEEPSEEK_API_KEY
);
default:
const errorMessage = `Failed to get token - unsupported model provider: ${provider}`;
elizaLogger.error(errorMessage);
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,32 @@ export async function generateText({
break;
}

case ModelProviderName.DEEPSEEK: {
elizaLogger.debug("Initializing DeepSeek model.");
const deepseek = createOpenAI({
apiKey: apiKey,
baseURL: endpoint,
fetch: runtime.fetch,
});

const { text: deepseekResponse } = await aiGenerateText({
model: deepseek.languageModel(model),
prompt: context,
system:
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
});

response = deepseekResponse;
elizaLogger.debug("Received response from DeepSeek model.");
break;
}

default: {
const errorMessage = `Unsupported provider: ${provider}`;
elizaLogger.error(errorMessage);
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,24 @@ export const models: Models = {
[ModelClass.IMAGE]: settings.LIVEPEER_IMAGE_MODEL || "ByteDance/SDXL-Lightning",
},
},
[ModelProviderName.DEEPSEEK]: {
endpoint: "https://api.deepseek.com/v1",
settings: {
stop: [],
maxInputTokens: 128000,
maxOutputTokens: 4096,
frequency_penalty: 0.0,
presence_penalty: 0.0,
temperature: 0.7,
},
model: {
[ModelClass.SMALL]: settings.SMALL_DEEPSEEK_MODEL || "deepseek-chat",
[ModelClass.MEDIUM]: settings.MEDIUM_DEEPSEEK_MODEL || "deepseek-chat",
[ModelClass.LARGE]: settings.LARGE_DEEPSEEK_MODEL || "deepseek-chat",
[ModelClass.EMBEDDING]: settings.EMBEDDING_DEEPSEEK_MODEL || "",
[ModelClass.IMAGE]: settings.IMAGE_DEEPSEEK_MODEL || "",
},
},
};

export function getModel(provider: ModelProviderName, type: ModelClass) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export type Models = {
[ModelProviderName.VENICE]: Model;
[ModelProviderName.AKASH_CHAT_API]: Model;
[ModelProviderName.LIVEPEER]: Model;
[ModelProviderName.DEEPSEEK]: Model;
};

/**
Expand Down Expand Up @@ -243,6 +244,7 @@ export enum ModelProviderName {
VENICE = "venice",
AKASH_CHAT_API = "akash_chat_api",
LIVEPEER = "livepeer",
DEEPSEEK = "deepseek",
}

/**
Expand Down
Loading