Skip to content

Commit

Permalink
SDK regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Mar 12, 2024
1 parent c677e30 commit f8f758d
Show file tree
Hide file tree
Showing 15 changed files with 1,597 additions and 795 deletions.
256 changes: 196 additions & 60 deletions client/client.go

Large diffs are not rendered by default.

66 changes: 54 additions & 12 deletions connectors/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func (c *Client) List(
) (*v2.ListConnectorsResponse, error) {
options := core.NewRequestOptions(opts...)

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

queryParams, err := core.QueryValues(request)
if err != nil {
Expand All @@ -77,6 +77,13 @@ func (c *Client) List(
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
Expand Down Expand Up @@ -114,14 +121,14 @@ func (c *Client) Create(
) (*v2.CreateConnectorResponse, error) {
options := core.NewRequestOptions(opts...)

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

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

Expand All @@ -147,6 +154,13 @@ func (c *Client) Create(
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
Expand Down Expand Up @@ -186,14 +200,14 @@ func (c *Client) Get(
) (*v2.GetConnectorResponse, error) {
options := core.NewRequestOptions(opts...)

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

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

Expand All @@ -219,6 +233,13 @@ func (c *Client) Get(
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
Expand Down Expand Up @@ -257,14 +278,14 @@ func (c *Client) Delete(
) (v2.DeleteConnectorResponse, error) {
options := core.NewRequestOptions(opts...)

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

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

Expand Down Expand Up @@ -297,6 +318,13 @@ func (c *Client) Delete(
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
Expand Down Expand Up @@ -336,14 +364,14 @@ func (c *Client) Update(
) (*v2.UpdateConnectorResponse, error) {
options := core.NewRequestOptions(opts...)

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

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

Expand Down Expand Up @@ -376,6 +404,13 @@ func (c *Client) Update(
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
Expand Down Expand Up @@ -416,14 +451,14 @@ func (c *Client) OAuthAuthorize(
) (*v2.OAuthAuthorizeResponse, error) {
options := core.NewRequestOptions(opts...)

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

queryParams, err := core.QueryValues(request)
if err != nil {
Expand Down Expand Up @@ -457,6 +492,13 @@ func (c *Client) OAuthAuthorize(
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
Expand Down
18 changes: 15 additions & 3 deletions core/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,27 @@ func TestQueryValues(t *testing.T) {

t.Run("date", func(t *testing.T) {
type example struct {
DateTime time.Time `json:"dateTime" url:"dateTime" format:"date"`
Date time.Time `json:"date" url:"date" format:"date"`
}

values, err := QueryValues(
&example{
DateTime: time.Date(1994, 3, 16, 12, 34, 56, 0, time.UTC),
Date: time.Date(1994, 3, 16, 12, 34, 56, 0, time.UTC),
},
)
require.NoError(t, err)
assert.Equal(t, "dateTime=1994-03-16", values.Encode())
assert.Equal(t, "date=1994-03-16", values.Encode())
})

t.Run("optional time", func(t *testing.T) {
type example struct {
Date *time.Time `json:"date,omitempty" url:"date,omitempty" format:"date"`
}

values, err := QueryValues(
&example{},
)
require.NoError(t, err)
assert.Empty(t, values.Encode())
})
}
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.5.2")
headers.Set("X-Fern-SDK-Version", "v2.6.0")
return headers
}

Expand Down
137 changes: 137 additions & 0 deletions core/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package core

import (
"encoding/json"
"time"
)

const dateFormat = "2006-01-02"

// DateTime wraps time.Time and adapts its JSON representation
// to conform to a RFC3339 date (e.g. 2006-01-02).
//
// Ref: https://ijmacd.github.io/rfc3339-iso8601
type Date struct {
t *time.Time
}

// NewDate returns a new *Date. If the given time.Time
// is nil, nil will be returned.
func NewDate(t time.Time) *Date {
return &Date{t: &t}
}

// NewOptionalDate returns a new *Date. If the given time.Time
// is nil, nil will be returned.
func NewOptionalDate(t *time.Time) *Date {
if t == nil {
return nil
}
return &Date{t: t}
}

// Time returns the Date's underlying time, if any. If the
// date is nil, the zero value is returned.
func (d *Date) Time() time.Time {
if d == nil || d.t == nil {
return time.Time{}
}
return *d.t
}

// TimePtr returns a pointer to the Date's underlying time.Time, if any.
func (d *Date) TimePtr() *time.Time {
if d == nil || d.t == nil {
return nil
}
if d.t.IsZero() {
return nil
}
return d.t
}

func (d *Date) MarshalJSON() ([]byte, error) {
if d == nil || d.t == nil {
return nil, nil
}
return json.Marshal(d.t.Format(dateFormat))
}

func (d *Date) UnmarshalJSON(data []byte) error {
var raw string
if err := json.Unmarshal(data, &raw); err != nil {
return err
}

parsedTime, err := time.Parse(dateFormat, raw)
if err != nil {
return err
}

*d = Date{t: &parsedTime}
return nil
}

// DateTime wraps time.Time and adapts its JSON representation
// to conform to a RFC3339 date-time (e.g. 2017-07-21T17:32:28Z).
//
// Ref: https://ijmacd.github.io/rfc3339-iso8601
type DateTime struct {
t *time.Time
}

// NewDateTime returns a new *DateTime.
func NewDateTime(t time.Time) *DateTime {
return &DateTime{t: &t}
}

// NewOptionalDateTime returns a new *DateTime. If the given time.Time
// is nil, nil will be returned.
func NewOptionalDateTime(t *time.Time) *DateTime {
if t == nil {
return nil
}
return &DateTime{t: t}
}

// Time returns the DateTime's underlying time, if any. If the
// date-time is nil, the zero value is returned.
func (d *DateTime) Time() time.Time {
if d == nil || d.t == nil {
return time.Time{}
}
return *d.t
}

// TimePtr returns a pointer to the DateTime's underlying time.Time, if any.
func (d *DateTime) TimePtr() *time.Time {
if d == nil || d.t == nil {
return nil
}
if d.t.IsZero() {
return nil
}
return d.t
}

func (d *DateTime) MarshalJSON() ([]byte, error) {
if d == nil || d.t == nil {
return nil, nil
}
return json.Marshal(d.t.Format(time.RFC3339))
}

func (d *DateTime) UnmarshalJSON(data []byte) error {
var raw string
if err := json.Unmarshal(data, &raw); err != nil {
return err
}

parsedTime, err := time.Parse(time.RFC3339, raw)
if err != nil {
return err
}

*d = DateTime{t: &parsedTime}
return nil
}
4 changes: 2 additions & 2 deletions datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

type DatasetsCreateRequest struct {
// The name of the uploaded dataset.
Name *string `json:"-" url:"name,omitempty"`
Name string `json:"-" url:"name"`
// The dataset type, which is used to validate the data.
Type *DatasetType `json:"-" url:"type,omitempty"`
Type DatasetType `json:"-" url:"type,omitempty"`
// Indicates if the original file should be stored.
KeepOriginalFile *bool `json:"-" url:"keep_original_file,omitempty"`
// Indicates whether rows with malformed input should be dropped (instead of failing the validation check). Dropped rows will be returned in the warnings field.
Expand Down
Loading

0 comments on commit f8f758d

Please sign in to comment.