Skip to content

Commit

Permalink
feat: go doc added
Browse files Browse the repository at this point in the history
  • Loading branch information
nurali-techie committed Feb 3, 2025
1 parent 940600e commit baca4a5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Go Client - Deepseek API
# Go-Deepseek -- Go Client for [Deepseek API](https://api-docs.deepseek.com/)

### Why yet another Go client?
## Demo

We needed to call the DeepSeek API from one of our Go services but couldn't find a complete and reliable Go client, so we built our own.
Left side -- https://chat.deepseek.com/

Right side -- [deepseek-demo](https://github.com/go-deepseek/deepseek-demo)

### Why this Go client is best?
https://github.com/user-attachments/assets/baa05145-a13c-460d-91ce-90129c5b32d7

## Why yet another Go client?

Because this Go client is not only complete and reliable but also simple and performant.
We needed to call the DeepSeek API from one of our Go services but couldn't find a complete and reliable Go client, so we built our own.

## Why this Go client is better?

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

Expand All @@ -21,14 +27,6 @@ Because this Go client is not only complete and reliable but also simple and per
go get github.com/go-deepseek/deepseek
```

## Demo

Left side -- https://chat.deepseek.com/

Right side -- [deepseek-demo](https://github.com/go-deepseek/deepseek-demo)

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

## Usage

Here’s an example of sending a "Hello Deepseek!" message using `model=deepseek-chat` and `stream=false`
Expand Down Expand Up @@ -70,3 +68,9 @@ func main() {
## Examples

Please check the [examples](examples/) directory, which showcases each feature of this client.

![examples](docs/examples_directory.png)

## Buy me a GitHub Star ⭐

If you like our work then please give github star to this repo. 😊
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package config

// Config for deepseek client.
//
// ApiKey - deepseek API key.
// TimeoutSeconds - http client timeout used by deepseek client.
// DisableRequestValidation - disable request validation by deepseek client.
type Config struct {
ApiKey string
TimeoutSeconds int
Expand Down
13 changes: 13 additions & 0 deletions deepseek.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ const (
)

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)

// StreamChatCompletionsChat 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)
}

// NewClient creates deeseek client with given api key.
func NewClient(apiKey string) (Client, error) {
config := config.Config{
ApiKey: apiKey,
Expand All @@ -34,6 +46,7 @@ func NewClient(apiKey string) (Client, error) {
return NewClientWithConfig(config)
}

// NewClient creates deeseek client with given client config.
func NewClientWithConfig(config config.Config) (Client, error) {
return client.NewClient(config)
}
Binary file added docs/examples_directory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
1 change: 1 addition & 0 deletions request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
ResponseFormatJsonObject = "json_object"
)

// ChatCompletionsRequest is request payload for `POST /chat/completions` API.
type ChatCompletionsRequest struct {
Messages []*Message `json:"messages"`
Model string `json:"model"`
Expand Down
1 change: 1 addition & 0 deletions response/response.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package response

// ChatCompletionsResponse is response payload for `POST /chat/completions` API.
type ChatCompletionsResponse struct {
Id string `json:"id"`
Choices []*Choice `json:"choices"`
Expand Down

0 comments on commit baca4a5

Please sign in to comment.