client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package client 是 DeepSeek HTTP API 的最薄封装。

DeepSeek 是 OpenAI 兼容接口: Bearer token 鉴权, base url 默认 https://api.deepseek.com

Index

Constants

View Source
const DefaultBaseURL = "https://api.deepseek.com"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status int
	Body   []byte
}

APIError 表示一个非 2xx 的响应, 携带原始 body 便于 --format-error 处理。

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	APIKey  string
	BaseURL string
	Debug   bool
	HTTP    *http.Client
}

Client 持有鉴权与 base url。

func New

func New(apiKey, baseURL string, debug bool) *Client

New 构造一个 client, baseURL 为空时用默认值。

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body any) ([]byte, error)

Do 发送请求并返回完整响应 body (非 2xx 包装成 APIError)。

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, method, path string, body any, onChunk func([]byte) error) error

Stream 处理 SSE 流式响应, 对每个 `data:` 行回调一次原始 JSON (去掉 [DONE])。

Jump to

Keyboard shortcuts

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