deepseek

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package deepseek implements a flyto.ModelProvider for DeepSeek's official API.

DeepSeek 官方 API 实现, ADR-0007 § 2.1 第 5 个 direct provider.

DeepSeek offers two API formats:

  1. OpenAI compat - https://api.deepseek.com (default, primary)
  2. Anthropic compat - https://api.deepseek.com/anthropic

Default ModeOpenAI rationale:

  • The reasoning_content passback contract (r24 root cause) is wired in the OpenAI-compat wire layer (ADR-0007 C4 commit 17f7ba4); routing production traffic through ModeOpenAI directly consumes that fix.
  • Anthropic-compat ignores budget_tokens / cache_control / top_k / image / mcp_servers (per /guides/anthropic_api).
  • Anthropic-compat silently falls back unknown model ids to v4-flash (per /guides/anthropic_api), masking probe / config bugs.

默认 ModeOpenAI 原因:

  • reasoning_content passback 协议 (r24 真因) 在 OpenAI compat wire 层 (ADR-0007 C4 commit 17f7ba4) 已修, 走 OpenAI compat 直接接通已修的 wire 层.
  • Anthropic compat 限制更多: budget_tokens / cache_control / top_k / image / mcp_servers 全部 ignore (官方文档 /guides/anthropic_api).
  • Anthropic compat 有静默 model fallback 坑: 送错 ID 不 4xx 自动落到 v4-flash, 掩盖 probe / 配置错误.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIKey is the DeepSeek API key (from platform.deepseek.com).
	//
	// APIKey 是 DeepSeek API 密钥 (从 platform.deepseek.com 获取).
	APIKey string

	// BaseURL overrides the default endpoint. Empty uses
	// https://api.deepseek.com (the API path suffix is appended per Mode).
	//
	// BaseURL 覆盖默认端点. 空字符串使用 https://api.deepseek.com (Mode 决定追加路径后缀).
	BaseURL string

	// Mode selects OpenAI vs Anthropic compat (default ModeOpenAI).
	//
	// Mode 选择 OpenAI vs Anthropic 兼容 (默认 ModeOpenAI).
	Mode Mode

	// ThinkingBudget enables thinking mode and sets the max reasoning tokens.
	// 0 = disabled.
	//
	// ModeAnthropic ignores this value per DeepSeek docs but the field is
	// still accepted for symmetry with other providers.
	//
	// ThinkingBudget 启用思考模式并设置 reasoning token 上限. 0 = 禁用.
	// ModeAnthropic 据 DeepSeek 文档 ignore 此值, 但仍接受参数保持与其他
	// provider 接口对称.
	ThinkingBudget int

	// HTTPClient injects a custom HTTP client. nil uses the default
	// http.Client with ResponseHeaderTimeout set from Timeout below.
	// When non-nil the consumer fully owns timeout policy and Timeout is
	// ignored (do not set http.Client.Timeout - it kills SSE streams).
	//
	// HTTPClient 注入自定义 HTTP 客户端. nil 使用默认 http.Client (带 Timeout
	// 字段配置的 ResponseHeaderTimeout). 非 nil 时 consumer 完全接管超时
	// 责任, Timeout 字段被忽略 (不要设 http.Client.Timeout - 会砍死 SSE 流).
	HTTPClient *http.Client

	// Timeout limits the time from request send to first response byte.
	// 0 = use defaultTimeout (60s). Implemented via
	// http.Transport.ResponseHeaderTimeout, does NOT affect SSE body reads
	// (DeepSeek long thinking can still complete).
	//
	// Timeout 限制 "从请求发出到收到响应首字节" 的时间. 0 = 使用 defaultTimeout
	// (60s). 通过 http.Transport.ResponseHeaderTimeout 实现, 不影响 SSE 流式
	// 响应的后续 body 读取 (DeepSeek 长思考模式可以正常读完).
	Timeout time.Duration

	// ModelOverrides replaces the static model table returned by Models().
	// Useful for tests / preview models not in the default table.
	//
	// ModelOverrides 覆盖 Models() 返回的静态模型表, 用于测试 / 预览模型注入.
	ModelOverrides []flyto.ModelInfo
}

Config configures the DeepSeek provider.

Config 是 DeepSeek provider 的配置.

func (Config) GoString

func (c Config) GoString() string

GoString masks the API key in printf("%#v") output.

GoString 在 printf("%#v") 输出中遮蔽 API key.

type Mode

type Mode string

Mode selects the API format used to talk to DeepSeek.

Mode 选择对接 DeepSeek 的 API 格式.

const (
	// ModeOpenAI uses the OpenAI-compatible endpoint at /v1/chat/completions
	// with Authorization: Bearer auth. This is the default and primary path.
	//
	// ModeOpenAI 走 OpenAI 兼容端点 /v1/chat/completions, Bearer 鉴权.
	// 默认主路径.
	ModeOpenAI Mode = "openai"

	// ModeAnthropic uses the Anthropic-compatible endpoint at
	// /anthropic/v1/messages with x-api-key auth. anthropic-version /
	// anthropic-beta headers are ignored by DeepSeek.
	//
	// ModeAnthropic 走 Anthropic 兼容端点 /anthropic/v1/messages, x-api-key
	// 鉴权. anthropic-version / anthropic-beta header 被 DeepSeek 忽略.
	ModeAnthropic Mode = "anthropic"
)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is the DeepSeek API client (one of wireClient or anthroClient is non-nil based on Mode).

Provider 是 DeepSeek API 客户端 (按 Mode 二选一持有 wireClient 或 anthroClient).

func New

func New(cfg Config) *Provider

New constructs a DeepSeek provider.

New 构造 DeepSeek provider.

func (*Provider) Models

func (p *Provider) Models(_ context.Context) ([]flyto.ModelInfo, error)

Models returns the static DeepSeek model table.

Models 返回 DeepSeek 模型静态表.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider identifier.

Name 返回 provider 标识.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *flyto.Request) (<-chan flyto.Event, error)

Stream issues a streaming request to DeepSeek.

DeepSeek does not support image / document / video input on either V4 model (per official docs); image blocks are rejected up front with a typed error from shared.CheckNoImageBlocks rather than being forwarded for the server to reject.

Stream 向 DeepSeek 发起流式请求.

DeepSeek 两个 V4 模型均不支持图像 / 文档 / 视频输入 (官方文档), image block 在 shared.CheckNoImageBlocks 提前用 typed error 拒绝, 不下发给服务端避免无意义的 4xx.

Jump to

Keyboard shortcuts

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