deepseek

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

DeepSeek Plugin

This plugin provides Genkit support for DeepSeek's OpenAI-compatible models, DeepSeek V4 Flash and DeepSeek V4 Pro.

Setup

Set a DeepSeek API key:

export DEEPSEEK_API_KEY=<your-api-key>

The plugin uses https://api.deepseek.com by default. Set DEEPSEEK_BASE_URL, or pass option.WithBaseURL through the plugin's Opts, to use another compatible endpoint, such as DeepSeek's beta endpoint.

import (
    "context"

    "github.com/firebase/genkit/go/ai"
    "github.com/firebase/genkit/go/genkit"
    "github.com/firebase/genkit/go/plugins/compat_oai/deepseek"
)

ctx := context.Background()
plugin := &deepseek.DeepSeek{}
g := genkit.Init(ctx,
    genkit.WithPlugins(plugin),
    genkit.WithDefaultModel("deepseek/deepseek-v4-flash"),
)

response, err := genkit.Generate(ctx, g, ai.WithPrompt("Explain mixture-of-experts models."))

DeepSeek's reasoning_content output is returned as Genkit reasoning parts and is available through response.Reasoning().

Models

deepseek-v4-flash and deepseek-v4-pro are registered. The catalog is not a ceiling: any model ID DeepSeek serves resolves on demand, and the Models field describes or corrects any model, curated or not. The current model list and pricing, including the dated snapshots a config version can pin, are at https://api-docs.deepseek.com/quick_start/pricing, and the API reference is at https://api-docs.deepseek.com.

Config

Models take a typed deepseek.ChatConfig: the generation fields DeepSeek accepts plus its thinking controls, thinking for the mode and reasoningEffort (low, high, or max) for the depth. deepseek.ModelRef carries the config with the model ID. Thinking is on by default, so turning it off is the common case:

response, err := genkit.Generate(ctx, g,
    ai.WithModel(deepseek.ModelRef("deepseek-v4-flash", &deepseek.ChatConfig{
        Thinking: &deepseek.ThinkingConfig{Type: deepseek.ThinkingTypeDisabled},
    })),
    ai.WithPrompt("Answer concisely."),
)

maxOutputTokens reaches DeepSeek as the max_tokens it reads. DeepSeek no longer supports the frequency and presence penalties, so the config does not offer them.

Every config also carries the settings Genkit owns: version pins the exact model version a request is served by, apiKey (settable only from Go code) serves one request with a different credential, and extra forwards request body fields the config does not declare, keyed by DeepSeek's wire names (for example logprobs).

Prompt caching

DeepSeek caches prompt prefixes automatically and bills a cache hit at a lower rate; the hits come back as response.Usage.CachedContentTokens. Set userId to partition that cache per end user, so users neither read nor evict each other's cached prefixes:

response, err := genkit.Generate(ctx, g,
    ai.WithModel(deepseek.ModelRef("deepseek-v4-flash", &deepseek.ChatConfig{
        UserID: "tenant-42",
    })),
    ai.WithPrompt("Answer concisely."),
)

Not supported

The V4 models are text-only, so image inputs are not advertised. DeepSeek's beta features (chat prefix completion and FIM) are not exposed by this plugin.

Live tests

Live tests are skipped unless DEEPSEEK_API_KEY is set:

go test -race ./plugins/compat_oai/deepseek -run '^TestPluginLive$' -v -count=1

Documentation

Overview

Package deepseek provides a Genkit plugin for DeepSeek's models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModelRef

func ModelRef(id string, config *ChatConfig) ai.ModelRef

ModelRef names a DeepSeek model and carries the config to generate with, so the config is typed at the call site instead of an any the model checks at runtime. A nil config leaves the request's config unset.

ai.WithModel(deepseek.ModelRef("deepseek-v4-pro", &deepseek.ChatConfig{
	Thinking: &deepseek.ThinkingConfig{Type: "disabled"},
}))

id is the model ID, with or without the provider prefix.

Types

type ChatConfig

type ChatConfig struct {
	compat_oai.RequestConfig

	// Temperature controls the degree of randomness in token selection, from
	// 0 to 2; DeepSeek's default is 1.
	Temperature *float64 `` /* 178-byte string literal not displayed */
	// TopP is the nucleus sampling threshold, up to 1.
	TopP *float64 `json:"topP,omitempty" jsonschema:"maximum=1" jsonschema_description:"Nucleus sampling threshold, up to 1."`
	// MaxOutputTokens is the maximum number of tokens to generate, sent as the
	// API's max_tokens.
	MaxOutputTokens int `` /* 148-byte string literal not displayed */
	// StopSequences stop generation when produced by the model, up to sixteen.
	StopSequences []string `` /* 149-byte string literal not displayed */
	// LogProbs requests log probabilities for the output tokens.
	LogProbs *bool `json:"logProbs,omitempty" jsonschema_description:"Requests log probabilities for the output tokens."`
	// TopLogProbs is how many of the most likely tokens to return log
	// probabilities for at each position, from 0 to 20; it requires LogProbs.
	TopLogProbs *int `` /* 205-byte string literal not displayed */
	// UserID identifies the end user a request is made on behalf of, up to 512
	// characters of [a-zA-Z0-9_-]. DeepSeek partitions its context cache by
	// this ID, so end users neither read nor evict each other's cached
	// prefixes; sent as the API's user_id, not OpenAI's user.
	UserID string `` /* 297-byte string literal not displayed */
	// ReasoningEffort adjusts how hard the model thinks, [ReasoningEffortLow]
	// to [ReasoningEffortMax]; DeepSeek's default is high. Sent as the API's
	// top-level reasoning_effort: the create-chat-completion reference also
	// documents it nested inside thinking, but the service silently ignores it
	// there and reads only the top-level field the thinking-mode guide's
	// examples use.
	ReasoningEffort ReasoningEffort `` /* 172-byte string literal not displayed */
	// Thinking controls the thinking mode of DeepSeek models, which is on by
	// default; sent as the API's thinking field.
	Thinking *ThinkingConfig `json:"thinking,omitempty" jsonschema_description:"Thinking mode controls, on by default; sent as the API's thinking field."`
}

