Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
luoshengheng committed Nov 9, 2023
1 parent ec1b1a7 commit 2277a94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ChatCompletionRequest struct {
Functions []FunctionDefinition `json:"functions,omitempty"`
FunctionCall any `json:"function_call,omitempty"`
AllowFallback bool `json:"allow_fallback,omitempty"`
CaptchaToken string `json:"captchaToken,omitempty"` //easychat的额外参数
}

type FunctionDefinition struct {
Expand Down Expand Up @@ -149,6 +150,7 @@ type ChatCompletionResponse struct {
func (c *Client) CreateChatCompletion(
ctx context.Context,
request ChatCompletionRequest,
extraHeaders ...map[string]string,
) (response ChatCompletionResponse, err error) {
if request.Stream {
err = ErrChatCompletionStreamNotSupported
Expand All @@ -162,6 +164,17 @@ func (c *Client) CreateChatCompletion(
}

req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix, request.Model), withBody(request))
if len(extraHeaders) > 0 && extraHeaders[0] != nil {
for _, headers := range extraHeaders {
if headers == nil {
continue
}
for k, v := range headers {
req.Header.Set(k, v)
}
}

}
if err != nil {
return
}
Expand Down
12 changes: 12 additions & 0 deletions chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ChatCompletionStream struct {
func (c *Client) CreateChatCompletionStream(
ctx context.Context,
request ChatCompletionRequest,
extraHeaders ...map[string]string,
) (stream *ChatCompletionStream, err error) {
urlSuffix := chatCompletionsSuffix
if !checkEndpointSupportsModel(urlSuffix, request.Model) {
Expand All @@ -52,6 +53,17 @@ func (c *Client) CreateChatCompletionStream(
if err != nil {
return nil, err
}
if len(extraHeaders) > 0 && extraHeaders[0] != nil {
for _, headers := range extraHeaders {
if headers == nil {
continue
}
for k, v := range headers {
req.Header.Set(k, v)
}
}

}
resp, err := sendRequestStream[ChatCompletionStreamResponse](c, req)
if err != nil {
return
Expand Down

0 comments on commit 2277a94

Please sign in to comment.