# deepseek-go **Repository Path**: jiebinhu/deepseekgosdk ## Basic Information - **Project Name**: deepseek-go - **Description**: fork from https://github.com/cohesion-org/deepseek-go - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-01-08 - **Last Updated**: 2025-02-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Deepseek-Go [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) Deepseek-Go is a Go-based API wrapper for the [Deepseek](https://deepseek.com) platform. It provides a clean and type-safe interface to interact with Deepseek's AI features, including chat completions with streaming, token usage tracking, and more. This library is designed for developers building Go applications that require seamless integration with Deepseek AI. ## Features - **Chat Completion**: Easily send chat messages and receive responses from Deepseek's AI models. It also supports streaming. - **Modular Design**: The library is structured into reusable components for building, sending, and handling requests and responses. - **MIT License**: Open-source and free for both personal and commercial use. ## Installation To use Deepseek-Go, ensure you have Go installed, and run: ```sh go get github.com/cohesion-org/deepseek-go ``` ## Getting Started Here's a quick example of how to use the library: ### Prerequisites Before using the library, ensure you have: - A valid Deepseek API key. - Go installed on your system.
Chat ### Example for chatting with deepseek ```go package main import ( "context" "fmt" "log" "os" deepseek "github.com/cohesion-org/deepseek-go" ) func main() { // Set up the Deepseek client client := deepseek.NewClient(os.Getenv("DEEPSEEK_KEY")) // Create a chat completion request request := &deepseek.ChatCompletionRequest{ Model: deepseek.DeepSeekChat, Messages: []deepseek.ChatCompletionMessage{ {Role: deepseek.ChatMessageRoleSystem, Content: "Answer every question using slang."}, {Role: deepseek.ChatMessageRoleUser, Content: "Which is the tallest mountain in the world?"}, }, } // Send the request and handle the response ctx := context.Background() response, err := client.CreateChatCompletion(ctx, request) if err != nil { log.Fatalf("error: %v", err) } // Print the response fmt.Println("Response:", response.Choices[0].Message.Content) } ``` Save this code to a file (e.g., `main.go`), and run it: ```sh go run main.go ```
Sedning other params like Temp, Stop You just need to extend the ChatCompletionMessage with the supported parameters. ```go request := &deepseek.ChatCompletionRequest{ Model: deepseek.DeepSeekChat, Messages: []deepseek.ChatCompletionMessage{ {Role: deepseek.ChatMessageRoleUser, Content: "What is the meaning of deepseek"}, {Role: deepseek.ChatMessageRoleSystem, Content: "Answer every question using slang"}, }, Temperature: 1.0, Stop: []string{"yo", "hello"}, ResponseFormat: &deepseek.ResponseFormat{ Type: "text", }, } ```
Chat with Streaming ```go package main import ( "context" "errors" "fmt" "io" "log" "os" deepseek "github.com/cohesion-org/deepseek-go" ) func main() { client := deepseek.NewClient(os.Getenv("DEEPSEEK_KEY")) request := &deepseek.StreamChatCompletionRequest{ Model: deepseek.DeepSeekChat, Messages: []deepseek.ChatCompletionMessage{ {Role: deepseek.ChatMessageRoleUser, Content: "Just testing if the streaming feature is working or not!"}, }, Stream: true, } ctx := context.Background() stream, err := client.CreateChatCompletionStream(ctx, request) if err != nil { log.Fatalf("ChatCompletionStream error: %v", err) } var fullMessage string defer stream.Close() for { response, err := stream.Recv() if errors.Is(err, io.EOF) { fmt.Println("\nStream finished") break } if err != nil { fmt.Printf("\nStream error: %v\n", err) break } for _, choice := range response.Choices { fullMessage += choice.Delta.Content // Accumulate chunk content log.Println(choice.Delta.Content) } } log.Println("The full message is: ", fullMessage) } ```
Get the balance(s) of the user. ```go package main import ( "context" "log" "os" deepseek "github.com/cohesion-org/deepseek-go" ) func main() { client := deepseek.NewClient(os.Getenv("DEEPSEEK_KEY")) ctx := context.Background() balance, err := deepseek.GetBalance(client, ctx) if err != nil { log.Fatalf("Error getting balance: %v", err) } if balance == nil { log.Fatalf("Balance is nil") } if len(balance.BalanceInfos) == 0 { log.Fatalf("No balance information returned") } log.Printf("%+v\n", balance) } ```
--- ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. --- ## TODO - [X] Make streaming possible. - [ ] Add examples for token usage tracking. - [ ] Improve error handling in the wrapper. - [ ] Add support for other Deepseek endpoints. - [ ] Write comprehensive tests. --- ## Credits - **`chat.go` Inspiration**: Adapted from [sashabaranov/go-openai](https://github.com/sashabaranov/go-openai/tree/master). --- Feel free to contribute, open issues, or submit PRs to help improve Deepseek-Go! Let us know if you encounter any issues.