Skip to content

Commit

Permalink
SDK regeneration (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
  • Loading branch information
fern-api[bot] authored Oct 15, 2024
1 parent abe8044 commit f736ded
Show file tree
Hide file tree
Showing 17 changed files with 7,565 additions and 2,790 deletions.
206 changes: 119 additions & 87 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
context "context"
json "encoding/json"
errors "errors"
fmt "fmt"
v2 "github.com/cohere-ai/cohere-go/v2"
connectors "github.com/cohere-ai/cohere-go/v2/connectors"
core "github.com/cohere-ai/cohere-go/v2/core"
Expand All @@ -15,6 +16,7 @@ import (
finetuningclient "github.com/cohere-ai/cohere-go/v2/finetuning/client"
models "github.com/cohere-ai/cohere-go/v2/models"
option "github.com/cohere-ai/cohere-go/v2/option"
v2v2 "github.com/cohere-ai/cohere-go/v2/v2"
io "io"
http "net/http"
os "os"
Expand All @@ -25,6 +27,7 @@ type Client struct {
caller *core.Caller
header http.Header

V2 *v2v2.Client
EmbedJobs *embedjobs.Client
Datasets *datasets.Client
Connectors *connectors.Client
Expand All @@ -46,6 +49,7 @@ func NewClient(opts ...option.RequestOption) *Client {
},
),
header: options.ToHeader(),
V2: v2v2.NewClient(opts...),
EmbedJobs: embedjobs.NewClient(opts...),
Datasets: datasets.NewClient(opts...),
Connectors: connectors.NewClient(opts...),
Expand All @@ -55,7 +59,7 @@ func NewClient(opts ...option.RequestOption) *Client {
}

// Generates a text response to a user message.
// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
// To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
func (c *Client) ChatStream(
ctx context.Context,
request *v2.ChatStreamRequest,
Expand All @@ -73,6 +77,9 @@ func (c *Client) ChatStream(
endpointURL := baseURL + "/v1/chat"

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())
if request.Accepts != nil {
headers.Add("Accepts", fmt.Sprintf("%v", request.Accepts))
}

errorDecoder := func(statusCode int, body io.Reader) error {
raw, err := io.ReadAll(body)
Expand Down Expand Up @@ -167,19 +174,21 @@ func (c *Client) ChatStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}

// Generates a text response to a user message.
// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
// To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
func (c *Client) Chat(
ctx context.Context,
request *v2.ChatRequest,
Expand All @@ -197,6 +206,9 @@ func (c *Client) Chat(
endpointURL := baseURL + "/v1/chat"

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())
if request.Accepts != nil {
headers.Add("Accepts", fmt.Sprintf("%v", request.Accepts))
}

errorDecoder := func(statusCode int, body io.Reader) error {
raw, err := io.ReadAll(body)
Expand Down Expand Up @@ -291,14 +303,16 @@ func (c *Client) Chat(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -421,13 +435,15 @@ func (c *Client) GenerateStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}
Expand Down Expand Up @@ -547,14 +563,16 @@ func (c *Client) Generate(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -678,14 +696,16 @@ func (c *Client) Embed(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -805,14 +825,16 @@ func (c *Client) Rerank(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -933,14 +955,16 @@ func (c *Client) Classify(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -1063,14 +1087,16 @@ func (c *Client) Summarize(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -1190,14 +1216,16 @@ func (c *Client) Tokenize(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -1317,14 +1345,16 @@ func (c *Client) Detokenize(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -1443,13 +1473,15 @@ func (c *Client) CheckApiKey(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit f736ded

Please sign in to comment.