Skip to content

Commit

Permalink
feat: config added for enable req validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nurali-techie committed Feb 1, 2025
1 parent a18ed88 commit b7cd7cf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
40 changes: 24 additions & 16 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/go-deepseek/deepseek/response"
)

type Client struct {
type Client struct { // TODO: VN -- move to internal pkg
*http.Client
apiKey string
config.Config
}

func NewClient(config config.Config) (*Client, error) {
Expand All @@ -29,7 +29,7 @@ func NewClient(config config.Config) (*Client, error) {
}

c := &Client{
apiKey: config.ApiKey,
Config: config,
Client: &http.Client{
Timeout: time.Second * time.Duration(config.TimeoutSeconds),
},
Expand All @@ -45,9 +45,11 @@ func (c *Client) CallChatCompletionsChat(chatReq *request.ChatCompletionsRequest
if chatReq.Model != "deepseek-chat" {
return nil, errors.New(`err: model should be "deepseek-chat"`)
}
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
if c.EnableRequestValidation {
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
}
}

// call api
Expand All @@ -74,9 +76,11 @@ func (c *Client) StreamChatCompletionsChat(chatReq *request.ChatCompletionsReque
if chatReq.Model != "deepseek-chat" {
return nil, errors.New(`err: model should be "deepseek-chat"`)
}
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
if c.EnableRequestValidation {
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
}
}

// call api
Expand All @@ -97,9 +101,11 @@ func (c *Client) CallChatCompletionsReasoner(chatReq *request.ChatCompletionsReq
if chatReq.Model != "deepseek-reasoner" {
return nil, errors.New(`err: model should be "deepseek-reasoner"`)
}
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
if c.EnableRequestValidation {
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
}
}

// call api
Expand All @@ -126,9 +132,11 @@ func (c *Client) StreamChatCompletionsReasoner(chatReq *request.ChatCompletionsR
if chatReq.Model != "deepseek-reasoner" {
return nil, errors.New(`err: model should be "deepseek-reasoner"`)
}
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
if c.EnableRequestValidation {
err := request.ValidateChatCompletionsRequest(chatReq)
if err != nil {
return nil, err
}
}

// call api
Expand All @@ -154,7 +162,7 @@ func (c *Client) do(chatReq *request.ChatCompletionsRequest) (io.ReadCloser, err
if err != nil {
return nil, err
}
setDefaultHeaders(req, c.apiKey)
setDefaultHeaders(req, c.ApiKey)

resp, err := c.Client.Do(req)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

type Config struct {
ApiKey string
TimeoutSeconds int
ApiKey string
TimeoutSeconds int
EnableRequestValidation bool
}
5 changes: 3 additions & 2 deletions deepseek.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type Client interface {

func NewClient(apiKey string) (Client, error) {
config := config.Config{
ApiKey: apiKey,
TimeoutSeconds: DEFAULT_TIMEOUT_SECONDS,
ApiKey: apiKey,
TimeoutSeconds: DEFAULT_TIMEOUT_SECONDS,
EnableRequestValidation: true,
}
return NewClientWithConfig(config)
}
Expand Down

0 comments on commit b7cd7cf

Please sign in to comment.