dsr

package module
v0.0.0-...-3bc8d4f Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: GPL-2.0 Imports: 10 Imported by: 2

README

go-dsr

GoDoc Go Report Card

⚠️ This is currently in development. Things will probably break, but existing functionality is usable. ⚠️

go get github.com/samjtro/go-dsr

built by: rizome labs

contact us: hi (at) rizome.dev

quick start

  1. create a .env, formatted:
DEEPSEEK_API_KEY="KEY"

example

c := dsr.NewChatClient()
c.AddUserMessage("hello!")
res, _ := c.GetNextChatCompletion()
c.AddMessage(res.Choices[0].Message)
c.AddUserMessage("can you help me with a math problem?")
res, _ = c.GetNextChatCompletion()
c.AddMessage(res.Choices[0].Message)
fmt.Println(c.Messages)

output:

[{user hello! }

{assistant Hello! How can I assist you today? 😊 Okay, the user just said "hello!" That's a friendly greeting.

I should respond in a warm and welcoming manner.

Maybe say something like "Hello! How can I assist you today?" to keep the conversation going.

Keep it simple and open-ended so they feel comfortable asking for help.}

{user can you help me with a math problem? }

{assistant Of course! I'd be happy to help with your math problem. Please go ahead and share the details, and I'll do my best to guide you through it step by step. 😊 Okay, the user asked if I can help with a math problem. Let me respond positively first. I need to be encouraging.

They might have a specific problem in mind. I should ask them to provide the details so I can understand what they need. Maybe it's algebra, calculus, geometry? I shouldn't assume.

I should also mention that they can type the problem as they have it, even if it's not perfectly formatted. That way they feel comfortable sharing whatever they have. Maybe add an emoji to keep the tone friendly. Let me check the previous message for the emoji usage. The user used a smiley in their first message, so it's okay to use one here too.

Wait, the last response from the assistant had a 😊. Repeating emojis might be okay, but maybe a different one? Or stick to the same. Hmm. Probably better to use a similar friendly emoji. Let me go with 😊 again.

Need to make sure the user feels supported. Also, avoid technical jargon in the request. Keep it simple. Let them know I can guide them through step by step. That's important because they might need explanation, not just the answer.

Alright, the response should be something like: "Of course! I'd be happy to help with your math problem. Please go ahead and share the details, and I'll do my best to guide you through it step by step. 😊"}]

Documentation

Index

Constants

View Source
const (
	BASE_URL = "https://api.deepseek.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatClient

type ChatClient struct {
	*Client
	Messages []Message
}

func NewChatClient

func NewChatClient(opts ...ClientOption) *ChatClient

func (*ChatClient) AddAssistantMessage

func (c *ChatClient) AddAssistantMessage(content, reasoningContent string)

func (*ChatClient) AddMessage

func (c *ChatClient) AddMessage(m Message)

func (*ChatClient) AddSystemMessage

func (c *ChatClient) AddSystemMessage(content string)

func (*ChatClient) AddUserMessage

func (c *ChatClient) AddUserMessage(content string)

func (*ChatClient) GetNextChatCompletion

func (c *ChatClient) GetNextChatCompletion() (*Response, error)

type Choice

type Choice struct {
	Index        int      `json:"index"`
	Message      Message  `json:"message"`
	Logprobs     Logprobs `json:"logprobs"`
	FinishReason string   `json:"finish_reason"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Initiate

func Initiate(opts ...ClientOption) *Client

func (*Client) Handler

func (c *Client) Handler(resp *http.Response) (*Response, error)

type ClientOption

type ClientOption func(*ClientOptions)

type ClientOptions

type ClientOptions struct {
	Key string
	Log *slog.Logger
}

type Logprobs

type Logprobs struct {
	Content struct {
		Token       string  `json:"token"`
		Logprob     float64 `json:"logprob"`
		Bytes       []int   `json:"bytes"`
		TopLogprobs []struct {
			Token   string  `json:"token"`
			Logprob float64 `json:"logprob"`
			Bytes   []int   `json:"bytes"`
		} `json:"top_logprobs"`
	} `json:"content"`
}

type Message

type Message struct {
	Role             string `json:"role"`
	Content          string `json:"content"`
	ReasoningContent string `json:"reasoning_content,omitempty"`
}

type Response

type Response struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int      `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   struct {
		PromptTokens        int `json:"prompt_tokens"`
		CompletionTokens    int `json:"completion_tokens"`
		TotalTokens         int `json:"total_tokens"`
		PromptTokensDetails struct {
			CachedTokens int `json:"cached_tokens"`
		} `json:"prompt_tokens_details"`
		CompletionTokensDetails struct {
			ReasoningTokens int `json:"reasoning_tokens"`
		} `json:"completion_tokens_details"`
		PromptCacheHitTokens  int `json:"prompt_cache_hit_tokens"`
		PromptCacheMissTokens int `json:"prompt_cache_miss_tokens"`
	} `json:"usage"`
	SystemFingerprint string `json:"system_fingerprint"`
}

Jump to

Keyboard shortcuts

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