ChatConfig is the per-request config for DeepSeek models: the generation fields DeepSeek accepts plus its thinking controls. See https://api-docs.deepseek.com/api/create-chat-completion.

DeepSeek no longer supports the frequency and presence penalties, so those are deliberately absent.

func (ChatConfig) ApplyToChatCompletion

func (c ChatConfig) ApplyToChatCompletion(params *openai.ChatCompletionNewParams)

ApplyToChatCompletion implements compat_oai.ChatConfig: the generation fields land on their chat completion counterparts, MaxOutputTokens on the max_tokens DeepSeek reads, ReasoningEffort on the SDK's reasoning_effort, and the fields DeepSeek names differently than OpenAI, thinking and user_id, ride as extra request fields.

type DeepSeek

type DeepSeek struct {
	// APIKey is the DeepSeek API key. If empty, DEEPSEEK_API_KEY is consulted.
	APIKey string
	// Opts contains additional OpenAI client request options, such as
	// [option.WithBaseURL] for a different endpoint, e.g. DeepSeek's beta one
	// (DEEPSEEK_BASE_URL works too). Options supplied here are applied after
	// the plugin defaults, so they win on overlap.
	Opts []option.RequestOption

	// Models overrides what the plugin knows about a DeepSeek model, keyed by
	// model ID, bare or provider-prefixed. Every DeepSeek model already works
	// without an entry: known IDs carry curated capabilities and the rest take
	// the DeepSeek defaults. Supply an entry only to correct or extend what the
	// plugin resolves, most often for a model released after this version of
	// the plugin.
	//
	//	&deepseek.DeepSeek{Models: map[string]ai.ModelOptions{
	//		"deepseek-v4-pro": {Supports: &ai.ModelSupports{Multiturn: true, Tools: true}},
	//	}}
	//
	// Fields left at their zero value keep what the plugin resolves, so an
	// entry can pin one capability without restating the label or the
	// versions. Entries apply to the models Init registers as well as the
	// ones [DeepSeek.ListActions] advertises and [DeepSeek.ResolveAction] builds,
	// which is the way to describe a curated model differently: Init has
	// already registered those and nothing can re-register them.
	Models map[string]ai.ModelOptions
	// contains filtered or unexported fields
}

DeepSeek configures the DeepSeek plugin.

func (*DeepSeek) Init

func (d *DeepSeek) Init(ctx context.Context) []api.Action

Init implements genkit.Plugin.

func (*DeepSeek) ListActions

func (d *DeepSeek) ListActions(ctx context.Context) []api.ActionDesc

ListActions lists the models the configured DeepSeek endpoint exposes, described by the plugin's config schema and capabilities.

func (*DeepSeek) Name

func (d *DeepSeek) Name() string

Name implements genkit.Plugin.

func (*DeepSeek) ResolveAction

func (d *DeepSeek) ResolveAction(atype api.ActionType, id string) api.Action

ResolveAction dynamically builds a model exposed by the DeepSeek endpoint, described by the plugin's config schema and capabilities.

type ReasoningEffort

type ReasoningEffort string

ReasoningEffort is how hard a DeepSeek model thinks before it answers.

const (
	// ReasoningEffortLow is the fastest, shallowest reasoning.
	ReasoningEffortLow ReasoningEffort = "low"
	// ReasoningEffortHigh is deeper reasoning.
	ReasoningEffortHigh ReasoningEffort = "high"
	// ReasoningEffortMax is the deepest reasoning.
	ReasoningEffortMax ReasoningEffort = "max"
)

type ThinkingConfig

type ThinkingConfig struct {
	// Type turns thinking [ThinkingTypeEnabled] or [ThinkingTypeDisabled].
	Type ThinkingType `json:"type,omitempty" jsonschema:"enum=enabled,enum=disabled" jsonschema_description:"Turns thinking enabled or disabled."`
}

ThinkingConfig configures the thinking mode of DeepSeek models.

type ThinkingType

type ThinkingType string

ThinkingType turns the thinking mode of DeepSeek models on or off.

const (
	// ThinkingTypeEnabled turns thinking on, which is DeepSeek's default.
	ThinkingTypeEnabled ThinkingType = "enabled"
	// ThinkingTypeDisabled turns thinking off.
	ThinkingTypeDisabled ThinkingType = "disabled"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL