Skip to content

Commit

Permalink
adding deepseek
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jan 6, 2025
1 parent 5c4b99f commit 4c72258
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Usage: genaiscript run [options] <script> [files...]
Runs a GenAIScript against files.
Options:
-p, --provider <string> Preferred LLM provider aliases (choices: "openai", "azure", "azure_serverless", "azure_serverless_models", "anthropic", "anthropic_bedrock", "google", "huggingface", "mistral", "alibaba", "github", "transformers", "ollama", "lmstudio", "jan", "llamafile", "litellm")
-p, --provider <string> Preferred LLM provider aliases (choices: "openai", "azure", "azure_serverless", "azure_serverless_models", "anthropic", "anthropic_bedrock", "google", "huggingface", "mistral", "alibaba", "github", "deepseek", "transformers", "ollama", "lmstudio", "jan", "llamafile", "litellm")
-m, --model <string> 'large' model alias (default)
-sm, --small-model <string> 'small' alias model
-vm, --vision-model <string> 'vision' alias model
Expand Down Expand Up @@ -92,8 +92,8 @@ Options:
"azure_serverless_models", "anthropic",
"anthropic_bedrock", "google",
"huggingface", "mistral", "alibaba",
"github", "transformers", "ollama",
"lmstudio", "jan", "llamafile",
"github", "deepseek", "transformers",
"ollama", "lmstudio", "jan", "llamafile",
"litellm")
-m, --model <string> 'large' model alias (default)
-sm, --small-model <string> 'small' alias model
Expand Down
20 changes: 19 additions & 1 deletion packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
MODEL_PROVIDER_JAN,
JAN_API_BASE,
MODEL_PROVIDER_ANTHROPIC_BEDROCK,
MODEL_PROVIDER_DEEPSEEK,
DEEPSEEK_API_BASE,
} from "./constants"
import { host, runtimeHost } from "./host"
import { parseModelIdentifier } from "./models"
Expand Down Expand Up @@ -412,6 +414,22 @@ export async function parseTokenFromEnv(
} satisfies LanguageModelConfiguration
}

if (provider === MODEL_PROVIDER_DEEPSEEK) {
const base =
findEnvVar(env, "DEEPSEEK", BASE_SUFFIX)?.value || DEEPSEEK_API_BASE
if (!URL.canParse(base)) throw new Error(`${base} must be a valid URL`)
const token = env.DEEPSEEK_API_KEY
if (!token) throw new Error("DEEPSEEK_API_KEY not configured")
return {
provider,
model,
base,
token,
type: "openai",
source: "env: DEEPSEEK_API_...",
}
}

const prefixes = [
tag ? `${provider}_${model}_${tag}` : undefined,
provider ? `${provider}_${model}` : undefined,
Expand Down Expand Up @@ -493,7 +511,7 @@ export async function parseTokenFromEnv(
provider,
model,
base,
token: "lmstudio",
token: "jan",
type: "openai",
source: "env: JAN_API_...",
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const GOOGLE_API_BASE =
export const ALIBABA_BASE =
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
export const MISTRAL_API_BASE = "https://api.mistral.ai/v1"
export const DEEPSEEK_API_BASE = "https://api.deepseek.com/v1"

export const PROMPTFOO_CACHE_PATH = ".genaiscript/cache/tests"
export const PROMPTFOO_CONFIG_DIR = ".genaiscript/config/tests"
Expand Down Expand Up @@ -156,6 +157,7 @@ export const MODEL_PROVIDER_ALIBABA = "alibaba"
export const MODEL_PROVIDER_MISTRAL = "mistral"
export const MODEL_PROVIDER_LMSTUDIO = "lmstudio"
export const MODEL_PROVIDER_JAN = "jan"
export const MODEL_PROVIDER_DEEPSEEK = "deepseek"

export const TRACE_FILE_PREVIEW_MAX_LENGTH = 240

Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/llms.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@
"reasoning_small": "o1-mini"
}
},
{
"id": "deepseek",
"detail": "DeepSeek Models",
"base": "https://api.deepseek.com/v1",
"bearerToken": true,
"aliases": {
"large": "deepseek-chat",
"small": "deepseek-chat",
"vision": "deepseek-chat"
}
},
{
"id": "transformers",
"detail": "Hugging Face Transformers",
Expand Down Expand Up @@ -632,6 +643,11 @@
"price_per_million_input_tokens": 0.8,
"price_per_million_output_tokens": 4,
"input_cache_token_rebate": 0.1
},
"deepseek:deepseek-chat": {
"price_per_million_input_tokens": 0.14,
"price_per_million_output_tokens": 0.28,
"input_cache_token_rebate": 0.1
}
}
}
1 change: 0 additions & 1 deletion packages/core/src/lm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MODEL_PROVIDER_ANTHROPIC,
MODEL_PROVIDER_ANTHROPIC_BEDROCK,
MODEL_PROVIDER_CLIENT,
MODEL_PROVIDER_JAN,
MODEL_PROVIDER_OLLAMA,
MODEL_PROVIDER_TRANSFORMERS,
MODEL_PROVIDERS,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ type ModelType = OptionsOrString<
| "alibaba:qwen-plus"
| "alibaba:qwen2-72b-instruct"
| "alibaba:qwen2-57b-a14b-instruct"
| "deepseek:deepseek-chat"
| "transformers:onnx-community/Qwen2.5-0.5B-Instruct:q4"
| "transformers:HuggingFaceTB/SmolLM2-1.7B-Instruct:q4f16"
>
Expand Down

0 comments on commit 4c72258

Please sign in to comment.