Skip to content

Commit

Permalink
SDK regeneration (#74)
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 May 8, 2024
1 parent bd13c06 commit ed1baa1
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 14 deletions.
55 changes: 55 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,58 @@ func (c *Client) Detokenize(
}
return response, nil
}

// Checks that the api key in the Authorization header is valid and active
func (c *Client) CheckApiKey(
ctx context.Context,
opts ...option.RequestOption,
) (*v2.CheckApiKeyResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.cohere.ai/v1"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := baseURL + "/" + "check-api-key"

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

errorDecoder := func(statusCode int, body io.Reader) error {
raw, err := io.ReadAll(body)
if err != nil {
return err
}
apiError := core.NewAPIError(statusCode, errors.New(string(raw)))
decoder := json.NewDecoder(bytes.NewReader(raw))
switch statusCode {
case 429:
value := new(v2.TooManyRequestsError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
}
return apiError
}

var response *v2.CheckApiKeyResponse
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,
},
); err != nil {
return nil, err
}
return response, nil
}
2 changes: 1 addition & 1 deletion core/request_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *RequestOptions) cloneHeader() http.Header {
headers := r.HTTPHeader.Clone()
headers.Set("X-Fern-Language", "Go")
headers.Set("X-Fern-SDK-Name", "github.com/cohere-ai/cohere-go/v2")
headers.Set("X-Fern-SDK-Version", "v2.7.3")
headers.Set("X-Fern-SDK-Version", "v2.7.4")
return headers
}

Expand Down
2 changes: 1 addition & 1 deletion datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type DatasetsCreateRequest struct {
// The name of the uploaded dataset.
Name string `json:"-" url:"name"`
// The dataset type, which is used to validate the data. Valid types are `embed-input`, `reranker-finetune-input`, `prompt-completion-finetune-input`, `single-label-classification-finetune-input`, `chat-finetune-input`, and `multi-label-classification-finetune-input`.
// The dataset type, which is used to validate the data. Valid types are `embed-input`, `reranker-finetune-input`, `single-label-classification-finetune-input`, `chat-finetune-input`, and `multi-label-classification-finetune-input`.
Type DatasetType `json:"-" url:"type"`
// Indicates if the original file should be stored.
KeepOriginalFile *bool `json:"-" url:"keep_original_file,omitempty"`
Expand Down
Loading

0 comments on commit ed1baa1

Please sign in to comment.