deepseek

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: GPL-3.0 Imports: 5 Imported by: 1

README

Go-Deepseek

Go-deepseek is a Go client for the DeepSeek API; supporting DeepSeek-V3, DeepSeek-R1, and more, with both streaming and non-streaming options. This production-ready client is actively maintained, with ongoing bug fixes and feature enhancements.

go-deepseek-design

Demo

30 seconds deepseek-demo (code):

left-side browser with chat.deepseek.com v/s go-deepseek in right-side terminal.

https://github.com/user-attachments/assets/baa05145-a13c-460d-91ce-90129c5b32d7

Install

go get github.com/go-deepseek/deepseek

Usage

go-deepseek-flow

Here’s an example of sending a "Hello Deepseek!" message using model=deepseek-chat (DeepSeek-V3 model) and stream=false

package main

import (
	"context"
	"fmt"

	"github.com/go-deepseek/deepseek"
	"github.com/go-deepseek/deepseek/request"
)

func main() {
	client, _ := deepseek.NewClient("your_deepseek_api_token")

	chatReq := &request.ChatCompletionsRequest{
		Model:  deepseek.DEEPSEEK_CHAT_MODEL,
		Stream: false,
		Messages: []*request.Message{
			{
				Role:    "user",
				Content: "Hello Deepseek!", // set your input message
			},
		},
	}

	chatResp, err := client.CallChatCompletionsChat(context.Background(), chatReq)
	if err != nil {
		fmt.Println("Error =>", err)
		return
	}
	fmt.Printf("output => %s\n", chatResp.Choices[0].Message.Content)
}

Try above example:

First, copy above code in `main.go`
Replace `your_deepseek_api_token` with valid api token

$ go mod init
$ go get github.com/go-deepseek/deepseek

$ go run main.go
output => Hello! How can I assist you today? 😊

Why yet another Go client?

We were looking for Dedicated & Simple Go Client for Deepseek API but we didn't find it so we built this one 😃

What's special about this Go client?

  • Simple – Check below, Go package structure with all exported entities. It is as simple as possible. Also, it's Go's idiomatic way - request is under request pkg, response is under response.

  • Complete – Check below, It offers full support for all APIs, including their complete request and response payloads. (Note: Beta feature support coming soon.)

go_pkg_structure

  • Reliable – We have implemented numerous Go tests to ensure that all features work correctly at all times.

  • Performant – Speed is crucial when working with AI models. We have optimized this client to deliver the fastest possible performance.

[!IMPORTANT]
We know that sometimes Deepseek API is down but we won't let you down.

We have Fake Client using which you can continue your development and testing even though Deepseek API is down.

Use fake.NewFakeCallbackClient(fake.Callbacks{}) / See example examples/81-fake-callback-client/main_test.go

Examples

Please check the examples directory, which showcases each feature of this client.

examples

Buy me a GitHub Star ⭐

If you like our work then please give github star to this repo. 😊

Documentation

Index

Constants

View Source
const (
	DEEPSEEK_CHAT_MODEL     = "deepseek-chat"
	DEEPSEEK_REASONER_MODEL = "deepseek-reasoner"
)
View Source
const DEFAULT_TIMEOUT_SECONDS = 120

Variables

This section is empty.

Functions

func NewConfigWithDefaults added in v0.4.0

func NewConfigWithDefaults() config.Config

NewConfigWithDefaults returns client config with default values.

Types

type Client

type Client interface {
	// CallChatCompletionsChat calls chat api with model=deepseek-chat and stream=false.
	// It returns response from DeepSeek-V3 model.
	CallChatCompletionsChat(ctx context.Context, chatReq *request.ChatCompletionsRequest) (*response.ChatCompletionsResponse, error)

	// CallChatCompletionsReasoner calls chat api with model=deepseek-reasoner and stream=false.
	// It returns response from DeepSeek-R1 model.
	CallChatCompletionsReasoner(ctx context.Context, chatReq *request.ChatCompletionsRequest) (*response.ChatCompletionsResponse, error)

	// StreamChatCompletionsChat calls chat api with model=deepseek-chat and stream=true.
	// It returns response from DeepSeek-V3 model.
	StreamChatCompletionsChat(ctx context.Context, chatReq *request.ChatCompletionsRequest) (response.StreamReader, error)

	// StreamChatCompletionsReasoner calls chat api with model=deepseek-reasoner and stream=true.
	// It returns response from DeepSeek-R1 model.
	StreamChatCompletionsReasoner(ctx context.Context, chatReq *request.ChatCompletionsRequest) (response.StreamReader, error)

	// PingChatCompletions is a ping to check go deepseek client is working fine.
	PingChatCompletions(ctx context.Context, inputMessage string) (outputMessge string, err error)
}

Client interface defines methods for interacting with the DeepSeek API.

func NewClient

func NewClient(apiKey string) (Client, error)

NewClient returns deeseek client which uses given deepseek API key.

func NewClientWithConfig

func NewClientWithConfig(config config.Config) (Client, error)

NewClientWithConfig returns deeseek client with given client config.

Jump to

Keyboard shortcuts

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