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: deepseek model for ai api #816

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/old-cycles-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/ai": patch
---

Add Deepseek support
1 change: 1 addition & 0 deletions packages/ai/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ export enum envKeys {
OpenAiApiKey = "OPENAI_API_KEY",
GeminiApiKey = "GEMINI_API_KEY",
AnthropicApiKey = "ANTHROPIC_API_KEY",
DeepSeekApiKey = "DEEPSEEK_API_KEY",
}
72 changes: 72 additions & 0 deletions packages/ai/src/models/deepseek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { type AiAdapter } from "../adapter.js";
import { type OpenAiAiAdapter } from "../adapters/openai.js";
import { envKeys, processEnv } from "../env";

/**
* Create a DeepSeek model using the OpenAI-compatible chat format.
*
* By default it targets the `https://api.deepseek.com/v1/` base URL.
*/
export const deepseek: AiAdapter.ModelCreator<
[options: DeepSeek.AiModelOptions],
DeepSeek.AiModel
> = (options) => {
const authKey = options.apiKey || processEnv(envKeys.DeepSeekApiKey) || "";

// Ensure we add a trailing slash to our base URL if it doesn't have one,
// otherwise we'll replace the path instead of appending it.
let baseUrl = options.baseUrl || "https://api.deepseek.com/v1/";
if (!baseUrl.endsWith("/")) {
baseUrl += "/";
}

const url = new URL("chat/completions", baseUrl);

return {
url: url.href,
authKey,
format: "openai-chat",
onCall(_, body) {
body.model ||= options.model;
},
options,
} as DeepSeek.AiModel;
};

export namespace DeepSeek {
/**
* IDs of models available in the DeepSeek API.
*/
export type Model = "deepseek-chat" | "deepseek-reasoner" | (string & {});

/**
* Options for creating a DeepSeek model.
*/
export interface AiModelOptions {
/**
* ID of the model to use. Currently supports 'deepseek-chat' (DeepSeek-V3)
* and 'deepseek-reasoner' (DeepSeek-R1).
*/
model: Model;

/**
* The DeepSeek API key to use for authenticating your request. By default we'll
* search for and use the `DEEPSEEK_API_KEY` environment variable.
*/
apiKey?: string;

/**
* The base URL for the DeepSeek API.
*
* @default "https://api.deepseek.com/v1/"
*/
baseUrl?: string;
}

/**
* A DeepSeek model using the OpenAI-compatible format for I/O.
*/
export interface AiModel extends OpenAiAiAdapter {
options: AiModelOptions;
}
}
7 changes: 4 additions & 3 deletions packages/ai/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./anthropic";
export * from "./gemini";
export * from "./openai";
export * from "./anthropic.js";
export * from "./gemini.js";
export * from "./openai.js";
export * from "./deepseek.js";
Loading