From 727e4778da18f05a73d952cfdab9887a5f159082 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:23:58 +0000 Subject: [PATCH] Release v2.2.0 --- client/client.go | 15 +- connectors.go | 268 +++++++++++++++++++++ connectors/client.go | 405 ++++++++++++++++++++++++++++++++ core/client_option.go | 2 +- dataset.go => datasets.go | 40 ++-- {dataset => datasets}/client.go | 16 +- doc.go | 2 +- errors.go | 46 ++++ types.go | 115 +++++++++ 9 files changed, 873 insertions(+), 36 deletions(-) create mode 100644 connectors.go create mode 100644 connectors/client.go rename dataset.go => datasets.go (72%) rename {dataset => datasets}/client.go (84%) diff --git a/client/client.go b/client/client.go index c2bed45..e10f3b2 100644 --- a/client/client.go +++ b/client/client.go @@ -9,8 +9,9 @@ import ( 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" - dataset "github.com/cohere-ai/cohere-go/v2/dataset" + datasets "github.com/cohere-ai/cohere-go/v2/datasets" io "io" http "net/http" ) @@ -20,7 +21,8 @@ type Client struct { caller *core.Caller header http.Header - Dataset *dataset.Client + Datasets *datasets.Client + Connectors *connectors.Client } func NewClient(opts ...core.ClientOption) *Client { @@ -29,10 +31,11 @@ func NewClient(opts ...core.ClientOption) *Client { opt(options) } return &Client{ - baseURL: options.BaseURL, - caller: core.NewCaller(options.HTTPClient), - header: options.ToHeader(), - Dataset: dataset.NewClient(opts...), + baseURL: options.BaseURL, + caller: core.NewCaller(options.HTTPClient), + header: options.ToHeader(), + Datasets: datasets.NewClient(opts...), + Connectors: connectors.NewClient(opts...), } } diff --git a/connectors.go b/connectors.go new file mode 100644 index 0000000..8bcce5a --- /dev/null +++ b/connectors.go @@ -0,0 +1,268 @@ +// This file was auto-generated by Fern from our API Definition. + +package api + +import ( + json "encoding/json" + fmt "fmt" + core "github.com/cohere-ai/cohere-go/v2/core" +) + +type CreateRequest struct { + // A human-readable name for the connector. + Name string `json:"name"` + // A description of the connector. + Description *string `json:"description,omitempty"` + // The URL of the connector that will be used to search for documents. + Url string `json:"url"` + // A list of fields to exclude from the prompt (fields remain in the document). + Excludes []string `json:"excludes,omitempty"` + // The OAuth 2.0 configuration for the connector. Cannot be specified if serviceAuth is specified. + Oauth *CreateConnectorOAuth `json:"oauth,omitempty"` + // Whether the connector is active or not. + Active *bool `json:"active,omitempty"` + // Whether a chat request should continue or not if the request to this connector fails. + ContinueOnFailure *bool `json:"continueOnFailure,omitempty"` + // The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. + ServiceAuth *CreateConnectorServiceAuth `json:"serviceAuth,omitempty"` +} + +type ListRequest struct { + // Maximum number of connectors to return [0, 100]. + Limit *float64 `json:"-"` + // Number of connectors to skip before returning results [0, inf]. + Offset *float64 `json:"-"` +} + +type CreateConnectorOAuth struct { + // The OAuth 2.0 client ID. This fields is encrypted at rest. + ClientId string `json:"clientId"` + // The OAuth 2.0 client Secret. This field is encrypted at rest and never returned in a response. + ClientSecret string `json:"clientSecret"` + // The OAuth 2.0 /authorize endpoint to use when users authorize the connector. + AuthorizeUrl string `json:"authorizeUrl"` + // The OAuth 2.0 /token endpoint to use when users authorize the connector. + TokenUrl string `json:"tokenUrl"` + // The OAuth scopes to request when users authorize the connector. + Scope *string `json:"scope,omitempty"` + + _rawJSON json.RawMessage +} + +func (c *CreateConnectorOAuth) UnmarshalJSON(data []byte) error { + type unmarshaler CreateConnectorOAuth + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CreateConnectorOAuth(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CreateConnectorOAuth) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type CreateConnectorServiceAuth struct { + // The token_type specifies the way the token is passed in the Authorization header. Valid values are "bearer", "basic", and "noscheme". + Type string `json:"type"` + // The token that will be used in the HTTP Authorization header when making requests to the connector. This field is encrypted at rest and never returned in a response. + Token string `json:"token"` + + _rawJSON json.RawMessage +} + +func (c *CreateConnectorServiceAuth) UnmarshalJSON(data []byte) error { + type unmarshaler CreateConnectorServiceAuth + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CreateConnectorServiceAuth(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CreateConnectorServiceAuth) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type CreateResponse struct { + Connector *Connector `json:"connector,omitempty"` + + _rawJSON json.RawMessage +} + +func (c *CreateResponse) UnmarshalJSON(data []byte) error { + type unmarshaler CreateResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CreateResponse(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CreateResponse) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type DeleteResponse = map[string]interface{} + +type GetResponse struct { + Connector *Connector `json:"connector,omitempty"` + + _rawJSON json.RawMessage +} + +func (g *GetResponse) UnmarshalJSON(data []byte) error { + type unmarshaler GetResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *g = GetResponse(value) + g._rawJSON = json.RawMessage(data) + return nil +} + +func (g *GetResponse) String() string { + if len(g._rawJSON) > 0 { + if value, err := core.StringifyJSON(g._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(g); err == nil { + return value + } + return fmt.Sprintf("%#v", g) +} + +type ListResponse struct { + Connectors []*Connector `json:"connectors,omitempty"` + + _rawJSON json.RawMessage +} + +func (l *ListResponse) UnmarshalJSON(data []byte) error { + type unmarshaler ListResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *l = ListResponse(value) + l._rawJSON = json.RawMessage(data) + return nil +} + +func (l *ListResponse) String() string { + if len(l._rawJSON) > 0 { + if value, err := core.StringifyJSON(l._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(l); err == nil { + return value + } + return fmt.Sprintf("%#v", l) +} + +type OAuthAuthorizeResponse struct { + // The OAuth 2.0 redirect url. Redirect the user to this url to authorize the connector. + RedirectUrl *string `json:"redirect_url,omitempty"` + + _rawJSON json.RawMessage +} + +func (o *OAuthAuthorizeResponse) UnmarshalJSON(data []byte) error { + type unmarshaler OAuthAuthorizeResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *o = OAuthAuthorizeResponse(value) + o._rawJSON = json.RawMessage(data) + return nil +} + +func (o *OAuthAuthorizeResponse) String() string { + if len(o._rawJSON) > 0 { + if value, err := core.StringifyJSON(o._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(o); err == nil { + return value + } + return fmt.Sprintf("%#v", o) +} + +type UpdateResponse struct { + Connector *Connector `json:"connector,omitempty"` + + _rawJSON json.RawMessage +} + +func (u *UpdateResponse) UnmarshalJSON(data []byte) error { + type unmarshaler UpdateResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *u = UpdateResponse(value) + u._rawJSON = json.RawMessage(data) + return nil +} + +func (u *UpdateResponse) String() string { + if len(u._rawJSON) > 0 { + if value, err := core.StringifyJSON(u._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(u); err == nil { + return value + } + return fmt.Sprintf("%#v", u) +} + +type UpdateRequest struct { + // A human-readable name for the connector. + Name *string `json:"name,omitempty"` + // The URL of the connector that will be used to search for documents. + Url *string `json:"url,omitempty"` + // A list of fields to exclude from the prompt (fields remain in the document). + Excludes []string `json:"excludes,omitempty"` + // The OAuth 2.0 configuration for the connector. Cannot be specified if serviceAuth is specified. + Oauth *CreateConnectorOAuth `json:"oauth,omitempty"` + Active *bool `json:"active,omitempty"` + ContinueOnFailure *bool `json:"continueOnFailure,omitempty"` + // The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. + ServiceAuth *CreateConnectorServiceAuth `json:"serviceAuth,omitempty"` +} diff --git a/connectors/client.go b/connectors/client.go new file mode 100644 index 0000000..dc897d2 --- /dev/null +++ b/connectors/client.go @@ -0,0 +1,405 @@ +// This file was auto-generated by Fern from our API Definition. + +package connectors + +import ( + bytes "bytes" + 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" + io "io" + http "net/http" + url "net/url" +) + +type Client struct { + baseURL string + caller *core.Caller + header http.Header +} + +func NewClient(opts ...core.ClientOption) *Client { + options := core.NewClientOptions() + for _, opt := range opts { + opt(options) + } + return &Client{ + baseURL: options.BaseURL, + caller: core.NewCaller(options.HTTPClient), + header: options.ToHeader(), + } +} + +// Returns a list of connectors ordered by descending creation date (newer first). +func (c *Client) List(ctx context.Context, request *v2.ListRequest) (*v2.ListResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := baseURL + "/" + "v1/connectors" + + queryParams := make(url.Values) + if request.Limit != nil { + queryParams.Add("limit", fmt.Sprintf("%v", *request.Limit)) + } + if request.Offset != nil { + queryParams.Add("offset", fmt.Sprintf("%v", *request.Offset)) + } + if len(queryParams) > 0 { + endpointURL += "?" + queryParams.Encode() + } + + 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 500: + value := new(v2.InternalServerError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + } + return apiError + } + + var response *v2.ListResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodGet, + Headers: c.header, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Creates a new connector. The connector is tested during registration +// and will cancel registration when the test is unsuccessful. +func (c *Client) Create(ctx context.Context, request *v2.CreateRequest) (*v2.CreateResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := baseURL + "/" + "v1/connectors" + + 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 403: + value := new(v2.ForbiddenError) + 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.CreateResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: c.header, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Retrieve a connector by ID. +// +// The ID of the connector to retrieve. +func (c *Client) Get(ctx context.Context, id string) (*v2.GetResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v1/connectors/%v", id) + + 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 404: + value := new(v2.NotFoundError) + 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.GetResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodGet, + Headers: c.header, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Delete a connector by ID. +// +// The ID of the connector to delete. +func (c *Client) Delete(ctx context.Context, id string) (v2.DeleteResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v1/connectors/%v", id) + + 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 403: + value := new(v2.ForbiddenError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 404: + value := new(v2.NotFoundError) + 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.DeleteResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodDelete, + Headers: c.header, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Update a connector by ID. Omitted fields will not be updated. +// +// The ID of the connector to update. +func (c *Client) Update(ctx context.Context, id string, request *v2.UpdateRequest) (*v2.UpdateResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v1/connectors/%v", id) + + 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 403: + value := new(v2.ForbiddenError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 404: + value := new(v2.NotFoundError) + 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.UpdateResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodPatch, + Headers: c.header, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Authorize the connector with the given ID for the connector oauth app. +// +// The ID of the connector to authorize. +func (c *Client) OAuthAuthorize(ctx context.Context, id string) (*v2.OAuthAuthorizeResponse, error) { + baseURL := "https://api.cohere.ai" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v1/connectors/%v/oauth/authorize", id) + + 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 404: + value := new(v2.NotFoundError) + 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.OAuthAuthorizeResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: c.header, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} diff --git a/core/client_option.go b/core/client_option.go index ba20f21..d9761de 100644 --- a/core/client_option.go +++ b/core/client_option.go @@ -43,6 +43,6 @@ func (c *ClientOptions) cloneHeader() http.Header { headers := c.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.1.0") + headers.Set("X-Fern-SDK-Version", "v2.2.0") return headers } diff --git a/dataset.go b/datasets.go similarity index 72% rename from dataset.go rename to datasets.go index 43819f9..1935786 100644 --- a/dataset.go +++ b/datasets.go @@ -9,7 +9,7 @@ import ( time "time" ) -type DatasetGetRequest struct { +type DatasetsListRequest struct { // optional filter by dataset type DatasetType *string `json:"-"` // optional filter before a date @@ -22,24 +22,24 @@ type DatasetGetRequest struct { Offset *string `json:"-"` } -type DatasetGetResponse struct { - Datasets []*Dataset `json:"datasets,omitempty"` +type DatasetsGetResponse struct { + Dataset *Dataset `json:"dataset,omitempty"` _rawJSON json.RawMessage } -func (d *DatasetGetResponse) UnmarshalJSON(data []byte) error { - type unmarshaler DatasetGetResponse +func (d *DatasetsGetResponse) UnmarshalJSON(data []byte) error { + type unmarshaler DatasetsGetResponse var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *d = DatasetGetResponse(value) + *d = DatasetsGetResponse(value) d._rawJSON = json.RawMessage(data) return nil } -func (d *DatasetGetResponse) String() string { +func (d *DatasetsGetResponse) String() string { if len(d._rawJSON) > 0 { if value, err := core.StringifyJSON(d._rawJSON); err == nil { return value @@ -51,24 +51,25 @@ func (d *DatasetGetResponse) String() string { return fmt.Sprintf("%#v", d) } -type DatasetIdGetResponse struct { - Dataset *Dataset `json:"dataset,omitempty"` +type DatasetsGetUsageResponse struct { + // The total number of bytes used by the organization. + OrganizationUsage *string `json:"organizationUsage,omitempty"` _rawJSON json.RawMessage } -func (d *DatasetIdGetResponse) UnmarshalJSON(data []byte) error { - type unmarshaler DatasetIdGetResponse +func (d *DatasetsGetUsageResponse) UnmarshalJSON(data []byte) error { + type unmarshaler DatasetsGetUsageResponse var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *d = DatasetIdGetResponse(value) + *d = DatasetsGetUsageResponse(value) d._rawJSON = json.RawMessage(data) return nil } -func (d *DatasetIdGetResponse) String() string { +func (d *DatasetsGetUsageResponse) String() string { if len(d._rawJSON) > 0 { if value, err := core.StringifyJSON(d._rawJSON); err == nil { return value @@ -80,25 +81,24 @@ func (d *DatasetIdGetResponse) String() string { return fmt.Sprintf("%#v", d) } -type DatasetUsageGetResponse struct { - // The total number of bytes used by the organization. - OrganizationUsage *string `json:"organizationUsage,omitempty"` +type DatasetsListResponse struct { + Datasets []*Dataset `json:"datasets,omitempty"` _rawJSON json.RawMessage } -func (d *DatasetUsageGetResponse) UnmarshalJSON(data []byte) error { - type unmarshaler DatasetUsageGetResponse +func (d *DatasetsListResponse) UnmarshalJSON(data []byte) error { + type unmarshaler DatasetsListResponse var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *d = DatasetUsageGetResponse(value) + *d = DatasetsListResponse(value) d._rawJSON = json.RawMessage(data) return nil } -func (d *DatasetUsageGetResponse) String() string { +func (d *DatasetsListResponse) String() string { if len(d._rawJSON) > 0 { if value, err := core.StringifyJSON(d._rawJSON); err == nil { return value diff --git a/dataset/client.go b/datasets/client.go similarity index 84% rename from dataset/client.go rename to datasets/client.go index 1430ff5..55c53d1 100644 --- a/dataset/client.go +++ b/datasets/client.go @@ -1,6 +1,6 @@ // This file was auto-generated by Fern from our API Definition. -package dataset +package datasets import ( context "context" @@ -30,7 +30,7 @@ func NewClient(opts ...core.ClientOption) *Client { } } -func (c *Client) Get(ctx context.Context, request *v2.DatasetGetRequest) (*v2.DatasetGetResponse, error) { +func (c *Client) List(ctx context.Context, request *v2.DatasetsListRequest) (*v2.DatasetsListResponse, error) { baseURL := "https://api.cohere.ai" if c.baseURL != "" { baseURL = c.baseURL @@ -57,7 +57,7 @@ func (c *Client) Get(ctx context.Context, request *v2.DatasetGetRequest) (*v2.Da endpointURL += "?" + queryParams.Encode() } - var response *v2.DatasetGetResponse + var response *v2.DatasetsListResponse if err := c.caller.Call( ctx, &core.CallParams{ @@ -72,14 +72,14 @@ func (c *Client) Get(ctx context.Context, request *v2.DatasetGetRequest) (*v2.Da return response, nil } -func (c *Client) UsageGet(ctx context.Context) (*v2.DatasetUsageGetResponse, error) { +func (c *Client) GetUsage(ctx context.Context) (*v2.DatasetsGetUsageResponse, error) { baseURL := "https://api.cohere.ai" if c.baseURL != "" { baseURL = c.baseURL } endpointURL := baseURL + "/" + "v1/dataset/usage" - var response *v2.DatasetUsageGetResponse + var response *v2.DatasetsGetUsageResponse if err := c.caller.Call( ctx, &core.CallParams{ @@ -94,14 +94,14 @@ func (c *Client) UsageGet(ctx context.Context) (*v2.DatasetUsageGetResponse, err return response, nil } -func (c *Client) IdGet(ctx context.Context, id string) (*v2.DatasetIdGetResponse, error) { +func (c *Client) Get(ctx context.Context, id string) (*v2.DatasetsGetResponse, error) { baseURL := "https://api.cohere.ai" if c.baseURL != "" { baseURL = c.baseURL } endpointURL := fmt.Sprintf(baseURL+"/"+"v1/dataset/%v", id) - var response *v2.DatasetIdGetResponse + var response *v2.DatasetsGetResponse if err := c.caller.Call( ctx, &core.CallParams{ @@ -116,7 +116,7 @@ func (c *Client) IdGet(ctx context.Context, id string) (*v2.DatasetIdGetResponse return response, nil } -func (c *Client) IdDelete(ctx context.Context, id string) (map[string]interface{}, error) { +func (c *Client) Delete(ctx context.Context, id string) (map[string]interface{}, error) { baseURL := "https://api.cohere.ai" if c.baseURL != "" { baseURL = c.baseURL diff --git a/doc.go b/doc.go index 107f1cf..0801c52 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ // This file was auto-generated by Fern from our API Definition. -// Dataset API +// Connectors API package api diff --git a/errors.go b/errors.go index 5ac2826..a49084c 100644 --- a/errors.go +++ b/errors.go @@ -30,6 +30,29 @@ func (b *BadRequestError) Unwrap() error { return b.APIError } +type ForbiddenError struct { + *core.APIError + Body interface{} +} + +func (f *ForbiddenError) UnmarshalJSON(data []byte) error { + var body interface{} + if err := json.Unmarshal(data, &body); err != nil { + return err + } + f.StatusCode = 403 + f.Body = body + return nil +} + +func (f *ForbiddenError) MarshalJSON() ([]byte, error) { + return json.Marshal(f.Body) +} + +func (f *ForbiddenError) Unwrap() error { + return f.APIError +} + type InternalServerError struct { *core.APIError Body interface{} @@ -52,3 +75,26 @@ func (i *InternalServerError) MarshalJSON() ([]byte, error) { func (i *InternalServerError) Unwrap() error { return i.APIError } + +type NotFoundError struct { + *core.APIError + Body interface{} +} + +func (n *NotFoundError) UnmarshalJSON(data []byte) error { + var body interface{} + if err := json.Unmarshal(data, &body); err != nil { + return err + } + n.StatusCode = 404 + n.Body = body + return nil +} + +func (n *NotFoundError) MarshalJSON() ([]byte, error) { + return json.Marshal(n.Body) +} + +func (n *NotFoundError) Unwrap() error { + return n.APIError +} diff --git a/types.go b/types.go index ad271de..fbf5c84 100644 --- a/types.go +++ b/types.go @@ -1261,6 +1261,121 @@ func (c *Cluster) String() string { return fmt.Sprintf("%#v", c) } +// A connector allows you to integrate data sources with the '/chat' endpoint to create grounded generations with citations to the data source. +// documents to help answer users. +type Connector struct { + // The unique identifier of the connector (used in both `/connectors` & `/chat` endpoints). + // This is automatically created from the name of the connector upon registration. + Id string `json:"id"` + // The organization to which this connector belongs. This is automatically set to + // the organization of the user who created the connector. + OrganizationId *string `json:"organizationId,omitempty"` + // A human-readable name for the connector. + Name string `json:"name"` + // A description of the connector. + Description *string `json:"description,omitempty"` + // The URL of the connector that will be used to search for documents. + Url *string `json:"url,omitempty"` + // The UTC time at which the connector was created. + CreatedAt time.Time `json:"createdAt"` + // The UTC time at which the connector was last updated. + UpdatedAt time.Time `json:"updatedAt"` + // A list of fields to exclude from the prompt (fields remain in the document). + Excludes []string `json:"excludes,omitempty"` + // The type of authentication/authorization used by the connector. Possible values: [oauth, service_auth] + AuthType *string `json:"authType,omitempty"` + // The OAuth 2.0 configuration for the connector. + Oauth *ConnectorOAuth `json:"oauth,omitempty"` + // The OAuth status for the user making the request. One of ["valid", "expired", ""]. Empty string (field is omitted) means the user has not authorized the connector yet. + AuthStatus *ConnectorAuthStatus `json:"authStatus,omitempty"` + // Whether the connector is active or not. + Active *bool `json:"active,omitempty"` + // Whether a chat request should continue or not if the request to this connector fails. + ContinueOnFailure *bool `json:"continueOnFailure,omitempty"` + + _rawJSON json.RawMessage +} + +func (c *Connector) UnmarshalJSON(data []byte) error { + type unmarshaler Connector + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = Connector(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *Connector) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +// The OAuth status for the user making the request. One of ["valid", "expired", ""]. Empty string (field is omitted) means the user has not authorized the connector yet. +type ConnectorAuthStatus string + +const ( + ConnectorAuthStatusValid ConnectorAuthStatus = "valid" + ConnectorAuthStatusExpired ConnectorAuthStatus = "expired" +) + +func NewConnectorAuthStatusFromString(s string) (ConnectorAuthStatus, error) { + switch s { + case "valid": + return ConnectorAuthStatusValid, nil + case "expired": + return ConnectorAuthStatusExpired, nil + } + var t ConnectorAuthStatus + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (c ConnectorAuthStatus) Ptr() *ConnectorAuthStatus { + return &c +} + +type ConnectorOAuth struct { + // The OAuth 2.0 /authorize endpoint to use when users authorize the connector. + AuthorizeUrl *string `json:"authorizeUrl,omitempty"` + // The OAuth 2.0 /token endpoint to use when users authorize the connector. + TokenUrl *string `json:"tokenUrl,omitempty"` + // The OAuth scopes to request when users authorize the connector. + Scope *string `json:"scope,omitempty"` + + _rawJSON json.RawMessage +} + +func (c *ConnectorOAuth) UnmarshalJSON(data []byte) error { + type unmarshaler ConnectorOAuth + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ConnectorOAuth(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectorOAuth) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + // Response for creating a cluster job. type CreateClusterJobResponse struct { JobId string `json:"job_id"`