dsc

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dsc provides deepseek client

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxTokens = config.GetInt("max-tokens", 8192*48) // 384K

DefaultMaxTokens 默认 max_tokens,可通过 config max-tokens 覆盖

View Source
var V4Enabled = config.GetBool("deepseek-v4", true)

V4Enabled deepseek-v4 专有参数开关,默认开启。

Functions

This section is empty.

Types

type BalanceResponse

type BalanceResponse struct {
	IsAvailable  bool                `json:"is_available"`
	BalanceInfos []map[string]string `json:"balance_infos"`
}

type ChatRequest

type ChatRequest struct {
	Model           string           `json:"model"`
	Messages        []prompt.Message `json:"messages"`
	Tools           []toolcall.Tool  `json:"tools,omitzero"`
	Stream          bool             `json:"stream"`
	MaxTokens       int              `json:"max_tokens,omitzero"`
	Thinking        Thinking         `json:"thinking"`
	ReasoningEffort string           `json:"reasoning_effort,omitzero"`
}

ChatRequest 扩展,支持 tools

type ChatResponse

type ChatResponse struct {
	ID      string   `json:"id"`
	Choices []Choice `json:"choices"`
}

ChatResponse 响应

type Choice

type Choice struct {
	Message      prompt.Message `json:"message"`
	FinishReason string         `json:"finish_reason"`
}

type Client

type Client interface {
	Models() (*ModelsResponse, error)
	Balance() (*BalanceResponse, error)
	FIM(ctx context.Context, req FIMRequest) (*FIMResponse, error)
	Chat(ctx context.Context, messages []prompt.Message, tools []toolcall.Tool) (*ChatResponse, error)
}

func NewClient

func NewClient(apiKey, baseURL string) Client

type Deepseek

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

func (*Deepseek) Balance

func (c *Deepseek) Balance() (*BalanceResponse, error)

Balance 获取余额信息

func (*Deepseek) Chat

func (c *Deepseek) Chat(ctx context.Context, messages []prompt.Message, tools []toolcall.Tool) (*ChatResponse, error)

Chat 发送聊天请求

func (*Deepseek) FIM

func (c *Deepseek) FIM(ctx context.Context, req FIMRequest) (*FIMResponse, error)

FIM 实现填充中间代码(Fill-In-the-Middle)功能。

通过 context.StreamKey 控制流式/非流式:

  • false(默认):一次性返回完整补全结果
  • true:通过 SSE 流式输出,实时打印补全内容

参考 API 文档: https://api.deepseek.com/beta/completions

func (*Deepseek) Models

func (c *Deepseek) Models() (*ModelsResponse, error)

Models 获取模型列表

type FIMChoice

type FIMChoice struct {
	Text         string `json:"text"`
	Index        int    `json:"index"`
	FinishReason string `json:"finish_reason,omitzero"`
}

type FIMRequest

type FIMRequest struct {
	Model       string  `json:"model"`
	Prompt      string  `json:"prompt"`
	Suffix      string  `json:"suffix,omitzero"`
	MaxTokens   int     `json:"max_tokens,omitzero"`
	Temperature float64 `json:"temperature,omitzero"`
	TopP        float64 `json:"top_p,omitzero"`
	Stream      bool    `json:"stream,omitzero"`
	Echo        bool    `json:"echo,omitzero"`
	Stop        any     `json:"stop,omitzero"`
}

FIMRequest FIM (Fill-In-the-Middle) completion request. For streaming, set Stream=true or use context.StreamKey.

type FIMResponse

type FIMResponse struct {
	ID      string      `json:"id"`
	Choices []FIMChoice `json:"choices"`
	Usage   FIMUsage    `json:"usage,omitzero"`
}

FIMResponse non-streaming FIM response.

type FIMStreamChunk added in v0.7.9

type FIMStreamChunk struct {
	ID      string      `json:"id"`
	Object  string      `json:"object"`
	Created int64       `json:"created"`
	Model   string      `json:"model"`
	Choices []FIMChoice `json:"choices"`
	Usage   *FIMUsage   `json:"usage,omitzero"`
}

FIMStreamChunk SSE streaming response chunk for FIM.

type FIMUsage added in v0.7.9

type FIMUsage struct {
	CompletionTokens int `json:"completion_tokens"`
	PromptTokens     int `json:"prompt_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type Model

type Model struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	OwnedBy string `json:"owned_by"`
}

type ModelsResponse

type ModelsResponse struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

type Thinking added in v0.7.4

type Thinking struct {
	Type string `json:"type,omitzero"`
}

Source Files

  • client.go
  • dsc.go
  • dsc_chat.go
  • dsc_chat_stream.go
  • dsc_fim.go

Jump to

Keyboard shortcuts

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