Skip to content

Commit

Permalink
🌿 Fern Regeneration -- April 4, 2024 (#70)
Browse files Browse the repository at this point in the history
* SDK regeneration

* Drop banner and fix tests

* Ignore ci.yml

---------

Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: Billy Trend <[email protected]>
  • Loading branch information
fern-api[bot] and billytrend-cohere authored Apr 5, 2024
1 parent bde3a73 commit 41e65d0
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 162 deletions.
4 changes: 2 additions & 2 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Specify files that shouldn't be modified by Fern
README.md
banner.png
LICENSE
.github/workflows/e2e.yml
tests/
tests/
.github/workflows/ci.yml
13 changes: 1 addition & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,4 @@ jobs:
uses: actions/setup-go@v4

- name: Compile
run: go build ./...
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up go
uses: actions/setup-go@v4

- name: Test
run: go test ./...
run: go build ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cohere Go Library

![](banner.png)
![](https://raw.githubusercontent.com/cohere-ai/cohere-typescript/5188b11a6e91727fdd4d46f4a690419ad204224d/banner.png)

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)
[![go shield](https://img.shields.io/badge/go-docs-blue)](https://pkg.go.dev/github.com/cohere-ai/cohere-go/v2)
Expand Down
Binary file removed banner.png
Binary file not shown.
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.0")
headers.Set("X-Fern-SDK-Version", "v2.7.1")
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.
// 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`.
Type DatasetType `json:"-" url:"type,omitempty"`
// Indicates if the original file should be stored.
KeepOriginalFile *bool `json:"-" url:"keep_original_file,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions embed_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ type CreateEmbedJobRequest struct {
InputType EmbedInputType `json:"input_type,omitempty" url:"input_type,omitempty"`
// The name of the embed job.
Name *string `json:"name,omitempty" url:"name,omitempty"`
// Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.
//
// * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models.
// * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
// * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
// * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models.
// * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
EmbeddingTypes []EmbeddingType `json:"embedding_types,omitempty" url:"embedding_types,omitempty"`
// One of `START|END` to specify how the API will handle inputs longer than the maximum token length.
//
// Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.
Expand Down
71 changes: 71 additions & 0 deletions models/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"
core "github.com/cohere-ai/cohere-go/v2/core"
option "github.com/cohere-ai/cohere-go/v2/option"
Expand Down Expand Up @@ -34,6 +35,76 @@ func NewClient(opts ...option.RequestOption) *Client {
}
}

// Returns the details of a model, provided its name.
func (c *Client) Get(
ctx context.Context,
model string,
opts ...option.RequestOption,
) (*v2.GetModelResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.cohere.ai/v1"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"models/%v", model)

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 400:
value := new(v2.BadRequestError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
case 429:
value := new(v2.TooManyRequestsError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
case 500:
value := new(v2.InternalServerError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
}
return apiError
}

var response *v2.GetModelResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
}
return response, nil
}

// Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models.
func (c *Client) List(
ctx context.Context,
Expand Down
4 changes: 2 additions & 2 deletions tests/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestNewClient(t *testing.T) {
context.TODO(),
&cohere.TokenizeRequest{
Text: str,
Model: strPointer("base"),
Model: "base",
},
)

Expand Down Expand Up @@ -357,7 +357,7 @@ func TestNewClient(t *testing.T) {
Description: "Connects to a database about sales volumes",
ParameterDefinitions: map[string]*cohere.ToolParameterDefinitionsValue{
"day": {
Description: "Retrieves sales data from this day, formatted as YYYY-MM-DD.",
Description: strPointer("Retrieves sales data from this day, formatted as YYYY-MM-DD."),
Type: "str",
Required: boolPointer(true),
},
Expand Down
Loading

0 comments on commit 41e65d0

Please sign in to comment.