Documentation
¶
Index ¶
- Constants
- Variables
- func HandleAPIError(resp *http.Response) error
- type APIError
- type APIModels
- type APIType
- type BalanceInfo
- type BalanceResponse
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionStream
- type Client
- type ClientConfig
- type Function
- type HTTPDoer
- type Model
- type Parameters
- type ResponseFormat
- type StreamChatCompletionMessage
- type StreamChatCompletionRequest
- type StreamChatCompletionResponse
- type StreamChoices
- type StreamDelta
- type StreamOptions
- type StreamUsage
- type TokenEstimate
- type Tools
Constants ¶
const ( DeepSeekChat = "deepseek-chat" DeepSeekCoder = "deepseek-coder" // not sure if this exists anymore DeepSeekReasoner = "deepseek-reasoner" )
Official DeepSeek Models
const ( AzureDeepSeekR1 = "DeepSeek-R1" // Azure model for DeepSeek R1 OpenRouterDeepSeekR1 = "deepseek/deepseek-r1" // OpenRouter model for DeepSeek R1 )
External Models that can be used with the API
const BaseURL string = "https://api.deepseek.com/v1"
Variables ¶
var ( ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method") ErrUnexpectedResponseFormat = errors.New("unexpected response format") )
Functions ¶
func HandleAPIError ¶
Types ¶
type APIError ¶
type APIModels ¶ added in v0.1.1
type BalanceInfo ¶
type BalanceInfo struct {
Currency string `json:"currency"` //The currency of the balance.
TotalBalance string `json:"total_balance"` //The total available balance, including the granted balance and the topped-up balance.
GrantedBalance string `json:"granted_balance"` //The total not expired granted balance.
ToppedUpBalance string `json:"topped_up_balance"` //The total topped-up balance.
}
type BalanceResponse ¶
type BalanceResponse struct {
IsAvailable bool `json:"is_available"` //Whether the user's balance is sufficient for API calls.
BalanceInfos []BalanceInfo `json:"balance_infos"` //List of Balance infos
}
func GetBalance ¶
func GetBalance(c *Client, ctx context.Context) (*BalanceResponse, error)
type ChatCompletionMessage ¶
func MapMessageToChatCompletionMessage ¶
func MapMessageToChatCompletionMessage(m handlers.Message) (ChatCompletionMessage, error)
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"` // Required: Model ID, e.g., "deepseek-chat"
Messages []ChatCompletionMessage `json:"messages"` // Required: List of messages
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // Optional: Frequency penalty, >= -2 and <= 2
MaxTokens int `json:"max_tokens,omitempty"` // Optional: Maximum tokens, > 1
PresencePenalty float32 `json:"presence_penalty,omitempty"` // Optional: Presence penalty, >= -2 and <= 2
Temperature float32 `json:"temperature,omitempty"` // Optional: Sampling temperature, <= 2
TopP float32 `json:"top_p,omitempty"` // Optional: Nucleus sampling parameter, <= 1
ResponseFormat *ResponseFormat `json:"response_format,omitempty"` // Optional: Custom response format
Stop []string `json:"stop,omitempty"` // Optional: Stop signals
Tools []Tools `json:"tools,omitempty"` // Optional: List of tools
LogProbs bool `json:"logprobs,omitempty"` // Optional: Enable log probabilities
TopLogProbs int `json:"top_logprobs,omitempty"` // Optional: Number of top tokens with log probabilities, <= 20
}
make a different struct for streaming with streaming options parameter
type ChatCompletionStream ¶
type ChatCompletionStream interface {
Recv() (*StreamChatCompletionResponse, error)
Close() error
}
ChatCompletionStream is an interface for receiving streaming chat completion responses.
type Client ¶
func NewClient ¶
NewClient creates a new client with an authentication token and an optional custom baseURL. If no baseURL is provided, it defaults to "https://api.deepseek.com/".
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, request *ChatCompletionRequest, ) (*handlers.ChatCompletionResponse, error)
CreateChatCompletion sends a chat completion request and returns the generated response.
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, request *StreamChatCompletionRequest, ) (ChatCompletionStream, error)
CreateStreamChatCompletion send a chat completion request with stream = true and returns the delta
type ClientConfig ¶
func DefaultConfig ¶
func DefaultConfig(AuthToken string) ClientConfig
type Function ¶
type Function struct {
Name string `json:"name"` // The name of the function (required)
Description string `json:"description"` // Description of the function (required)
Parameters *Parameters `json:"parameters,omitempty"` // Parameters schema (optional)
}
Function defines the structure of a function tool
type Parameters ¶
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type"` //either text or json_object. If json_object, please mention "json" anywhere in your prompt.
}
type StreamChatCompletionMessage ¶
type StreamChatCompletionMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
StreamChatCompletionMessage represents a single message in a chat completion stream.
type StreamChatCompletionRequest ¶
type StreamChatCompletionRequest struct {
Stream bool `json:"stream,omitempty"` //Comments: Defaults to true, since it's "STREAM"
Model string `json:"model"` // Required: Model ID, e.g., "deepseek-chat"
Messages []ChatCompletionMessage `json:"messages"` // Required: List of messages
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // Optional: Frequency penalty, >= -2 and <= 2
MaxTokens int `json:"max_tokens,omitempty"` // Optional: Maximum tokens, > 1
PresencePenalty float32 `json:"presence_penalty,omitempty"` // Optional: Presence penalty, >= -2 and <= 2
Temperature float32 `json:"temperature,omitempty"` // Optional: Sampling temperature, <= 2
TopP float32 `json:"top_p,omitempty"` // Optional: Nucleus sampling parameter, <= 1
ResponseFormat *ResponseFormat `json:"response_format,omitempty"` // Optional: Custom response format: just don't try, it breaks rn ;)
Stop []string `json:"stop,omitempty"` // Optional: Stop signals
Tools []Tools `json:"tools,omitempty"` // Optional: List of tools
LogProbs bool `json:"logprobs,omitempty"` // Optional: Enable log probabilities
TopLogProbs int `json:"top_logprobs,omitempty"` // Optional: Number of top tokens with log probabilities, <= 20
}
StreamChatCompletionRequest represents the request body for a streaming chat completion API call.
type StreamChatCompletionResponse ¶
type StreamChatCompletionResponse struct {
ID string `json:"id"` // ID of the response.
Object string `json:"object"` // Type of object.
Created int64 `json:"created"` // Creation timestamp.
Model string `json:"model"` // Model used.
Choices []StreamChoices `json:"choices"` // Choices generated.
Usage *StreamUsage `json:"usage,omitempty"` // Usage statistics (optional).
}
StreamChatCompletionResponse represents a single response from a streaming chat completion API call.
type StreamChoices ¶
type StreamChoices struct {
Index int `json:"index"` // Index of the choice.
Delta StreamDelta // Delta information.
FinishReason string `json:"finish_reason"` // Reason for finishing the generation.
}
StreamChoices represents a choice in the chat completion stream.
type StreamDelta ¶
type StreamDelta struct {
Role string `json:"role,omitempty"` // Role of the message.
Content string `json:"content"` // Content of the message.
}
StreamDelta represents a delta in the chat completion stream.
type StreamOptions ¶
type StreamOptions struct {
IncludeUsage bool
}
type StreamUsage ¶
type StreamUsage struct {
PromptTokens int `json:"prompt_tokens"` // Number of tokens in the prompt.
CompletionTokens int `json:"completion_tokens"` // Number of tokens in the completion.
TotalTokens int `json:"total_tokens"` // Total number of tokens used.
}
StreamUsage represents token usage statistics for a streaming chat completion response. You will get {0 0 0} up until the last stream delta.
type TokenEstimate ¶ added in v0.1.1
type TokenEstimate struct {
EstimatedTokens int `json:"estimated_tokens"` //the total estimated prompt tokens. These are different form total tokens used.
}
TokenEstimate represents an estimated token count
func EstimateTokenCount ¶ added in v0.1.1
func EstimateTokenCount(text string) *TokenEstimate
EstimateTokenCount estimates the number of tokens in a text based on character type ratios
func EstimateTokensFromMessages ¶ added in v0.1.1
func EstimateTokensFromMessages(messages *ChatCompletionRequest) *TokenEstimate
EstimateTokensFromMessages estimates the number of tokens in a list of chat messages