diff --git a/client/client.go b/client/client.go index a6c9a4c..1bc0110 100644 --- a/client/client.go +++ b/client/client.go @@ -55,7 +55,7 @@ func NewClient(opts ...option.RequestOption) *Client { } // Generates a text response to a user message. -// To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). +// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). func (c *Client) ChatStream( ctx context.Context, request *v2.ChatStreamRequest, @@ -70,7 +70,7 @@ func (c *Client) ChatStream( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "chat" + endpointURL := baseURL + "/chat" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -82,6 +82,41 @@ func (c *Client) ChatStream( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -89,6 +124,41 @@ func (c *Client) ChatStream( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -109,7 +179,7 @@ func (c *Client) ChatStream( } // Generates a text response to a user message. -// To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). +// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). func (c *Client) Chat( ctx context.Context, request *v2.ChatRequest, @@ -124,7 +194,7 @@ func (c *Client) Chat( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "chat" + endpointURL := baseURL + "/chat" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -136,6 +206,41 @@ func (c *Client) Chat( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -143,6 +248,41 @@ func (c *Client) Chat( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -185,7 +325,7 @@ func (c *Client) GenerateStream( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "generate" + endpointURL := baseURL + "/generate" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -204,6 +344,34 @@ func (c *Client) GenerateStream( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -211,6 +379,13 @@ func (c *Client) GenerateStream( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -218,6 +393,27 @@ func (c *Client) GenerateStream( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -256,7 +452,7 @@ func (c *Client) Generate( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "generate" + endpointURL := baseURL + "/generate" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -275,6 +471,34 @@ func (c *Client) Generate( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -282,6 +506,13 @@ func (c *Client) Generate( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -289,6 +520,27 @@ func (c *Client) Generate( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -331,7 +583,7 @@ func (c *Client) Embed( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "embed" + endpointURL := baseURL + "/embed" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -350,6 +602,34 @@ func (c *Client) Embed( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -357,6 +637,13 @@ func (c *Client) Embed( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -364,6 +651,27 @@ func (c *Client) Embed( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -402,7 +710,7 @@ func (c *Client) Rerank( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "rerank" + endpointURL := baseURL + "/rerank" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -414,6 +722,41 @@ func (c *Client) Rerank( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -421,7 +764,42 @@ func (c *Client) Rerank( return apiError } return value - } + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + } return apiError } @@ -460,7 +838,7 @@ func (c *Client) Classify( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "classify" + endpointURL := baseURL + "/classify" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -479,6 +857,34 @@ func (c *Client) Classify( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -486,6 +892,13 @@ func (c *Client) Classify( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -493,6 +906,27 @@ func (c *Client) Classify( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -535,7 +969,7 @@ func (c *Client) Summarize( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "summarize" + endpointURL := baseURL + "/summarize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -547,6 +981,41 @@ func (c *Client) Summarize( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -554,6 +1023,41 @@ func (c *Client) Summarize( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -592,7 +1096,7 @@ func (c *Client) Tokenize( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "tokenize" + endpointURL := baseURL + "/tokenize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -611,6 +1115,34 @@ func (c *Client) Tokenize( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -618,6 +1150,13 @@ func (c *Client) Tokenize( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -625,6 +1164,27 @@ func (c *Client) Tokenize( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -663,7 +1223,7 @@ func (c *Client) Detokenize( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "detokenize" + endpointURL := baseURL + "/detokenize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -675,6 +1235,41 @@ func (c *Client) Detokenize( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -682,6 +1277,41 @@ func (c *Client) Detokenize( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -719,7 +1349,7 @@ func (c *Client) CheckApiKey( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "check-api-key" + endpointURL := baseURL + "/check-api-key" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -731,6 +1361,41 @@ func (c *Client) CheckApiKey( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -738,6 +1403,41 @@ func (c *Client) CheckApiKey( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } diff --git a/connectors.go b/connectors.go index 1e98e69..c7423c4 100644 --- a/connectors.go +++ b/connectors.go @@ -4,21 +4,21 @@ package api type CreateConnectorRequest struct { // A human-readable name for the connector. - Name string `json:"name" url:"name"` + Name string `json:"name" url:"-"` // A description of the connector. - Description *string `json:"description,omitempty" url:"description,omitempty"` + Description *string `json:"description,omitempty" url:"-"` // The URL of the connector that will be used to search for documents. - Url string `json:"url" url:"url"` + Url string `json:"url" url:"-"` // A list of fields to exclude from the prompt (fields remain in the document). - Excludes []string `json:"excludes,omitempty" url:"excludes,omitempty"` + Excludes []string `json:"excludes,omitempty" url:"-"` // The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. - Oauth *CreateConnectorOAuth `json:"oauth,omitempty" url:"oauth,omitempty"` + Oauth *CreateConnectorOAuth `json:"oauth,omitempty" url:"-"` // Whether the connector is active or not. - Active *bool `json:"active,omitempty" url:"active,omitempty"` + Active *bool `json:"active,omitempty" url:"-"` // Whether a chat request should continue or not if the request to this connector fails. - ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"continue_on_failure,omitempty"` + ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"-"` // The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. - ServiceAuth *CreateConnectorServiceAuth `json:"service_auth,omitempty" url:"service_auth,omitempty"` + ServiceAuth *CreateConnectorServiceAuth `json:"service_auth,omitempty" url:"-"` } type ConnectorsListRequest struct { @@ -35,15 +35,15 @@ type ConnectorsOAuthAuthorizeRequest struct { type UpdateConnectorRequest struct { // A human-readable name for the connector. - Name *string `json:"name,omitempty" url:"name,omitempty"` + Name *string `json:"name,omitempty" url:"-"` // The URL of the connector that will be used to search for documents. - Url *string `json:"url,omitempty" url:"url,omitempty"` + Url *string `json:"url,omitempty" url:"-"` // A list of fields to exclude from the prompt (fields remain in the document). - Excludes []string `json:"excludes,omitempty" url:"excludes,omitempty"` + Excludes []string `json:"excludes,omitempty" url:"-"` // The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. - Oauth *CreateConnectorOAuth `json:"oauth,omitempty" url:"oauth,omitempty"` - Active *bool `json:"active,omitempty" url:"active,omitempty"` - ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"continue_on_failure,omitempty"` + Oauth *CreateConnectorOAuth `json:"oauth,omitempty" url:"-"` + Active *bool `json:"active,omitempty" url:"-"` + ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"-"` // The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. - ServiceAuth *CreateConnectorServiceAuth `json:"service_auth,omitempty" url:"service_auth,omitempty"` + ServiceAuth *CreateConnectorServiceAuth `json:"service_auth,omitempty" url:"-"` } diff --git a/connectors/client.go b/connectors/client.go index 82ea6c8..dce1176 100644 --- a/connectors/client.go +++ b/connectors/client.go @@ -7,7 +7,6 @@ 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" @@ -54,7 +53,7 @@ func (c *Client) List( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "connectors" + endpointURL := baseURL + "/connectors" queryParams, err := core.QueryValues(request) if err != nil { @@ -81,6 +80,34 @@ func (c *Client) List( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -88,6 +115,13 @@ func (c *Client) List( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -95,6 +129,27 @@ func (c *Client) List( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -132,7 +187,7 @@ func (c *Client) Create( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "connectors" + endpointURL := baseURL + "/connectors" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -151,6 +206,13 @@ func (c *Client) Create( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 403: value := new(v2.ForbiddenError) value.APIError = apiError @@ -158,6 +220,20 @@ func (c *Client) Create( 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -165,6 +241,13 @@ func (c *Client) Create( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -172,6 +255,27 @@ func (c *Client) Create( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -211,7 +315,7 @@ func (c *Client) Get( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -230,6 +334,20 @@ func (c *Client) Get( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 @@ -237,6 +355,13 @@ func (c *Client) Get( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -244,6 +369,13 @@ func (c *Client) Get( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -251,6 +383,27 @@ func (c *Client) Get( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -289,7 +442,7 @@ func (c *Client) Delete( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -308,6 +461,13 @@ func (c *Client) Delete( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 403: value := new(v2.ForbiddenError) value.APIError = apiError @@ -322,6 +482,13 @@ func (c *Client) Delete( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -329,6 +496,13 @@ func (c *Client) Delete( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -336,6 +510,27 @@ func (c *Client) Delete( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -375,7 +570,7 @@ func (c *Client) Update( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -394,6 +589,13 @@ func (c *Client) Update( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 403: value := new(v2.ForbiddenError) value.APIError = apiError @@ -408,6 +610,13 @@ func (c *Client) Update( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -415,6 +624,13 @@ func (c *Client) Update( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -422,6 +638,27 @@ func (c *Client) Update( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -462,7 +699,7 @@ func (c *Client) OAuthAuthorize( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"connectors/%v/oauth/authorize", id) + endpointURL := core.EncodeURL(baseURL+"/connectors/%v/oauth/authorize", id) queryParams, err := core.QueryValues(request) if err != nil { @@ -489,6 +726,20 @@ func (c *Client) OAuthAuthorize( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 @@ -496,6 +747,13 @@ func (c *Client) OAuthAuthorize( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -503,6 +761,13 @@ func (c *Client) OAuthAuthorize( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -510,6 +775,27 @@ func (c *Client) OAuthAuthorize( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } diff --git a/core/core.go b/core/core.go index 5277d13..3e28f90 100644 --- a/core/core.go +++ b/core/core.go @@ -9,6 +9,7 @@ import ( "io" "mime/multipart" "net/http" + "net/url" ) const ( @@ -22,6 +23,16 @@ type HTTPClient interface { Do(*http.Request) (*http.Response, error) } +// EncodeURL encodes the given arguments into the URL, escaping +// values as needed. +func EncodeURL(urlFormat string, args ...interface{}) string { + escapedArgs := make([]interface{}, 0, len(args)) + for _, arg := range args { + escapedArgs = append(escapedArgs, url.PathEscape(fmt.Sprintf("%v", arg))) + } + return fmt.Sprintf(urlFormat, escapedArgs...) +} + // MergeHeaders merges the given headers together, where the right // takes precedence over the left. func MergeHeaders(left, right http.Header) http.Header { diff --git a/core/extra_properties.go b/core/extra_properties.go new file mode 100644 index 0000000..a6af3e1 --- /dev/null +++ b/core/extra_properties.go @@ -0,0 +1,141 @@ +package core + +import ( + "bytes" + "encoding/json" + "fmt" + "reflect" + "strings" +) + +// MarshalJSONWithExtraProperty marshals the given value to JSON, including the extra property. +func MarshalJSONWithExtraProperty(marshaler interface{}, key string, value interface{}) ([]byte, error) { + return MarshalJSONWithExtraProperties(marshaler, map[string]interface{}{key: value}) +} + +// MarshalJSONWithExtraProperties marshals the given value to JSON, including any extra properties. +func MarshalJSONWithExtraProperties(marshaler interface{}, extraProperties map[string]interface{}) ([]byte, error) { + bytes, err := json.Marshal(marshaler) + if err != nil { + return nil, err + } + if len(extraProperties) == 0 { + return bytes, nil + } + keys, err := getKeys(marshaler) + if err != nil { + return nil, err + } + for _, key := range keys { + if _, ok := extraProperties[key]; ok { + return nil, fmt.Errorf("cannot add extra property %q because it is already defined on the type", key) + } + } + extraBytes, err := json.Marshal(extraProperties) + if err != nil { + return nil, err + } + if isEmptyJSON(bytes) { + if isEmptyJSON(extraBytes) { + return bytes, nil + } + return extraBytes, nil + } + result := bytes[:len(bytes)-1] + result = append(result, ',') + result = append(result, extraBytes[1:len(extraBytes)-1]...) + result = append(result, '}') + return result, nil +} + +// ExtractExtraProperties extracts any extra properties from the given value. +func ExtractExtraProperties(bytes []byte, value interface{}, exclude ...string) (map[string]interface{}, error) { + val := reflect.ValueOf(value) + for val.Kind() == reflect.Ptr { + if val.IsNil() { + return nil, fmt.Errorf("value must be non-nil to extract extra properties") + } + val = val.Elem() + } + if err := json.Unmarshal(bytes, &value); err != nil { + return nil, err + } + var extraProperties map[string]interface{} + if err := json.Unmarshal(bytes, &extraProperties); err != nil { + return nil, err + } + for i := 0; i < val.Type().NumField(); i++ { + key := jsonKey(val.Type().Field(i)) + if key == "" || key == "-" { + continue + } + delete(extraProperties, key) + } + for _, key := range exclude { + delete(extraProperties, key) + } + if len(extraProperties) == 0 { + return nil, nil + } + return extraProperties, nil +} + +// getKeys returns the keys associated with the given value. The value must be a +// a struct or a map with string keys. +func getKeys(value interface{}) ([]string, error) { + val := reflect.ValueOf(value) + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + if !val.IsValid() { + return nil, nil + } + switch val.Kind() { + case reflect.Struct: + return getKeysForStructType(val.Type()), nil + case reflect.Map: + var keys []string + if val.Type().Key().Kind() != reflect.String { + return nil, fmt.Errorf("cannot extract keys from %T; only structs and maps with string keys are supported", value) + } + for _, key := range val.MapKeys() { + keys = append(keys, key.String()) + } + return keys, nil + default: + return nil, fmt.Errorf("cannot extract keys from %T; only structs and maps with string keys are supported", value) + } +} + +// getKeysForStructType returns all the keys associated with the given struct type, +// visiting embedded fields recursively. +func getKeysForStructType(structType reflect.Type) []string { + if structType.Kind() == reflect.Pointer { + structType = structType.Elem() + } + if structType.Kind() != reflect.Struct { + return nil + } + var keys []string + for i := 0; i < structType.NumField(); i++ { + field := structType.Field(i) + if field.Anonymous { + keys = append(keys, getKeysForStructType(field.Type)...) + continue + } + keys = append(keys, jsonKey(field)) + } + return keys +} + +// jsonKey returns the JSON key from the struct tag of the given field, +// excluding the omitempty flag (if any). +func jsonKey(field reflect.StructField) string { + return strings.TrimSuffix(field.Tag.Get("json"), ",omitempty") +} + +// isEmptyJSON returns true if the given data is empty, the empty JSON object, or +// an explicit null. +func isEmptyJSON(data []byte) bool { + return len(data) <= 2 || bytes.Equal(data, []byte("null")) +} diff --git a/core/extra_properties_test.go b/core/extra_properties_test.go new file mode 100644 index 0000000..dc66fcc --- /dev/null +++ b/core/extra_properties_test.go @@ -0,0 +1,228 @@ +package core + +import ( + "encoding/json" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type testMarshaler struct { + Name string `json:"name"` + BirthDate time.Time `json:"birthDate"` + CreatedAt time.Time `json:"created_at"` +} + +func (t *testMarshaler) MarshalJSON() ([]byte, error) { + type embed testMarshaler + var marshaler = struct { + embed + BirthDate string `json:"birthDate"` + CreatedAt string `json:"created_at"` + }{ + embed: embed(*t), + BirthDate: t.BirthDate.Format("2006-01-02"), + CreatedAt: t.CreatedAt.Format(time.RFC3339), + } + return MarshalJSONWithExtraProperty(marshaler, "type", "test") +} + +func TestMarshalJSONWithExtraProperties(t *testing.T) { + tests := []struct { + desc string + giveMarshaler interface{} + giveExtraProperties map[string]interface{} + wantBytes []byte + wantError string + }{ + { + desc: "invalid type", + giveMarshaler: []string{"invalid"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot extract keys from []string; only structs and maps with string keys are supported`, + }, + { + desc: "invalid key type", + giveMarshaler: map[int]interface{}{42: "value"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot extract keys from map[int]interface {}; only structs and maps with string keys are supported`, + }, + { + desc: "invalid map overwrite", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot add extra property "key" because it is already defined on the type`, + }, + { + desc: "invalid struct overwrite", + giveMarshaler: new(testMarshaler), + giveExtraProperties: map[string]interface{}{"birthDate": "2000-01-01"}, + wantError: `cannot add extra property "birthDate" because it is already defined on the type`, + }, + { + desc: "invalid struct overwrite embedded type", + giveMarshaler: new(testMarshaler), + giveExtraProperties: map[string]interface{}{"name": "bob"}, + wantError: `cannot add extra property "name" because it is already defined on the type`, + }, + { + desc: "nil", + giveMarshaler: nil, + giveExtraProperties: nil, + wantBytes: []byte(`null`), + }, + { + desc: "empty", + giveMarshaler: map[string]interface{}{}, + giveExtraProperties: map[string]interface{}{}, + wantBytes: []byte(`{}`), + }, + { + desc: "no extra properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{}, + wantBytes: []byte(`{"key":"value"}`), + }, + { + desc: "only extra properties", + giveMarshaler: map[string]interface{}{}, + giveExtraProperties: map[string]interface{}{"key": "value"}, + wantBytes: []byte(`{"key":"value"}`), + }, + { + desc: "single extra property", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"extra": "property"}, + wantBytes: []byte(`{"key":"value","extra":"property"}`), + }, + { + desc: "multiple extra properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"one": 1, "two": 2}, + wantBytes: []byte(`{"key":"value","one":1,"two":2}`), + }, + { + desc: "nested properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{ + "user": map[string]interface{}{ + "age": 42, + "name": "alice", + }, + }, + wantBytes: []byte(`{"key":"value","user":{"age":42,"name":"alice"}}`), + }, + { + desc: "multiple nested properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{ + "metadata": map[string]interface{}{ + "ip": "127.0.0.1", + }, + "user": map[string]interface{}{ + "age": 42, + "name": "alice", + }, + }, + wantBytes: []byte(`{"key":"value","metadata":{"ip":"127.0.0.1"},"user":{"age":42,"name":"alice"}}`), + }, + { + desc: "custom marshaler", + giveMarshaler: &testMarshaler{ + Name: "alice", + BirthDate: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), + CreatedAt: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), + }, + giveExtraProperties: map[string]interface{}{ + "extra": "property", + }, + wantBytes: []byte(`{"name":"alice","birthDate":"2000-01-01","created_at":"2024-01-01T00:00:00Z","type":"test","extra":"property"}`), + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + bytes, err := MarshalJSONWithExtraProperties(tt.giveMarshaler, tt.giveExtraProperties) + if tt.wantError != "" { + require.EqualError(t, err, tt.wantError) + assert.Nil(t, tt.wantBytes) + return + } + require.NoError(t, err) + assert.Equal(t, tt.wantBytes, bytes) + + value := make(map[string]interface{}) + require.NoError(t, json.Unmarshal(bytes, &value)) + }) + } +} + +func TestExtractExtraProperties(t *testing.T) { + t.Run("none", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice"}`), value) + require.NoError(t, err) + assert.Nil(t, extraProperties) + }) + + t.Run("non-nil pointer", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("nil pointer", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + var value *user + _, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + assert.EqualError(t, err, "value must be non-nil to extract extra properties") + }) + + t.Run("non-zero value", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("zero value", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + var value user + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("exclude", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value, "age") + require.NoError(t, err) + assert.Nil(t, extraProperties) + }) +} diff --git a/core/request_option.go b/core/request_option.go index ac019e0..d495892 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -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.8.1") + headers.Set("X-Fern-SDK-Version", "v2.8.3") return headers } diff --git a/datasets.go b/datasets.go index 7c5d23f..7e55fbe 100644 --- a/datasets.go +++ b/datasets.go @@ -49,7 +49,12 @@ type DatasetsCreateResponse struct { // The dataset ID Id *string `json:"id,omitempty" url:"id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetsCreateResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetsCreateResponse) UnmarshalJSON(data []byte) error { @@ -59,6 +64,13 @@ func (d *DatasetsCreateResponse) UnmarshalJSON(data []byte) error { return err } *d = DatasetsCreateResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -78,7 +90,12 @@ func (d *DatasetsCreateResponse) String() string { type DatasetsGetResponse struct { Dataset *Dataset `json:"dataset,omitempty" url:"dataset,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetsGetResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetsGetResponse) UnmarshalJSON(data []byte) error { @@ -88,6 +105,13 @@ func (d *DatasetsGetResponse) UnmarshalJSON(data []byte) error { return err } *d = DatasetsGetResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -108,7 +132,12 @@ type DatasetsGetUsageResponse struct { // The total number of bytes used by the organization. OrganizationUsage *int64 `json:"organization_usage,omitempty" url:"organization_usage,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetsGetUsageResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetsGetUsageResponse) UnmarshalJSON(data []byte) error { @@ -118,6 +147,13 @@ func (d *DatasetsGetUsageResponse) UnmarshalJSON(data []byte) error { return err } *d = DatasetsGetUsageResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -137,7 +173,12 @@ func (d *DatasetsGetUsageResponse) String() string { type DatasetsListResponse struct { Datasets []*Dataset `json:"datasets,omitempty" url:"datasets,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetsListResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetsListResponse) UnmarshalJSON(data []byte) error { @@ -147,6 +188,13 @@ func (d *DatasetsListResponse) UnmarshalJSON(data []byte) error { return err } *d = DatasetsListResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } diff --git a/datasets/client.go b/datasets/client.go index 0673db4..9b57ef8 100644 --- a/datasets/client.go +++ b/datasets/client.go @@ -7,7 +7,6 @@ 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" @@ -55,7 +54,7 @@ func (c *Client) List( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "datasets" + endpointURL := baseURL + "/datasets" queryParams, err := core.QueryValues(request) if err != nil { @@ -75,6 +74,41 @@ func (c *Client) List( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -82,6 +116,41 @@ func (c *Client) List( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -121,7 +190,7 @@ func (c *Client) Create( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "datasets" + endpointURL := baseURL + "/datasets" queryParams, err := core.QueryValues(request) if err != nil { @@ -141,6 +210,41 @@ func (c *Client) Create( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -148,6 +252,41 @@ func (c *Client) Create( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -216,7 +355,7 @@ func (c *Client) GetUsage( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "datasets/usage" + endpointURL := baseURL + "/datasets/usage" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -228,6 +367,41 @@ func (c *Client) GetUsage( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -235,6 +409,41 @@ func (c *Client) GetUsage( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -272,7 +481,7 @@ func (c *Client) Get( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"datasets/%v", id) + endpointURL := core.EncodeURL(baseURL+"/datasets/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -284,6 +493,41 @@ func (c *Client) Get( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -291,6 +535,41 @@ func (c *Client) Get( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -328,7 +607,7 @@ func (c *Client) Delete( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"datasets/%v", id) + endpointURL := core.EncodeURL(baseURL+"/datasets/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -340,6 +619,41 @@ func (c *Client) Delete( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -347,6 +661,41 @@ func (c *Client) Delete( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } diff --git a/embed_jobs.go b/embed_jobs.go index 7d1d3ca..297e6d7 100644 --- a/embed_jobs.go +++ b/embed_jobs.go @@ -15,12 +15,12 @@ type CreateEmbedJobRequest struct { // - `embed-multilingual-v3.0` : 1024 // - `embed-english-light-v3.0` : 384 // - `embed-multilingual-light-v3.0` : 384 - Model string `json:"model" url:"model"` + Model string `json:"model" url:"-"` // ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated` - DatasetId string `json:"dataset_id" url:"dataset_id"` - InputType EmbedInputType `json:"input_type" url:"input_type"` + DatasetId string `json:"dataset_id" url:"-"` + InputType EmbedInputType `json:"input_type" url:"-"` // The name of the embed job. - Name *string `json:"name,omitempty" url:"name,omitempty"` + Name *string `json:"name,omitempty" url:"-"` // 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. @@ -28,11 +28,11 @@ type CreateEmbedJobRequest struct { // * `"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"` + EmbeddingTypes []EmbeddingType `json:"embedding_types,omitempty" url:"-"` // 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. - Truncate *CreateEmbedJobRequestTruncate `json:"truncate,omitempty" url:"truncate,omitempty"` + Truncate *CreateEmbedJobRequestTruncate `json:"truncate,omitempty" url:"-"` } // One of `START|END` to specify how the API will handle inputs longer than the maximum token length. diff --git a/embedjobs/client.go b/embedjobs/client.go index 43f581a..ee60a05 100644 --- a/embedjobs/client.go +++ b/embedjobs/client.go @@ -7,7 +7,6 @@ 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" @@ -53,7 +52,7 @@ func (c *Client) List( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "embed-jobs" + endpointURL := baseURL + "/embed-jobs" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -72,6 +71,34 @@ func (c *Client) List( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -79,6 +106,13 @@ func (c *Client) List( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -86,6 +120,27 @@ func (c *Client) List( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -123,7 +178,7 @@ func (c *Client) Create( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "embed-jobs" + endpointURL := baseURL + "/embed-jobs" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -142,6 +197,34 @@ func (c *Client) Create( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -149,6 +232,13 @@ func (c *Client) Create( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -156,6 +246,27 @@ func (c *Client) Create( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -195,7 +306,7 @@ func (c *Client) Get( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"embed-jobs/%v", id) + endpointURL := core.EncodeURL(baseURL+"/embed-jobs/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -214,6 +325,20 @@ func (c *Client) Get( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 @@ -221,6 +346,13 @@ func (c *Client) Get( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -228,6 +360,13 @@ func (c *Client) Get( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -235,6 +374,27 @@ func (c *Client) Get( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -273,7 +433,7 @@ func (c *Client) Cancel( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"embed-jobs/%v/cancel", id) + endpointURL := core.EncodeURL(baseURL+"/embed-jobs/%v/cancel", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -292,6 +452,20 @@ func (c *Client) Cancel( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 @@ -299,6 +473,13 @@ func (c *Client) Cancel( return apiError } return value + case 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -306,6 +487,13 @@ func (c *Client) Cancel( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -313,6 +501,27 @@ func (c *Client) Cancel( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } diff --git a/errors.go b/errors.go index 01d9f9a..42e07bd 100644 --- a/errors.go +++ b/errors.go @@ -5,7 +5,6 @@ package api import ( json "encoding/json" core "github.com/cohere-ai/cohere-go/v2/core" - finetuning "github.com/cohere-ai/cohere-go/v2/finetuning" ) type BadRequestError struct { @@ -31,6 +30,30 @@ func (b *BadRequestError) Unwrap() error { return b.APIError } +// This error is returned when a request is cancelled by the user. +type ClientClosedRequestError struct { + *core.APIError + Body *ClientClosedRequestErrorBody +} + +func (c *ClientClosedRequestError) UnmarshalJSON(data []byte) error { + var body *ClientClosedRequestErrorBody + if err := json.Unmarshal(data, &body); err != nil { + return err + } + c.StatusCode = 499 + c.Body = body + return nil +} + +func (c *ClientClosedRequestError) MarshalJSON() ([]byte, error) { + return json.Marshal(c.Body) +} + +func (c *ClientClosedRequestError) Unwrap() error { + return c.APIError +} + type ForbiddenError struct { *core.APIError Body interface{} @@ -54,6 +77,31 @@ func (f *ForbiddenError) Unwrap() error { return f.APIError } +// This error is returned when a request to the server times out. This could be due to: +// - An internal services taking too long to respond +type GatewayTimeoutError struct { + *core.APIError + Body *GatewayTimeoutErrorBody +} + +func (g *GatewayTimeoutError) UnmarshalJSON(data []byte) error { + var body *GatewayTimeoutErrorBody + if err := json.Unmarshal(data, &body); err != nil { + return err + } + g.StatusCode = 504 + g.Body = body + return nil +} + +func (g *GatewayTimeoutError) MarshalJSON() ([]byte, error) { + return json.Marshal(g.Body) +} + +func (g *GatewayTimeoutError) Unwrap() error { + return g.APIError +} + type InternalServerError struct { *core.APIError Body interface{} @@ -100,14 +148,37 @@ func (n *NotFoundError) Unwrap() error { return n.APIError } -// Status Service Unavailable +// This error is returned when the requested feature is not implemented. +type NotImplementedError struct { + *core.APIError + Body *NotImplementedErrorBody +} + +func (n *NotImplementedError) UnmarshalJSON(data []byte) error { + var body *NotImplementedErrorBody + if err := json.Unmarshal(data, &body); err != nil { + return err + } + n.StatusCode = 501 + n.Body = body + return nil +} + +func (n *NotImplementedError) MarshalJSON() ([]byte, error) { + return json.Marshal(n.Body) +} + +func (n *NotImplementedError) Unwrap() error { + return n.APIError +} + type ServiceUnavailableError struct { *core.APIError - Body *finetuning.Error + Body interface{} } func (s *ServiceUnavailableError) UnmarshalJSON(data []byte) error { - var body *finetuning.Error + var body interface{} if err := json.Unmarshal(data, &body); err != nil { return err } @@ -148,14 +219,13 @@ func (t *TooManyRequestsError) Unwrap() error { return t.APIError } -// Unauthorized type UnauthorizedError struct { *core.APIError - Body *finetuning.Error + Body interface{} } func (u *UnauthorizedError) UnmarshalJSON(data []byte) error { - var body *finetuning.Error + var body interface{} if err := json.Unmarshal(data, &body); err != nil { return err } @@ -171,3 +241,30 @@ func (u *UnauthorizedError) MarshalJSON() ([]byte, error) { func (u *UnauthorizedError) Unwrap() error { return u.APIError } + +// This error is returned when the request is not well formed. This could be because: +// - JSON is invalid +// - The request is missing required fields +// - The request contains an invalid combination of fields +type UnprocessableEntityError struct { + *core.APIError + Body *UnprocessableEntityErrorBody +} + +func (u *UnprocessableEntityError) UnmarshalJSON(data []byte) error { + var body *UnprocessableEntityErrorBody + if err := json.Unmarshal(data, &body); err != nil { + return err + } + u.StatusCode = 422 + u.Body = body + return nil +} + +func (u *UnprocessableEntityError) MarshalJSON() ([]byte, error) { + return json.Marshal(u.Body) +} + +func (u *UnprocessableEntityError) Unwrap() error { + return u.APIError +} diff --git a/finetuning.go b/finetuning.go index 45d9215..fdacc91 100644 --- a/finetuning.go +++ b/finetuning.go @@ -48,23 +48,23 @@ type FinetuningListTrainingStepMetricsRequest struct { type FinetuningUpdateFinetunedModelRequest struct { // FinetunedModel name (e.g. `foobar`). - Name string `json:"name" url:"name"` + Name string `json:"name" url:"-"` // User ID of the creator. - CreatorId *string `json:"creator_id,omitempty" url:"creator_id,omitempty"` + CreatorId *string `json:"creator_id,omitempty" url:"-"` // Organization ID. - OrganizationId *string `json:"organization_id,omitempty" url:"organization_id,omitempty"` + OrganizationId *string `json:"organization_id,omitempty" url:"-"` // FinetunedModel settings such as dataset, hyperparameters... - Settings *finetuning.Settings `json:"settings,omitempty" url:"settings,omitempty"` + Settings *finetuning.Settings `json:"settings,omitempty" url:"-"` // Current stage in the life-cycle of the fine-tuned model. - Status *finetuning.Status `json:"status,omitempty" url:"status,omitempty"` + Status *finetuning.Status `json:"status,omitempty" url:"-"` // Creation timestamp. - CreatedAt *time.Time `json:"created_at,omitempty" url:"created_at,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty" url:"-"` // Latest update timestamp. - UpdatedAt *time.Time `json:"updated_at,omitempty" url:"updated_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty" url:"-"` // Timestamp for the completed fine-tuning. - CompletedAt *time.Time `json:"completed_at,omitempty" url:"completed_at,omitempty"` + CompletedAt *time.Time `json:"completed_at,omitempty" url:"-"` // Timestamp for the latest request to this fine-tuned model. - LastUsed *time.Time `json:"last_used,omitempty" url:"last_used,omitempty"` + LastUsed *time.Time `json:"last_used,omitempty" url:"-"` } func (f *FinetuningUpdateFinetunedModelRequest) UnmarshalJSON(data []byte) error { diff --git a/finetuning/client/client.go b/finetuning/client/client.go index 619d8a3..29aaba7 100644 --- a/finetuning/client/client.go +++ b/finetuning/client/client.go @@ -7,7 +7,6 @@ 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" finetuning "github.com/cohere-ai/cohere-go/v2/finetuning" @@ -54,7 +53,7 @@ func (c *Client) ListFinetunedModels( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "finetuning/finetuned-models" + endpointURL := baseURL + "/finetuning/finetuned-models" queryParams, err := core.QueryValues(request) if err != nil { @@ -152,7 +151,7 @@ func (c *Client) CreateFinetunedModel( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "finetuning/finetuned-models" + endpointURL := baseURL + "/finetuning/finetuned-models" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -244,7 +243,7 @@ func (c *Client) GetFinetunedModel( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -335,7 +334,7 @@ func (c *Client) DeleteFinetunedModel( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -427,7 +426,7 @@ func (c *Client) UpdateFinetunedModel( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -520,7 +519,7 @@ func (c *Client) ListEvents( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"finetuning/finetuned-models/%v/events", finetunedModelId) + endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v/events", finetunedModelId) queryParams, err := core.QueryValues(request) if err != nil { @@ -620,7 +619,7 @@ func (c *Client) ListTrainingStepMetrics( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"finetuning/finetuned-models/%v/training-step-metrics", finetunedModelId) + endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v/training-step-metrics", finetunedModelId) queryParams, err := core.QueryValues(request) if err != nil { diff --git a/finetuning/types.go b/finetuning/types.go index 17cebf2..14b1f23 100644 --- a/finetuning/types.go +++ b/finetuning/types.go @@ -20,7 +20,12 @@ type BaseModel struct { // The fine-tuning strategy. Strategy *Strategy `json:"strategy,omitempty" url:"strategy,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (b *BaseModel) GetExtraProperties() map[string]interface{} { + return b.extraProperties } func (b *BaseModel) UnmarshalJSON(data []byte) error { @@ -30,6 +35,13 @@ func (b *BaseModel) UnmarshalJSON(data []byte) error { return err } *b = BaseModel(value) + + extraProperties, err := core.ExtractExtraProperties(data, *b) + if err != nil { + return err + } + b.extraProperties = extraProperties + b._rawJSON = json.RawMessage(data) return nil } @@ -89,7 +101,12 @@ type CreateFinetunedModelResponse struct { // Information about the fine-tuned model. FinetunedModel *FinetunedModel `json:"finetuned_model,omitempty" url:"finetuned_model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CreateFinetunedModelResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CreateFinetunedModelResponse) UnmarshalJSON(data []byte) error { @@ -99,6 +116,13 @@ func (c *CreateFinetunedModelResponse) UnmarshalJSON(data []byte) error { return err } *c = CreateFinetunedModelResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -118,37 +142,6 @@ func (c *CreateFinetunedModelResponse) String() string { // Response to request to delete a fine-tuned model. type DeleteFinetunedModelResponse = map[string]interface{} -// Error is the response for any unsuccessful event. -type Error struct { - // A developer-facing error message. - Message *string `json:"message,omitempty" url:"message,omitempty"` - - _rawJSON json.RawMessage -} - -func (e *Error) UnmarshalJSON(data []byte) error { - type unmarshaler Error - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *e = Error(value) - e._rawJSON = json.RawMessage(data) - return nil -} - -func (e *Error) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(e); err == nil { - return value - } - return fmt.Sprintf("%#v", e) -} - // A change in status of a fine-tuned model. type Event struct { // ID of the user who initiated the event. Empty if initiated by the system. @@ -158,7 +151,12 @@ type Event struct { // Timestamp when the event happened. CreatedAt *time.Time `json:"created_at,omitempty" url:"created_at,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (e *Event) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *Event) UnmarshalJSON(data []byte) error { @@ -175,6 +173,12 @@ func (e *Event) UnmarshalJSON(data []byte) error { *e = Event(unmarshaler.embed) e.CreatedAt = unmarshaler.CreatedAt.TimePtr() + extraProperties, err := core.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e._rawJSON = json.RawMessage(data) return nil } @@ -226,7 +230,12 @@ type FinetunedModel struct { // read-only. Timestamp for the latest request to this fine-tuned model. LastUsed *time.Time `json:"last_used,omitempty" url:"last_used,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (f *FinetunedModel) GetExtraProperties() map[string]interface{} { + return f.extraProperties } func (f *FinetunedModel) UnmarshalJSON(data []byte) error { @@ -249,6 +258,12 @@ func (f *FinetunedModel) UnmarshalJSON(data []byte) error { f.CompletedAt = unmarshaler.CompletedAt.TimePtr() f.LastUsed = unmarshaler.LastUsed.TimePtr() + extraProperties, err := core.ExtractExtraProperties(data, *f) + if err != nil { + return err + } + f.extraProperties = extraProperties + f._rawJSON = json.RawMessage(data) return nil } @@ -288,7 +303,12 @@ type GetFinetunedModelResponse struct { // Information about the fine-tuned model. FinetunedModel *FinetunedModel `json:"finetuned_model,omitempty" url:"finetuned_model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GetFinetunedModelResponse) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GetFinetunedModelResponse) UnmarshalJSON(data []byte) error { @@ -298,6 +318,13 @@ func (g *GetFinetunedModelResponse) UnmarshalJSON(data []byte) error { return err } *g = GetFinetunedModelResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -329,7 +356,12 @@ type Hyperparameters struct { // The learning rate to be used during training. LearningRate *float64 `json:"learning_rate,omitempty" url:"learning_rate,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (h *Hyperparameters) GetExtraProperties() map[string]interface{} { + return h.extraProperties } func (h *Hyperparameters) UnmarshalJSON(data []byte) error { @@ -339,6 +371,13 @@ func (h *Hyperparameters) UnmarshalJSON(data []byte) error { return err } *h = Hyperparameters(value) + + extraProperties, err := core.ExtractExtraProperties(data, *h) + if err != nil { + return err + } + h.extraProperties = extraProperties + h._rawJSON = json.RawMessage(data) return nil } @@ -365,7 +404,12 @@ type ListEventsResponse struct { // Total count of results. TotalSize *int `json:"total_size,omitempty" url:"total_size,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListEventsResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListEventsResponse) UnmarshalJSON(data []byte) error { @@ -375,6 +419,13 @@ func (l *ListEventsResponse) UnmarshalJSON(data []byte) error { return err } *l = ListEventsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -401,7 +452,12 @@ type ListFinetunedModelsResponse struct { // Total count of results. TotalSize *int `json:"total_size,omitempty" url:"total_size,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListFinetunedModelsResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListFinetunedModelsResponse) UnmarshalJSON(data []byte) error { @@ -411,6 +467,13 @@ func (l *ListFinetunedModelsResponse) UnmarshalJSON(data []byte) error { return err } *l = ListFinetunedModelsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -435,7 +498,12 @@ type ListTrainingStepMetricsResponse struct { // it means no further results for the request. NextPageToken *string `json:"next_page_token,omitempty" url:"next_page_token,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListTrainingStepMetricsResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListTrainingStepMetricsResponse) UnmarshalJSON(data []byte) error { @@ -445,6 +513,13 @@ func (l *ListTrainingStepMetricsResponse) UnmarshalJSON(data []byte) error { return err } *l = ListTrainingStepMetricsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -472,7 +547,12 @@ type Settings struct { // read-only. Whether the model is single-label or multi-label (only for classification). MultiLabel *bool `json:"multi_label,omitempty" url:"multi_label,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (s *Settings) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *Settings) UnmarshalJSON(data []byte) error { @@ -482,6 +562,13 @@ func (s *Settings) UnmarshalJSON(data []byte) error { return err } *s = Settings(value) + + extraProperties, err := core.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s._rawJSON = json.RawMessage(data) return nil } @@ -591,7 +678,12 @@ type TrainingStepMetrics struct { // Map of names and values for each evaluation metrics. Metrics map[string]float64 `json:"metrics,omitempty" url:"metrics,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *TrainingStepMetrics) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *TrainingStepMetrics) UnmarshalJSON(data []byte) error { @@ -608,6 +700,12 @@ func (t *TrainingStepMetrics) UnmarshalJSON(data []byte) error { *t = TrainingStepMetrics(unmarshaler.embed) t.CreatedAt = unmarshaler.CreatedAt.TimePtr() + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -641,7 +739,12 @@ type UpdateFinetunedModelResponse struct { // Information about the fine-tuned model. FinetunedModel *FinetunedModel `json:"finetuned_model,omitempty" url:"finetuned_model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (u *UpdateFinetunedModelResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UpdateFinetunedModelResponse) UnmarshalJSON(data []byte) error { @@ -651,6 +754,13 @@ func (u *UpdateFinetunedModelResponse) UnmarshalJSON(data []byte) error { return err } *u = UpdateFinetunedModelResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u._rawJSON = json.RawMessage(data) return nil } diff --git a/models/client.go b/models/client.go index e55be54..4e2acf9 100644 --- a/models/client.go +++ b/models/client.go @@ -7,7 +7,6 @@ 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" @@ -54,7 +53,7 @@ func (c *Client) Get( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"models/%v", model) + endpointURL := core.EncodeURL(baseURL+"/models/%v", model) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -73,6 +72,34 @@ func (c *Client) Get( return apiError } return value + case 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -80,6 +107,13 @@ func (c *Client) Get( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(v2.InternalServerError) value.APIError = apiError @@ -87,6 +121,27 @@ func (c *Client) Get( return apiError } return value + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } @@ -124,7 +179,7 @@ func (c *Client) List( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/" + "models" + endpointURL := baseURL + "/models" queryParams, err := core.QueryValues(request) if err != nil { @@ -144,6 +199,41 @@ func (c *Client) List( 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 401: + value := new(v2.UnauthorizedError) + 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 422: + value := new(v2.UnprocessableEntityError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 429: value := new(v2.TooManyRequestsError) value.APIError = apiError @@ -151,6 +241,41 @@ func (c *Client) List( return apiError } return value + case 499: + value := new(v2.ClientClosedRequestError) + 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 + case 501: + value := new(v2.NotImplementedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 503: + value := new(v2.ServiceUnavailableError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 504: + value := new(v2.GatewayTimeoutError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value } return apiError } diff --git a/tests/sdk_test.go b/tests/sdk_test.go index 2fc54a3..2076ae3 100644 --- a/tests/sdk_test.go +++ b/tests/sdk_test.go @@ -377,6 +377,7 @@ func TestNewClient(t *testing.T) { ## Style Guide Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling. `), + ForceSingleStep: cohere.Bool(true), }) require.NoError(t, err) @@ -414,10 +415,11 @@ func TestNewClient(t *testing.T) { citedResponse, err := client.Chat( context.TODO(), &cohere.ChatRequest{ - Message: "How good were the sales on September 29?", - Tools: tools, - ToolResults: toolResults, - Model: strPointer("command-nightly"), + Message: "How good were the sales on September 29?", + Tools: tools, + ToolResults: toolResults, + Model: strPointer("command-nightly"), + ForceSingleStep: cohere.Bool(true), }) require.NoError(t, err) diff --git a/types.go b/types.go index 8c8450b..db9056c 100644 --- a/types.go +++ b/types.go @@ -12,12 +12,12 @@ import ( type ChatRequest struct { // Text input for the model to respond to. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Message string `json:"message" url:"message"` + Message string `json:"message" url:"-"` // Defaults to `command-r-plus`. // // The name of a compatible [Cohere model](https://docs.cohere.com/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/docs/chat-fine-tuning) model. // Compatible Deployments: Cohere Platform, Private Deployments - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // Defaults to `false`. // // When `true`, the response will be a JSON stream of events. The final event will contain the complete response, and will have an `event_type` of `"stream-end"`. @@ -29,19 +29,19 @@ type ChatRequest struct { // // The `SYSTEM` role is also used for the contents of the optional `chat_history=` parameter. When used with the `chat_history=` parameter it adds content throughout a conversation. Conversely, when used with the `preamble=` parameter it adds content at the start of the conversation only. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Preamble *string `json:"preamble,omitempty" url:"preamble,omitempty"` + Preamble *string `json:"preamble,omitempty" url:"-"` // A list of previous messages between the user and the model, giving the model conversational context for responding to the user's `message`. // // Each item represents a single message in the chat history, excluding the current user turn. It has two properties: `role` and `message`. The `role` identifies the sender (`CHATBOT`, `SYSTEM`, or `USER`), while the `message` contains the text content. // // The chat_history parameter should not be used for `SYSTEM` messages in most cases. Instead, to add a `SYSTEM` role message at the beginning of a conversation, the `preamble` parameter should be used. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - ChatHistory []*Message `json:"chat_history,omitempty" url:"chat_history,omitempty"` + ChatHistory []*Message `json:"chat_history,omitempty" url:"-"` // An alternative to `chat_history`. // // Providing a `conversation_id` creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. // Compatible Deployments: Cohere Platform - ConversationId *string `json:"conversation_id,omitempty" url:"conversation_id,omitempty"` + ConversationId *string `json:"conversation_id,omitempty" url:"-"` // Defaults to `AUTO` when `connectors` are specified and `OFF` in all other cases. // // Dictates how the prompt will be constructed. @@ -52,17 +52,17 @@ type ChatRequest struct { // // With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned. // Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker, Private Deployments - PromptTruncation *ChatRequestPromptTruncation `json:"prompt_truncation,omitempty" url:"prompt_truncation,omitempty"` + PromptTruncation *ChatRequestPromptTruncation `json:"prompt_truncation,omitempty" url:"-"` // Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one. // // When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG). // Compatible Deployments: Cohere Platform - Connectors []*ChatConnector `json:"connectors,omitempty" url:"connectors,omitempty"` + Connectors []*ChatConnector `json:"connectors,omitempty" url:"-"` // Defaults to `false`. // // When `true`, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's `message` will be generated. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - SearchQueriesOnly *bool `json:"search_queries_only,omitempty" url:"search_queries_only,omitempty"` + SearchQueriesOnly *bool `json:"search_queries_only,omitempty" url:"-"` // A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. // // Example: @@ -83,65 +83,65 @@ type ChatRequest struct { // // See ['Document Mode'](https://docs.cohere.com/docs/retrieval-augmented-generation-rag#document-mode) in the guide for more information. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Documents []ChatDocument `json:"documents,omitempty" url:"documents,omitempty"` + Documents []ChatDocument `json:"documents,omitempty" url:"-"` // Defaults to `"accurate"`. // // Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results or `"fast"` results. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - CitationQuality *ChatRequestCitationQuality `json:"citation_quality,omitempty" url:"citation_quality,omitempty"` + CitationQuality *ChatRequestCitationQuality `json:"citation_quality,omitempty" url:"-"` // Defaults to `0.3`. // // A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations. // // Randomness can be further maximized by increasing the value of the `p` parameter. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Temperature *float64 `json:"temperature,omitempty" url:"temperature,omitempty"` + Temperature *float64 `json:"temperature,omitempty" url:"-"` // The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - MaxTokens *int `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` + MaxTokens *int `json:"max_tokens,omitempty" url:"-"` // The maximum number of input tokens to send to the model. If not specified, `max_input_tokens` is the model's context length limit minus a small buffer. // // Input will be truncated according to the `prompt_truncation` parameter. // Compatible Deployments: Cohere Platform - MaxInputTokens *int `json:"max_input_tokens,omitempty" url:"max_input_tokens,omitempty"` + MaxInputTokens *int `json:"max_input_tokens,omitempty" url:"-"` // Ensures only the top `k` most likely tokens are considered for generation at each step. // Defaults to `0`, min value of `0`, max value of `500`. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - K *int `json:"k,omitempty" url:"k,omitempty"` + K *int `json:"k,omitempty" url:"-"` // Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. // Defaults to `0.75`. min value of `0.01`, max value of `0.99`. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - P *float64 `json:"p,omitempty" url:"p,omitempty"` + P *float64 `json:"p,omitempty" url:"-"` // If specified, the backend will make a best effort to sample tokens // deterministically, such that repeated requests with the same // seed and parameters should return the same result. However, // determinism cannot be totally guaranteed. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + Seed *int `json:"seed,omitempty" url:"-"` // A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - StopSequences []string `json:"stop_sequences,omitempty" url:"stop_sequences,omitempty"` + StopSequences []string `json:"stop_sequences,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"frequency_penalty,omitempty"` + FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"presence_penalty,omitempty"` + PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"-"` // When enabled, the user's prompt will be sent to the model without // any pre-processing. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - RawPrompting *bool `json:"raw_prompting,omitempty" url:"raw_prompting,omitempty"` + RawPrompting *bool `json:"raw_prompting,omitempty" url:"-"` // The prompt is returned in the `prompt` response field when this is enabled. - ReturnPrompt *bool `json:"return_prompt,omitempty" url:"return_prompt,omitempty"` + ReturnPrompt *bool `json:"return_prompt,omitempty" url:"-"` // A list of available tools (functions) that the model may suggest invoking before producing a text response. // // When `tools` is passed (without `tool_results`), the `text` field in the response will be `""` and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Tools []*Tool `json:"tools,omitempty" url:"tools,omitempty"` + Tools []*Tool `json:"tools,omitempty" url:"-"` // A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using `tool_results`, `tools` must be passed as well. // Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries. // @@ -166,9 +166,9 @@ type ChatRequest struct { // ``` // **Note**: Chat calls with `tool_results` should not be included in the Chat history to avoid duplication of the message text. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - ToolResults []*ToolResult `json:"tool_results,omitempty" url:"tool_results,omitempty"` + ToolResults []*ToolResult `json:"tool_results,omitempty" url:"-"` // Forces the chat to be single step. Defaults to `false`. - ForceSingleStep *bool `json:"force_single_step,omitempty" url:"force_single_step,omitempty"` + ForceSingleStep *bool `json:"force_single_step,omitempty" url:"-"` stream bool } @@ -202,12 +202,12 @@ func (c *ChatRequest) MarshalJSON() ([]byte, error) { type ChatStreamRequest struct { // Text input for the model to respond to. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Message string `json:"message" url:"message"` + Message string `json:"message" url:"-"` // Defaults to `command-r-plus`. // // The name of a compatible [Cohere model](https://docs.cohere.com/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/docs/chat-fine-tuning) model. // Compatible Deployments: Cohere Platform, Private Deployments - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // Defaults to `false`. // // When `true`, the response will be a JSON stream of events. The final event will contain the complete response, and will have an `event_type` of `"stream-end"`. @@ -219,19 +219,19 @@ type ChatStreamRequest struct { // // The `SYSTEM` role is also used for the contents of the optional `chat_history=` parameter. When used with the `chat_history=` parameter it adds content throughout a conversation. Conversely, when used with the `preamble=` parameter it adds content at the start of the conversation only. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Preamble *string `json:"preamble,omitempty" url:"preamble,omitempty"` + Preamble *string `json:"preamble,omitempty" url:"-"` // A list of previous messages between the user and the model, giving the model conversational context for responding to the user's `message`. // // Each item represents a single message in the chat history, excluding the current user turn. It has two properties: `role` and `message`. The `role` identifies the sender (`CHATBOT`, `SYSTEM`, or `USER`), while the `message` contains the text content. // // The chat_history parameter should not be used for `SYSTEM` messages in most cases. Instead, to add a `SYSTEM` role message at the beginning of a conversation, the `preamble` parameter should be used. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - ChatHistory []*Message `json:"chat_history,omitempty" url:"chat_history,omitempty"` + ChatHistory []*Message `json:"chat_history,omitempty" url:"-"` // An alternative to `chat_history`. // // Providing a `conversation_id` creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. // Compatible Deployments: Cohere Platform - ConversationId *string `json:"conversation_id,omitempty" url:"conversation_id,omitempty"` + ConversationId *string `json:"conversation_id,omitempty" url:"-"` // Defaults to `AUTO` when `connectors` are specified and `OFF` in all other cases. // // Dictates how the prompt will be constructed. @@ -242,17 +242,17 @@ type ChatStreamRequest struct { // // With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned. // Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker, Private Deployments - PromptTruncation *ChatStreamRequestPromptTruncation `json:"prompt_truncation,omitempty" url:"prompt_truncation,omitempty"` + PromptTruncation *ChatStreamRequestPromptTruncation `json:"prompt_truncation,omitempty" url:"-"` // Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one. // // When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG). // Compatible Deployments: Cohere Platform - Connectors []*ChatConnector `json:"connectors,omitempty" url:"connectors,omitempty"` + Connectors []*ChatConnector `json:"connectors,omitempty" url:"-"` // Defaults to `false`. // // When `true`, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's `message` will be generated. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - SearchQueriesOnly *bool `json:"search_queries_only,omitempty" url:"search_queries_only,omitempty"` + SearchQueriesOnly *bool `json:"search_queries_only,omitempty" url:"-"` // A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. // // Example: @@ -273,65 +273,65 @@ type ChatStreamRequest struct { // // See ['Document Mode'](https://docs.cohere.com/docs/retrieval-augmented-generation-rag#document-mode) in the guide for more information. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Documents []ChatDocument `json:"documents,omitempty" url:"documents,omitempty"` + Documents []ChatDocument `json:"documents,omitempty" url:"-"` // Defaults to `"accurate"`. // // Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results or `"fast"` results. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - CitationQuality *ChatStreamRequestCitationQuality `json:"citation_quality,omitempty" url:"citation_quality,omitempty"` + CitationQuality *ChatStreamRequestCitationQuality `json:"citation_quality,omitempty" url:"-"` // Defaults to `0.3`. // // A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations. // // Randomness can be further maximized by increasing the value of the `p` parameter. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Temperature *float64 `json:"temperature,omitempty" url:"temperature,omitempty"` + Temperature *float64 `json:"temperature,omitempty" url:"-"` // The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - MaxTokens *int `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` + MaxTokens *int `json:"max_tokens,omitempty" url:"-"` // The maximum number of input tokens to send to the model. If not specified, `max_input_tokens` is the model's context length limit minus a small buffer. // // Input will be truncated according to the `prompt_truncation` parameter. // Compatible Deployments: Cohere Platform - MaxInputTokens *int `json:"max_input_tokens,omitempty" url:"max_input_tokens,omitempty"` + MaxInputTokens *int `json:"max_input_tokens,omitempty" url:"-"` // Ensures only the top `k` most likely tokens are considered for generation at each step. // Defaults to `0`, min value of `0`, max value of `500`. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - K *int `json:"k,omitempty" url:"k,omitempty"` + K *int `json:"k,omitempty" url:"-"` // Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. // Defaults to `0.75`. min value of `0.01`, max value of `0.99`. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - P *float64 `json:"p,omitempty" url:"p,omitempty"` + P *float64 `json:"p,omitempty" url:"-"` // If specified, the backend will make a best effort to sample tokens // deterministically, such that repeated requests with the same // seed and parameters should return the same result. However, // determinism cannot be totally guaranteed. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + Seed *int `json:"seed,omitempty" url:"-"` // A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - StopSequences []string `json:"stop_sequences,omitempty" url:"stop_sequences,omitempty"` + StopSequences []string `json:"stop_sequences,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"frequency_penalty,omitempty"` + FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"presence_penalty,omitempty"` + PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"-"` // When enabled, the user's prompt will be sent to the model without // any pre-processing. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - RawPrompting *bool `json:"raw_prompting,omitempty" url:"raw_prompting,omitempty"` + RawPrompting *bool `json:"raw_prompting,omitempty" url:"-"` // The prompt is returned in the `prompt` response field when this is enabled. - ReturnPrompt *bool `json:"return_prompt,omitempty" url:"return_prompt,omitempty"` + ReturnPrompt *bool `json:"return_prompt,omitempty" url:"-"` // A list of available tools (functions) that the model may suggest invoking before producing a text response. // // When `tools` is passed (without `tool_results`), the `text` field in the response will be `""` and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - Tools []*Tool `json:"tools,omitempty" url:"tools,omitempty"` + Tools []*Tool `json:"tools,omitempty" url:"-"` // A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using `tool_results`, `tools` must be passed as well. // Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries. // @@ -356,9 +356,9 @@ type ChatStreamRequest struct { // ``` // **Note**: Chat calls with `tool_results` should not be included in the Chat history to avoid duplication of the message text. // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments - ToolResults []*ToolResult `json:"tool_results,omitempty" url:"tool_results,omitempty"` + ToolResults []*ToolResult `json:"tool_results,omitempty" url:"-"` // Forces the chat to be single step. Defaults to `false`. - ForceSingleStep *bool `json:"force_single_step,omitempty" url:"force_single_step,omitempty"` + ForceSingleStep *bool `json:"force_single_step,omitempty" url:"-"` stream bool } @@ -393,30 +393,30 @@ type ClassifyRequest struct { // A list of up to 96 texts to be classified. Each one must be a non-empty string. // There is, however, no consistent, universal limit to the length a particular input can be. We perform classification on the first `x` tokens of each input, and `x` varies depending on which underlying model is powering classification. The maximum token length for each model is listed in the "max tokens" column [here](https://docs.cohere.com/docs/models). // Note: by default the `truncate` parameter is set to `END`, so tokens exceeding the limit will be automatically dropped. This behavior can be disabled by setting `truncate` to `NONE`, which will result in validation errors for longer texts. - Inputs []string `json:"inputs,omitempty" url:"inputs,omitempty"` + Inputs []string `json:"inputs,omitempty" url:"-"` // An array of examples to provide context to the model. Each example is a text string and its associated label/class. Each unique label requires at least 2 examples associated with it; the maximum number of examples is 2500, and each example has a maximum length of 512 tokens. The values should be structured as `{text: "...",label: "..."}`. // Note: [Fine-tuned Models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly. - Examples []*ClassifyExample `json:"examples,omitempty" url:"examples,omitempty"` + Examples []*ClassifyExample `json:"examples,omitempty" url:"-"` // The identifier of the model. Currently available models are `embed-multilingual-v2.0`, `embed-english-light-v2.0`, and `embed-english-v2.0` (default). Smaller "light" models are faster, while larger models will perform better. [Fine-tuned models](https://docs.cohere.com/docs/fine-tuning) can also be supplied with their full ID. - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // The ID of a custom playground preset. You can create presets in the [playground](https://dashboard.cohere.com/playground/classify?model=large). If you use a preset, all other parameters become optional, and any included parameters will override the preset's parameters. - Preset *string `json:"preset,omitempty" url:"preset,omitempty"` + Preset *string `json:"preset,omitempty" url:"-"` // One of `NONE|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. // If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - Truncate *ClassifyRequestTruncate `json:"truncate,omitempty" url:"truncate,omitempty"` + Truncate *ClassifyRequestTruncate `json:"truncate,omitempty" url:"-"` } type DetokenizeRequest struct { // The list of tokens to be detokenized. - Tokens []int `json:"tokens,omitempty" url:"tokens,omitempty"` + Tokens []int `json:"tokens,omitempty" url:"-"` // An optional parameter to provide the model name. This will ensure that the detokenization is done by the tokenizer used by that model. - Model string `json:"model" url:"model"` + Model string `json:"model" url:"-"` } type EmbedRequest struct { // An array of strings for the model to embed. Maximum number of texts per call is `96`. We recommend reducing the length of each text to be under `512` tokens for optimal quality. - Texts []string `json:"texts,omitempty" url:"texts,omitempty"` + Texts []string `json:"texts,omitempty" url:"-"` // Defaults to embed-english-v2.0 // // The identifier of the model. Smaller "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. @@ -431,8 +431,8 @@ type EmbedRequest struct { // * `embed-english-v2.0` 4096 // * `embed-english-light-v2.0` 1024 // * `embed-multilingual-v2.0` 768 - Model *string `json:"model,omitempty" url:"model,omitempty"` - InputType *EmbedInputType `json:"input_type,omitempty" url:"input_type,omitempty"` + Model *string `json:"model,omitempty" url:"-"` + InputType *EmbedInputType `json:"input_type,omitempty" url:"-"` // 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. @@ -440,24 +440,24 @@ type EmbedRequest struct { // * `"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"` + EmbeddingTypes []EmbeddingType `json:"embedding_types,omitempty" url:"-"` // One of `NONE|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. // // If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - Truncate *EmbedRequestTruncate `json:"truncate,omitempty" url:"truncate,omitempty"` + Truncate *EmbedRequestTruncate `json:"truncate,omitempty" url:"-"` } type GenerateRequest struct { // The input text that serves as the starting point for generating the response. // Note: The prompt will be pre-processed and modified before reaching the model. - Prompt string `json:"prompt" url:"prompt"` + Prompt string `json:"prompt" url:"-"` // The identifier of the model to generate with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). // Smaller, "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // The maximum number of generations that will be returned. Defaults to `1`, min value of `1`, max value of `5`. - NumGenerations *int `json:"num_generations,omitempty" url:"num_generations,omitempty"` + NumGenerations *int `json:"num_generations,omitempty" url:"-"` // When `true`, the response will be a JSON stream of events. Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated. // // The final event will contain the complete response, and will contain an `is_finished` field set to `true`. The event will also contain a `finish_reason`, which can be one of the following: @@ -471,49 +471,53 @@ type GenerateRequest struct { // This parameter is off by default, and if it's not specified, the model will continue generating until it emits an EOS completion token. See [BPE Tokens](/bpe-tokens-wiki) for more details. // // Can only be set to `0` if `return_likelihoods` is set to `ALL` to get the likelihood of the prompt. - MaxTokens *int `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` + MaxTokens *int `json:"max_tokens,omitempty" url:"-"` // One of `NONE|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. // // If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - Truncate *GenerateRequestTruncate `json:"truncate,omitempty" url:"truncate,omitempty"` + Truncate *GenerateRequestTruncate `json:"truncate,omitempty" url:"-"` // A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations. See [Temperature](/temperature-wiki) for more details. // Defaults to `0.75`, min value of `0.0`, max value of `5.0`. - Temperature *float64 `json:"temperature,omitempty" url:"temperature,omitempty"` - // If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + Temperature *float64 `json:"temperature,omitempty" url:"-"` + // If specified, the backend will make a best effort to sample tokens + // deterministically, such that repeated requests with the same + // seed and parameters should return the same result. However, + // determinism cannot be totally guaranteed. + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments + Seed *int `json:"seed,omitempty" url:"-"` // Identifier of a custom preset. A preset is a combination of parameters, such as prompt, temperature etc. You can create presets in the [playground](https://dashboard.cohere.com/playground/generate). // When a preset is specified, the `prompt` parameter becomes optional, and any included parameters will override the preset's parameters. - Preset *string `json:"preset,omitempty" url:"preset,omitempty"` + Preset *string `json:"preset,omitempty" url:"-"` // The generated text will be cut at the beginning of the earliest occurrence of an end sequence. The sequence will be excluded from the text. - EndSequences []string `json:"end_sequences,omitempty" url:"end_sequences,omitempty"` + EndSequences []string `json:"end_sequences,omitempty" url:"-"` // The generated text will be cut at the end of the earliest occurrence of a stop sequence. The sequence will be included the text. - StopSequences []string `json:"stop_sequences,omitempty" url:"stop_sequences,omitempty"` + StopSequences []string `json:"stop_sequences,omitempty" url:"-"` // Ensures only the top `k` most likely tokens are considered for generation at each step. // Defaults to `0`, min value of `0`, max value of `500`. - K *int `json:"k,omitempty" url:"k,omitempty"` + K *int `json:"k,omitempty" url:"-"` // Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. // Defaults to `0.75`. min value of `0.01`, max value of `0.99`. - P *float64 `json:"p,omitempty" url:"p,omitempty"` + P *float64 `json:"p,omitempty" url:"-"` // Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"frequency_penalty,omitempty"` + FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Can be used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"presence_penalty,omitempty"` + PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"-"` // One of `GENERATION|ALL|NONE` to specify how and if the token likelihoods are returned with the response. Defaults to `NONE`. // // If `GENERATION` is selected, the token likelihoods will only be provided for generated text. // // If `ALL` is selected, the token likelihoods will be provided both for the prompt and the generated text. - ReturnLikelihoods *GenerateRequestReturnLikelihoods `json:"return_likelihoods,omitempty" url:"return_likelihoods,omitempty"` + ReturnLikelihoods *GenerateRequestReturnLikelihoods `json:"return_likelihoods,omitempty" url:"-"` // When enabled, the user's prompt will be sent to the model without any pre-processing. - RawPrompting *bool `json:"raw_prompting,omitempty" url:"raw_prompting,omitempty"` + RawPrompting *bool `json:"raw_prompting,omitempty" url:"-"` stream bool } @@ -547,12 +551,12 @@ func (g *GenerateRequest) MarshalJSON() ([]byte, error) { type GenerateStreamRequest struct { // The input text that serves as the starting point for generating the response. // Note: The prompt will be pre-processed and modified before reaching the model. - Prompt string `json:"prompt" url:"prompt"` + Prompt string `json:"prompt" url:"-"` // The identifier of the model to generate with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). // Smaller, "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // The maximum number of generations that will be returned. Defaults to `1`, min value of `1`, max value of `5`. - NumGenerations *int `json:"num_generations,omitempty" url:"num_generations,omitempty"` + NumGenerations *int `json:"num_generations,omitempty" url:"-"` // When `true`, the response will be a JSON stream of events. Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated. // // The final event will contain the complete response, and will contain an `is_finished` field set to `true`. The event will also contain a `finish_reason`, which can be one of the following: @@ -566,49 +570,53 @@ type GenerateStreamRequest struct { // This parameter is off by default, and if it's not specified, the model will continue generating until it emits an EOS completion token. See [BPE Tokens](/bpe-tokens-wiki) for more details. // // Can only be set to `0` if `return_likelihoods` is set to `ALL` to get the likelihood of the prompt. - MaxTokens *int `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` + MaxTokens *int `json:"max_tokens,omitempty" url:"-"` // One of `NONE|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. // // If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - Truncate *GenerateStreamRequestTruncate `json:"truncate,omitempty" url:"truncate,omitempty"` + Truncate *GenerateStreamRequestTruncate `json:"truncate,omitempty" url:"-"` // A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations. See [Temperature](/temperature-wiki) for more details. // Defaults to `0.75`, min value of `0.0`, max value of `5.0`. - Temperature *float64 `json:"temperature,omitempty" url:"temperature,omitempty"` - // If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + Temperature *float64 `json:"temperature,omitempty" url:"-"` + // If specified, the backend will make a best effort to sample tokens + // deterministically, such that repeated requests with the same + // seed and parameters should return the same result. However, + // determinism cannot be totally guaranteed. + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments + Seed *int `json:"seed,omitempty" url:"-"` // Identifier of a custom preset. A preset is a combination of parameters, such as prompt, temperature etc. You can create presets in the [playground](https://dashboard.cohere.com/playground/generate). // When a preset is specified, the `prompt` parameter becomes optional, and any included parameters will override the preset's parameters. - Preset *string `json:"preset,omitempty" url:"preset,omitempty"` + Preset *string `json:"preset,omitempty" url:"-"` // The generated text will be cut at the beginning of the earliest occurrence of an end sequence. The sequence will be excluded from the text. - EndSequences []string `json:"end_sequences,omitempty" url:"end_sequences,omitempty"` + EndSequences []string `json:"end_sequences,omitempty" url:"-"` // The generated text will be cut at the end of the earliest occurrence of a stop sequence. The sequence will be included the text. - StopSequences []string `json:"stop_sequences,omitempty" url:"stop_sequences,omitempty"` + StopSequences []string `json:"stop_sequences,omitempty" url:"-"` // Ensures only the top `k` most likely tokens are considered for generation at each step. // Defaults to `0`, min value of `0`, max value of `500`. - K *int `json:"k,omitempty" url:"k,omitempty"` + K *int `json:"k,omitempty" url:"-"` // Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. // Defaults to `0.75`. min value of `0.01`, max value of `0.99`. - P *float64 `json:"p,omitempty" url:"p,omitempty"` + P *float64 `json:"p,omitempty" url:"-"` // Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"frequency_penalty,omitempty"` + FrequencyPenalty *float64 `json:"frequency_penalty,omitempty" url:"-"` // Defaults to `0.0`, min value of `0.0`, max value of `1.0`. // // Can be used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"presence_penalty,omitempty"` + PresencePenalty *float64 `json:"presence_penalty,omitempty" url:"-"` // One of `GENERATION|ALL|NONE` to specify how and if the token likelihoods are returned with the response. Defaults to `NONE`. // // If `GENERATION` is selected, the token likelihoods will only be provided for generated text. // // If `ALL` is selected, the token likelihoods will be provided both for the prompt and the generated text. - ReturnLikelihoods *GenerateStreamRequestReturnLikelihoods `json:"return_likelihoods,omitempty" url:"return_likelihoods,omitempty"` + ReturnLikelihoods *GenerateStreamRequestReturnLikelihoods `json:"return_likelihoods,omitempty" url:"-"` // When enabled, the user's prompt will be sent to the model without any pre-processing. - RawPrompting *bool `json:"raw_prompting,omitempty" url:"raw_prompting,omitempty"` + RawPrompting *bool `json:"raw_prompting,omitempty" url:"-"` stream bool } @@ -641,49 +649,49 @@ func (g *GenerateStreamRequest) MarshalJSON() ([]byte, error) { type RerankRequest struct { // The identifier of the model to use, one of : `rerank-english-v3.0`, `rerank-multilingual-v3.0`, `rerank-english-v2.0`, `rerank-multilingual-v2.0` - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // The search query - Query string `json:"query" url:"query"` + Query string `json:"query" url:"-"` // A list of document objects or strings to rerank. // If a document is provided the text fields is required and all other fields will be preserved in the response. // // The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000. // // We recommend a maximum of 1,000 documents for optimal endpoint performance. - Documents []*RerankRequestDocumentsItem `json:"documents,omitempty" url:"documents,omitempty"` + Documents []*RerankRequestDocumentsItem `json:"documents,omitempty" url:"-"` // The number of most relevant documents or indices to return, defaults to the length of the documents - TopN *int `json:"top_n,omitempty" url:"top_n,omitempty"` + TopN *int `json:"top_n,omitempty" url:"-"` // If a JSON object is provided, you can specify which keys you would like to have considered for reranking. The model will rerank based on order of the fields passed in (i.e. rank_fields=['title','author','text'] will rerank using the values in title, author, text sequentially. If the length of title, author, and text exceeds the context length of the model, the chunking will not re-consider earlier fields). If not provided, the model will use the default text field for ranking. - RankFields []string `json:"rank_fields,omitempty" url:"rank_fields,omitempty"` + RankFields []string `json:"rank_fields,omitempty" url:"-"` // - If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request. // - If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request. - ReturnDocuments *bool `json:"return_documents,omitempty" url:"return_documents,omitempty"` + ReturnDocuments *bool `json:"return_documents,omitempty" url:"-"` // The maximum number of chunks to produce internally from a document - MaxChunksPerDoc *int `json:"max_chunks_per_doc,omitempty" url:"max_chunks_per_doc,omitempty"` + MaxChunksPerDoc *int `json:"max_chunks_per_doc,omitempty" url:"-"` } type SummarizeRequest struct { // The text to generate a summary for. Can be up to 100,000 characters long. Currently the only supported language is English. - Text string `json:"text" url:"text"` + Text string `json:"text" url:"-"` // One of `short`, `medium`, `long`, or `auto` defaults to `auto`. Indicates the approximate length of the summary. If `auto` is selected, the best option will be picked based on the input text. - Length *SummarizeRequestLength `json:"length,omitempty" url:"length,omitempty"` + Length *SummarizeRequestLength `json:"length,omitempty" url:"-"` // One of `paragraph`, `bullets`, or `auto`, defaults to `auto`. Indicates the style in which the summary will be delivered - in a free form paragraph or in bullet points. If `auto` is selected, the best option will be picked based on the input text. - Format *SummarizeRequestFormat `json:"format,omitempty" url:"format,omitempty"` + Format *SummarizeRequestFormat `json:"format,omitempty" url:"-"` // The identifier of the model to generate the summary with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). Smaller, "light" models are faster, while larger models will perform better. - Model *string `json:"model,omitempty" url:"model,omitempty"` + Model *string `json:"model,omitempty" url:"-"` // One of `low`, `medium`, `high`, or `auto`, defaults to `auto`. Controls how close to the original text the summary is. `high` extractiveness summaries will lean towards reusing sentences verbatim, while `low` extractiveness summaries will tend to paraphrase more. If `auto` is selected, the best option will be picked based on the input text. - Extractiveness *SummarizeRequestExtractiveness `json:"extractiveness,omitempty" url:"extractiveness,omitempty"` + Extractiveness *SummarizeRequestExtractiveness `json:"extractiveness,omitempty" url:"-"` // Ranges from 0 to 5. Controls the randomness of the output. Lower values tend to generate more “predictable” output, while higher values tend to generate more “creative” output. The sweet spot is typically between 0 and 1. - Temperature *float64 `json:"temperature,omitempty" url:"temperature,omitempty"` + Temperature *float64 `json:"temperature,omitempty" url:"-"` // A free-form instruction for modifying how the summaries get generated. Should complete the sentence "Generate a summary _". Eg. "focusing on the next steps" or "written by Yoda" - AdditionalCommand *string `json:"additional_command,omitempty" url:"additional_command,omitempty"` + AdditionalCommand *string `json:"additional_command,omitempty" url:"-"` } type TokenizeRequest struct { // The string to be tokenized, the minimum text length is 1 character, and the maximum text length is 65536 characters. - Text string `json:"text" url:"text"` + Text string `json:"text" url:"-"` // An optional parameter to provide the model name. This will ensure that the tokenization uses the tokenizer used by that model. - Model string `json:"model" url:"model"` + Model string `json:"model" url:"-"` } type ApiMeta struct { @@ -692,7 +700,12 @@ type ApiMeta struct { Tokens *ApiMetaTokens `json:"tokens,omitempty" url:"tokens,omitempty"` Warnings []string `json:"warnings,omitempty" url:"warnings,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (a *ApiMeta) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ApiMeta) UnmarshalJSON(data []byte) error { @@ -702,6 +715,13 @@ func (a *ApiMeta) UnmarshalJSON(data []byte) error { return err } *a = ApiMeta(value) + + extraProperties, err := core.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a._rawJSON = json.RawMessage(data) return nil } @@ -723,7 +743,12 @@ type ApiMetaApiVersion struct { IsDeprecated *bool `json:"is_deprecated,omitempty" url:"is_deprecated,omitempty"` IsExperimental *bool `json:"is_experimental,omitempty" url:"is_experimental,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (a *ApiMetaApiVersion) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ApiMetaApiVersion) UnmarshalJSON(data []byte) error { @@ -733,6 +758,13 @@ func (a *ApiMetaApiVersion) UnmarshalJSON(data []byte) error { return err } *a = ApiMetaApiVersion(value) + + extraProperties, err := core.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a._rawJSON = json.RawMessage(data) return nil } @@ -759,7 +791,12 @@ type ApiMetaBilledUnits struct { // The number of billed classifications units. Classifications *float64 `json:"classifications,omitempty" url:"classifications,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (a *ApiMetaBilledUnits) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ApiMetaBilledUnits) UnmarshalJSON(data []byte) error { @@ -769,6 +806,13 @@ func (a *ApiMetaBilledUnits) UnmarshalJSON(data []byte) error { return err } *a = ApiMetaBilledUnits(value) + + extraProperties, err := core.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a._rawJSON = json.RawMessage(data) return nil } @@ -791,7 +835,12 @@ type ApiMetaTokens struct { // The number of tokens produced by the model. OutputTokens *float64 `json:"output_tokens,omitempty" url:"output_tokens,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (a *ApiMetaTokens) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ApiMetaTokens) UnmarshalJSON(data []byte) error { @@ -801,6 +850,13 @@ func (a *ApiMetaTokens) UnmarshalJSON(data []byte) error { return err } *a = ApiMetaTokens(value) + + extraProperties, err := core.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a._rawJSON = json.RawMessage(data) return nil } @@ -854,7 +910,12 @@ type ChatCitation struct { // Identifiers of documents cited by this section of the generated reply. DocumentIds []string `json:"document_ids,omitempty" url:"document_ids,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatCitation) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatCitation) UnmarshalJSON(data []byte) error { @@ -864,6 +925,13 @@ func (c *ChatCitation) UnmarshalJSON(data []byte) error { return err } *c = ChatCitation(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -884,7 +952,12 @@ type ChatCitationGenerationEvent struct { // Citations for the generated reply. Citations []*ChatCitation `json:"citations,omitempty" url:"citations,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatCitationGenerationEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatCitationGenerationEvent) UnmarshalJSON(data []byte) error { @@ -894,6 +967,13 @@ func (c *ChatCitationGenerationEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatCitationGenerationEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -925,7 +1005,12 @@ type ChatConnector struct { // For example, the connector `web-search` supports the `site` option, which limits search results to the specified domain. Options map[string]interface{} `json:"options,omitempty" url:"options,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatConnector) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatConnector) UnmarshalJSON(data []byte) error { @@ -935,6 +1020,13 @@ func (c *ChatConnector) UnmarshalJSON(data []byte) error { return err } *c = ChatConnector(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -959,7 +1051,12 @@ type ChatDataMetrics struct { // The preamble of this dataset. Preamble *string `json:"preamble,omitempty" url:"preamble,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatDataMetrics) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatDataMetrics) UnmarshalJSON(data []byte) error { @@ -969,6 +1066,13 @@ func (c *ChatDataMetrics) UnmarshalJSON(data []byte) error { return err } *c = ChatDataMetrics(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -999,7 +1103,12 @@ type ChatMessage struct { Message string `json:"message" url:"message"` ToolCalls []*ToolCall `json:"tool_calls,omitempty" url:"tool_calls,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatMessage) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatMessage) UnmarshalJSON(data []byte) error { @@ -1009,6 +1118,13 @@ func (c *ChatMessage) UnmarshalJSON(data []byte) error { return err } *c = ChatMessage(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1053,14 +1169,19 @@ func (c ChatRequestCitationQuality) Ptr() *ChatRequestCitationQuality { // (internal) Sets inference and model options for RAG search query and tool use generations. Defaults are used when options are not specified here, meaning that other parameters outside of connectors_search_options are ignored (such as model= or temperature=). type ChatRequestConnectorsSearchOptions struct { - Model interface{} `json:"model,omitempty" url:"model,omitempty"` - Temperature interface{} `json:"temperature,omitempty" url:"temperature,omitempty"` - MaxTokens interface{} `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` - Preamble interface{} `json:"preamble,omitempty" url:"preamble,omitempty"` - // If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + // If specified, the backend will make a best effort to sample tokens + // deterministically, such that repeated requests with the same + // seed and parameters should return the same result. However, + // determinism cannot be totally guaranteed. + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments + Seed *int `json:"seed,omitempty" url:"seed,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} - _rawJSON json.RawMessage +func (c *ChatRequestConnectorsSearchOptions) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatRequestConnectorsSearchOptions) UnmarshalJSON(data []byte) error { @@ -1070,6 +1191,13 @@ func (c *ChatRequestConnectorsSearchOptions) UnmarshalJSON(data []byte) error { return err } *c = ChatRequestConnectorsSearchOptions(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1125,7 +1253,12 @@ type ChatSearchQueriesGenerationEvent struct { // Generated search queries, meant to be used as part of the RAG flow. SearchQueries []*ChatSearchQuery `json:"search_queries,omitempty" url:"search_queries,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatSearchQueriesGenerationEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatSearchQueriesGenerationEvent) UnmarshalJSON(data []byte) error { @@ -1135,6 +1268,13 @@ func (c *ChatSearchQueriesGenerationEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatSearchQueriesGenerationEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1158,7 +1298,12 @@ type ChatSearchQuery struct { // Unique identifier for the generated search query. Useful for submitting feedback. GenerationId string `json:"generation_id" url:"generation_id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatSearchQuery) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatSearchQuery) UnmarshalJSON(data []byte) error { @@ -1168,6 +1313,13 @@ func (c *ChatSearchQuery) UnmarshalJSON(data []byte) error { return err } *c = ChatSearchQuery(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1195,7 +1347,12 @@ type ChatSearchResult struct { // Whether a chat request should continue or not if the request to this connector fails. ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"continue_on_failure,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatSearchResult) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatSearchResult) UnmarshalJSON(data []byte) error { @@ -1205,6 +1362,13 @@ func (c *ChatSearchResult) UnmarshalJSON(data []byte) error { return err } *c = ChatSearchResult(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1226,7 +1390,12 @@ type ChatSearchResultConnector struct { // The identifier of the connector. Id string `json:"id" url:"id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatSearchResultConnector) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatSearchResultConnector) UnmarshalJSON(data []byte) error { @@ -1236,6 +1405,13 @@ func (c *ChatSearchResultConnector) UnmarshalJSON(data []byte) error { return err } *c = ChatSearchResultConnector(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1258,7 +1434,12 @@ type ChatSearchResultsEvent struct { // Documents fetched from searches or provided by the user. Documents []ChatDocument `json:"documents,omitempty" url:"documents,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatSearchResultsEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatSearchResultsEvent) UnmarshalJSON(data []byte) error { @@ -1268,6 +1449,13 @@ func (c *ChatSearchResultsEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatSearchResultsEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1294,7 +1482,12 @@ type ChatStreamEndEvent struct { // The consolidated response from the model. Contains the generated reply and all the other information streamed back in the previous events. Response *NonStreamedChatResponse `json:"response,omitempty" url:"response,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatStreamEndEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatStreamEndEvent) UnmarshalJSON(data []byte) error { @@ -1304,6 +1497,13 @@ func (c *ChatStreamEndEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatStreamEndEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1357,7 +1557,12 @@ func (c ChatStreamEndEventFinishReason) Ptr() *ChatStreamEndEventFinishReason { } type ChatStreamEvent struct { - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatStreamEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatStreamEvent) UnmarshalJSON(data []byte) error { @@ -1367,6 +1572,13 @@ func (c *ChatStreamEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatStreamEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1411,14 +1623,19 @@ func (c ChatStreamRequestCitationQuality) Ptr() *ChatStreamRequestCitationQualit // (internal) Sets inference and model options for RAG search query and tool use generations. Defaults are used when options are not specified here, meaning that other parameters outside of connectors_search_options are ignored (such as model= or temperature=). type ChatStreamRequestConnectorsSearchOptions struct { - Model interface{} `json:"model,omitempty" url:"model,omitempty"` - Temperature interface{} `json:"temperature,omitempty" url:"temperature,omitempty"` - MaxTokens interface{} `json:"max_tokens,omitempty" url:"max_tokens,omitempty"` - Preamble interface{} `json:"preamble,omitempty" url:"preamble,omitempty"` - // If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. - Seed *float64 `json:"seed,omitempty" url:"seed,omitempty"` + // If specified, the backend will make a best effort to sample tokens + // deterministically, such that repeated requests with the same + // seed and parameters should return the same result. However, + // determinism cannot be totally guaranteed. + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments + Seed *int `json:"seed,omitempty" url:"seed,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} - _rawJSON json.RawMessage +func (c *ChatStreamRequestConnectorsSearchOptions) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatStreamRequestConnectorsSearchOptions) UnmarshalJSON(data []byte) error { @@ -1428,6 +1645,13 @@ func (c *ChatStreamRequestConnectorsSearchOptions) UnmarshalJSON(data []byte) er return err } *c = ChatStreamRequestConnectorsSearchOptions(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1483,7 +1707,12 @@ type ChatStreamStartEvent struct { // Unique identifier for the generated reply. Useful for submitting feedback. GenerationId string `json:"generation_id" url:"generation_id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatStreamStartEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatStreamStartEvent) UnmarshalJSON(data []byte) error { @@ -1493,6 +1722,13 @@ func (c *ChatStreamStartEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatStreamStartEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1513,7 +1749,12 @@ type ChatTextGenerationEvent struct { // The next batch of text generated by the model. Text string `json:"text" url:"text"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatTextGenerationEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatTextGenerationEvent) UnmarshalJSON(data []byte) error { @@ -1523,6 +1764,13 @@ func (c *ChatTextGenerationEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatTextGenerationEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1539,10 +1787,58 @@ func (c *ChatTextGenerationEvent) String() string { return fmt.Sprintf("%#v", c) } +type ChatToolCallsChunkEvent struct { + ToolCallDelta *ToolCallDelta `json:"tool_call_delta,omitempty" url:"tool_call_delta,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatToolCallsChunkEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ChatToolCallsChunkEvent) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallsChunkEvent + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ChatToolCallsChunkEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ChatToolCallsChunkEvent) 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 ChatToolCallsGenerationEvent struct { + // The text generated related to the tool calls generated + Text *string `json:"text,omitempty" url:"text,omitempty"` ToolCalls []*ToolCall `json:"tool_calls,omitempty" url:"tool_calls,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatToolCallsGenerationEvent) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ChatToolCallsGenerationEvent) UnmarshalJSON(data []byte) error { @@ -1552,6 +1848,13 @@ func (c *ChatToolCallsGenerationEvent) UnmarshalJSON(data []byte) error { return err } *c = ChatToolCallsGenerationEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1573,7 +1876,12 @@ type CheckApiKeyResponse struct { OrganizationId *string `json:"organization_id,omitempty" url:"organization_id,omitempty"` OwnerId *string `json:"owner_id,omitempty" url:"owner_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CheckApiKeyResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CheckApiKeyResponse) UnmarshalJSON(data []byte) error { @@ -1583,6 +1891,13 @@ func (c *CheckApiKeyResponse) UnmarshalJSON(data []byte) error { return err } *c = CheckApiKeyResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1602,7 +1917,12 @@ func (c *CheckApiKeyResponse) String() string { type ClassifyDataMetrics struct { LabelMetrics []*LabelMetric `json:"label_metrics,omitempty" url:"label_metrics,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClassifyDataMetrics) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClassifyDataMetrics) UnmarshalJSON(data []byte) error { @@ -1612,6 +1932,13 @@ func (c *ClassifyDataMetrics) UnmarshalJSON(data []byte) error { return err } *c = ClassifyDataMetrics(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1632,7 +1959,12 @@ type ClassifyExample struct { Text *string `json:"text,omitempty" url:"text,omitempty"` Label *string `json:"label,omitempty" url:"label,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClassifyExample) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClassifyExample) UnmarshalJSON(data []byte) error { @@ -1642,6 +1974,13 @@ func (c *ClassifyExample) UnmarshalJSON(data []byte) error { return err } *c = ClassifyExample(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1691,7 +2030,12 @@ type ClassifyResponse struct { Classifications []*ClassifyResponseClassificationsItem `json:"classifications,omitempty" url:"classifications,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClassifyResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClassifyResponse) UnmarshalJSON(data []byte) error { @@ -1701,6 +2045,13 @@ func (c *ClassifyResponse) UnmarshalJSON(data []byte) error { return err } *c = ClassifyResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1734,7 +2085,12 @@ type ClassifyResponseClassificationsItem struct { // The type of classification performed ClassificationType ClassifyResponseClassificationsItemClassificationType `json:"classification_type" url:"classification_type"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClassifyResponseClassificationsItem) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClassifyResponseClassificationsItem) UnmarshalJSON(data []byte) error { @@ -1744,6 +2100,13 @@ func (c *ClassifyResponseClassificationsItem) UnmarshalJSON(data []byte) error { return err } *c = ClassifyResponseClassificationsItem(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1786,7 +2149,12 @@ func (c ClassifyResponseClassificationsItemClassificationType) Ptr() *ClassifyRe type ClassifyResponseClassificationsItemLabelsValue struct { Confidence *float64 `json:"confidence,omitempty" url:"confidence,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClassifyResponseClassificationsItemLabelsValue) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClassifyResponseClassificationsItemLabelsValue) UnmarshalJSON(data []byte) error { @@ -1796,6 +2164,13 @@ func (c *ClassifyResponseClassificationsItemLabelsValue) UnmarshalJSON(data []by return err } *c = ClassifyResponseClassificationsItemLabelsValue(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -1812,6 +2187,47 @@ func (c *ClassifyResponseClassificationsItemLabelsValue) String() string { return fmt.Sprintf("%#v", c) } +type ClientClosedRequestErrorBody struct { + Data *string `json:"data,omitempty" url:"data,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ClientClosedRequestErrorBody) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ClientClosedRequestErrorBody) UnmarshalJSON(data []byte) error { + type unmarshaler ClientClosedRequestErrorBody + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ClientClosedRequestErrorBody(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ClientClosedRequestErrorBody) 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) +} + // One of the Cohere API endpoints that the model can be used with. type CompatibleEndpoint string @@ -1882,7 +2298,12 @@ type Connector struct { // Whether a chat request should continue or not if the request to this connector fails. ContinueOnFailure *bool `json:"continue_on_failure,omitempty" url:"continue_on_failure,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *Connector) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *Connector) UnmarshalJSON(data []byte) error { @@ -1901,8 +2322,14 @@ func (c *Connector) UnmarshalJSON(data []byte) error { c.CreatedAt = unmarshaler.CreatedAt.Time() c.UpdatedAt = unmarshaler.UpdatedAt.Time() - c._rawJSON = json.RawMessage(data) - return nil + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil } func (c *Connector) MarshalJSON() ([]byte, error) { @@ -1966,7 +2393,12 @@ type ConnectorOAuth struct { // The OAuth scopes to request when users authorize the connector. Scope *string `json:"scope,omitempty" url:"scope,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ConnectorOAuth) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectorOAuth) UnmarshalJSON(data []byte) error { @@ -1976,6 +2408,13 @@ func (c *ConnectorOAuth) UnmarshalJSON(data []byte) error { return err } *c = ConnectorOAuth(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -2004,7 +2443,12 @@ type CreateConnectorOAuth struct { // The OAuth scopes to request when users authorize the connector. Scope *string `json:"scope,omitempty" url:"scope,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CreateConnectorOAuth) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CreateConnectorOAuth) UnmarshalJSON(data []byte) error { @@ -2014,6 +2458,13 @@ func (c *CreateConnectorOAuth) UnmarshalJSON(data []byte) error { return err } *c = CreateConnectorOAuth(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -2033,7 +2484,12 @@ func (c *CreateConnectorOAuth) String() string { type CreateConnectorResponse struct { Connector *Connector `json:"connector,omitempty" url:"connector,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CreateConnectorResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CreateConnectorResponse) UnmarshalJSON(data []byte) error { @@ -2043,6 +2499,13 @@ func (c *CreateConnectorResponse) UnmarshalJSON(data []byte) error { return err } *c = CreateConnectorResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -2064,7 +2527,12 @@ type CreateConnectorServiceAuth struct { // 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" url:"token"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CreateConnectorServiceAuth) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CreateConnectorServiceAuth) UnmarshalJSON(data []byte) error { @@ -2074,6 +2542,13 @@ func (c *CreateConnectorServiceAuth) UnmarshalJSON(data []byte) error { return err } *c = CreateConnectorServiceAuth(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -2095,7 +2570,12 @@ type CreateEmbedJobResponse struct { JobId string `json:"job_id" url:"job_id"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CreateEmbedJobResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CreateEmbedJobResponse) UnmarshalJSON(data []byte) error { @@ -2105,6 +2585,13 @@ func (c *CreateEmbedJobResponse) UnmarshalJSON(data []byte) error { return err } *c = CreateEmbedJobResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c._rawJSON = json.RawMessage(data) return nil } @@ -2143,7 +2630,12 @@ type Dataset struct { // warnings found during validation ValidationWarnings []string `json:"validation_warnings,omitempty" url:"validation_warnings,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *Dataset) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *Dataset) UnmarshalJSON(data []byte) error { @@ -2162,6 +2654,12 @@ func (d *Dataset) UnmarshalJSON(data []byte) error { d.CreatedAt = unmarshaler.CreatedAt.Time() d.UpdatedAt = unmarshaler.UpdatedAt.Time() + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -2210,7 +2708,12 @@ type DatasetPart struct { // The first few rows of the parsed file Samples []string `json:"samples,omitempty" url:"samples,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetPart) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetPart) UnmarshalJSON(data []byte) error { @@ -2220,6 +2723,13 @@ func (d *DatasetPart) UnmarshalJSON(data []byte) error { return err } *d = DatasetPart(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -2319,7 +2829,12 @@ type DetokenizeResponse struct { Text string `json:"text" url:"text"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DetokenizeResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DetokenizeResponse) UnmarshalJSON(data []byte) error { @@ -2329,6 +2844,13 @@ func (d *DetokenizeResponse) UnmarshalJSON(data []byte) error { return err } *d = DetokenizeResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil } @@ -2353,7 +2875,12 @@ type EmbedByTypeResponse struct { Texts []string `json:"texts,omitempty" url:"texts,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (e *EmbedByTypeResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EmbedByTypeResponse) UnmarshalJSON(data []byte) error { @@ -2363,6 +2890,13 @@ func (e *EmbedByTypeResponse) UnmarshalJSON(data []byte) error { return err } *e = EmbedByTypeResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e._rawJSON = json.RawMessage(data) return nil } @@ -2392,7 +2926,12 @@ type EmbedByTypeResponseEmbeddings struct { // An array of packed unsigned binary embeddings. The length of each binary embedding is 1/8 the length of the float embeddings of the provided model. Each value is between 0 and 255. Ubinary [][]int `json:"ubinary,omitempty" url:"ubinary,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (e *EmbedByTypeResponseEmbeddings) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EmbedByTypeResponseEmbeddings) UnmarshalJSON(data []byte) error { @@ -2402,6 +2941,13 @@ func (e *EmbedByTypeResponseEmbeddings) UnmarshalJSON(data []byte) error { return err } *e = EmbedByTypeResponseEmbeddings(value) + + extraProperties, err := core.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e._rawJSON = json.RawMessage(data) return nil } @@ -2426,7 +2972,12 @@ type EmbedFloatsResponse struct { Texts []string `json:"texts,omitempty" url:"texts,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (e *EmbedFloatsResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EmbedFloatsResponse) UnmarshalJSON(data []byte) error { @@ -2436,6 +2987,13 @@ func (e *EmbedFloatsResponse) UnmarshalJSON(data []byte) error { return err } *e = EmbedFloatsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e._rawJSON = json.RawMessage(data) return nil } @@ -2505,7 +3063,12 @@ type EmbedJob struct { Truncate EmbedJobTruncate `json:"truncate" url:"truncate"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (e *EmbedJob) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EmbedJob) UnmarshalJSON(data []byte) error { @@ -2522,6 +3085,12 @@ func (e *EmbedJob) UnmarshalJSON(data []byte) error { *e = EmbedJob(unmarshaler.embed) e.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := core.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e._rawJSON = json.RawMessage(data) return nil } @@ -2668,24 +3237,10 @@ func (e *EmbedResponse) UnmarshalJSON(data []byte) error { func (e EmbedResponse) MarshalJSON() ([]byte, error) { if e.EmbeddingsFloats != nil { - var marshaler = struct { - ResponseType string `json:"response_type"` - *EmbedFloatsResponse - }{ - ResponseType: "embeddings_floats", - EmbedFloatsResponse: e.EmbeddingsFloats, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(e.EmbeddingsFloats, "response_type", "embeddings_floats") } if e.EmbeddingsByType != nil { - var marshaler = struct { - ResponseType string `json:"response_type"` - *EmbedByTypeResponse - }{ - ResponseType: "embeddings_by_type", - EmbedByTypeResponse: e.EmbeddingsByType, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(e.EmbeddingsByType, "response_type", "embeddings_by_type") } return nil, fmt.Errorf("type %T does not define a non-empty union type", e) } @@ -2750,7 +3305,12 @@ type FinetuneDatasetMetrics struct { // The size in bytes of all eval examples. EvalSizeBytes *int64 `json:"eval_size_bytes,omitempty" url:"eval_size_bytes,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (f *FinetuneDatasetMetrics) GetExtraProperties() map[string]interface{} { + return f.extraProperties } func (f *FinetuneDatasetMetrics) UnmarshalJSON(data []byte) error { @@ -2760,6 +3320,13 @@ func (f *FinetuneDatasetMetrics) UnmarshalJSON(data []byte) error { return err } *f = FinetuneDatasetMetrics(value) + + extraProperties, err := core.ExtractExtraProperties(data, *f) + if err != nil { + return err + } + f.extraProperties = extraProperties + f._rawJSON = json.RawMessage(data) return nil } @@ -2779,18 +3346,21 @@ func (f *FinetuneDatasetMetrics) String() string { type FinishReason string const ( - FinishReasonComplete FinishReason = "COMPLETE" - FinishReasonError FinishReason = "ERROR" - FinishReasonErrorToxic FinishReason = "ERROR_TOXIC" - FinishReasonErrorLimit FinishReason = "ERROR_LIMIT" - FinishReasonUserCancel FinishReason = "USER_CANCEL" - FinishReasonMaxTokens FinishReason = "MAX_TOKENS" + FinishReasonComplete FinishReason = "COMPLETE" + FinishReasonStopSequence FinishReason = "STOP_SEQUENCE" + FinishReasonError FinishReason = "ERROR" + FinishReasonErrorToxic FinishReason = "ERROR_TOXIC" + FinishReasonErrorLimit FinishReason = "ERROR_LIMIT" + FinishReasonUserCancel FinishReason = "USER_CANCEL" + FinishReasonMaxTokens FinishReason = "MAX_TOKENS" ) func NewFinishReasonFromString(s string) (FinishReason, error) { switch s { case "COMPLETE": return FinishReasonComplete, nil + case "STOP_SEQUENCE": + return FinishReasonStopSequence, nil case "ERROR": return FinishReasonError, nil case "ERROR_TOXIC": @@ -2810,6 +3380,47 @@ func (f FinishReason) Ptr() *FinishReason { return &f } +type GatewayTimeoutErrorBody struct { + Data *string `json:"data,omitempty" url:"data,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GatewayTimeoutErrorBody) GetExtraProperties() map[string]interface{} { + return g.extraProperties +} + +func (g *GatewayTimeoutErrorBody) UnmarshalJSON(data []byte) error { + type unmarshaler GatewayTimeoutErrorBody + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *g = GatewayTimeoutErrorBody(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + + g._rawJSON = json.RawMessage(data) + return nil +} + +func (g *GatewayTimeoutErrorBody) 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) +} + // One of `GENERATION|ALL|NONE` to specify how and if the token likelihoods are returned with the response. Defaults to `NONE`. // // If `GENERATION` is selected, the token likelihoods will only be provided for generated text. @@ -2875,7 +3486,12 @@ type GenerateStreamEnd struct { FinishReason *FinishReason `json:"finish_reason,omitempty" url:"finish_reason,omitempty"` Response *GenerateStreamEndResponse `json:"response,omitempty" url:"response,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenerateStreamEnd) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GenerateStreamEnd) UnmarshalJSON(data []byte) error { @@ -2885,6 +3501,13 @@ func (g *GenerateStreamEnd) UnmarshalJSON(data []byte) error { return err } *g = GenerateStreamEnd(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -2906,7 +3529,12 @@ type GenerateStreamEndResponse struct { Prompt *string `json:"prompt,omitempty" url:"prompt,omitempty"` Generations []*SingleGenerationInStream `json:"generations,omitempty" url:"generations,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenerateStreamEndResponse) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GenerateStreamEndResponse) UnmarshalJSON(data []byte) error { @@ -2916,6 +3544,13 @@ func (g *GenerateStreamEndResponse) UnmarshalJSON(data []byte) error { return err } *g = GenerateStreamEndResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -2940,7 +3575,12 @@ type GenerateStreamError struct { // Error message Err string `json:"err" url:"err"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenerateStreamError) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GenerateStreamError) UnmarshalJSON(data []byte) error { @@ -2950,6 +3590,13 @@ func (g *GenerateStreamError) UnmarshalJSON(data []byte) error { return err } *g = GenerateStreamError(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -2967,7 +3614,12 @@ func (g *GenerateStreamError) String() string { } type GenerateStreamEvent struct { - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenerateStreamEvent) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GenerateStreamEvent) UnmarshalJSON(data []byte) error { @@ -2977,6 +3629,13 @@ func (g *GenerateStreamEvent) UnmarshalJSON(data []byte) error { return err } *g = GenerateStreamEvent(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -3060,7 +3719,12 @@ type GenerateStreamText struct { Index *int `json:"index,omitempty" url:"index,omitempty"` IsFinished bool `json:"is_finished" url:"is_finished"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenerateStreamText) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GenerateStreamText) UnmarshalJSON(data []byte) error { @@ -3070,6 +3734,13 @@ func (g *GenerateStreamText) UnmarshalJSON(data []byte) error { return err } *g = GenerateStreamText(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -3127,34 +3798,13 @@ func (g *GenerateStreamedResponse) UnmarshalJSON(data []byte) error { func (g GenerateStreamedResponse) MarshalJSON() ([]byte, error) { if g.TextGeneration != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *GenerateStreamText - }{ - EventType: "text-generation", - GenerateStreamText: g.TextGeneration, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(g.TextGeneration, "event_type", "text-generation") } if g.StreamEnd != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *GenerateStreamEnd - }{ - EventType: "stream-end", - GenerateStreamEnd: g.StreamEnd, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(g.StreamEnd, "event_type", "stream-end") } if g.StreamError != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *GenerateStreamError - }{ - EventType: "stream-error", - GenerateStreamError: g.StreamError, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(g.StreamError, "event_type", "stream-error") } return nil, fmt.Errorf("type %T does not define a non-empty union type", g) } @@ -3186,7 +3836,12 @@ type Generation struct { Generations []*SingleGeneration `json:"generations,omitempty" url:"generations,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *Generation) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *Generation) UnmarshalJSON(data []byte) error { @@ -3196,6 +3851,13 @@ func (g *Generation) UnmarshalJSON(data []byte) error { return err } *g = Generation(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -3215,7 +3877,12 @@ func (g *Generation) String() string { type GetConnectorResponse struct { Connector *Connector `json:"connector,omitempty" url:"connector,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GetConnectorResponse) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GetConnectorResponse) UnmarshalJSON(data []byte) error { @@ -3225,6 +3892,13 @@ func (g *GetConnectorResponse) UnmarshalJSON(data []byte) error { return err } *g = GetConnectorResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -3256,7 +3930,12 @@ type GetModelResponse struct { // The API endpoints that the model is default to. DefaultEndpoints []CompatibleEndpoint `json:"default_endpoints,omitempty" url:"default_endpoints,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GetModelResponse) GetExtraProperties() map[string]interface{} { + return g.extraProperties } func (g *GetModelResponse) UnmarshalJSON(data []byte) error { @@ -3266,6 +3945,13 @@ func (g *GetModelResponse) UnmarshalJSON(data []byte) error { return err } *g = GetModelResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + g._rawJSON = json.RawMessage(data) return nil } @@ -3290,7 +3976,12 @@ type LabelMetric struct { // samples for this label Samples []string `json:"samples,omitempty" url:"samples,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *LabelMetric) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *LabelMetric) UnmarshalJSON(data []byte) error { @@ -3300,6 +3991,13 @@ func (l *LabelMetric) UnmarshalJSON(data []byte) error { return err } *l = LabelMetric(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -3321,7 +4019,12 @@ type ListConnectorsResponse struct { // Total number of connectors. TotalCount *float64 `json:"total_count,omitempty" url:"total_count,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListConnectorsResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListConnectorsResponse) UnmarshalJSON(data []byte) error { @@ -3331,6 +4034,13 @@ func (l *ListConnectorsResponse) UnmarshalJSON(data []byte) error { return err } *l = ListConnectorsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -3350,7 +4060,12 @@ func (l *ListConnectorsResponse) String() string { type ListEmbedJobResponse struct { EmbedJobs []*EmbedJob `json:"embed_jobs,omitempty" url:"embed_jobs,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListEmbedJobResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListEmbedJobResponse) UnmarshalJSON(data []byte) error { @@ -3360,6 +4075,13 @@ func (l *ListEmbedJobResponse) UnmarshalJSON(data []byte) error { return err } *l = ListEmbedJobResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -3381,7 +4103,12 @@ type ListModelsResponse struct { // A token to retrieve the next page of results. Provide in the page_token parameter of the next request. NextPageToken *string `json:"next_page_token,omitempty" url:"next_page_token,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (l *ListModelsResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *ListModelsResponse) UnmarshalJSON(data []byte) error { @@ -3391,6 +4118,13 @@ func (l *ListModelsResponse) UnmarshalJSON(data []byte) error { return err } *l = ListModelsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l._rawJSON = json.RawMessage(data) return nil } @@ -3454,44 +4188,16 @@ func (m *Message) UnmarshalJSON(data []byte) error { func (m Message) MarshalJSON() ([]byte, error) { if m.Chatbot != nil { - var marshaler = struct { - Role string `json:"role"` - *ChatMessage - }{ - Role: "CHATBOT", - ChatMessage: m.Chatbot, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(m.Chatbot, "role", "CHATBOT") } if m.System != nil { - var marshaler = struct { - Role string `json:"role"` - *ChatMessage - }{ - Role: "SYSTEM", - ChatMessage: m.System, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(m.System, "role", "SYSTEM") } if m.User != nil { - var marshaler = struct { - Role string `json:"role"` - *ChatMessage - }{ - Role: "USER", - ChatMessage: m.User, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(m.User, "role", "USER") } if m.Tool != nil { - var marshaler = struct { - Role string `json:"role"` - *ToolMessage - }{ - Role: "TOOL", - ToolMessage: m.Tool, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(m.Tool, "role", "TOOL") } return nil, fmt.Errorf("type %T does not define a non-empty union type", m) } @@ -3523,7 +4229,12 @@ type Metrics struct { FinetuneDatasetMetrics *FinetuneDatasetMetrics `json:"finetune_dataset_metrics,omitempty" url:"finetune_dataset_metrics,omitempty"` EmbedData *MetricsEmbedData `json:"embed_data,omitempty" url:"embed_data,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (m *Metrics) GetExtraProperties() map[string]interface{} { + return m.extraProperties } func (m *Metrics) UnmarshalJSON(data []byte) error { @@ -3533,6 +4244,13 @@ func (m *Metrics) UnmarshalJSON(data []byte) error { return err } *m = Metrics(value) + + extraProperties, err := core.ExtractExtraProperties(data, *m) + if err != nil { + return err + } + m.extraProperties = extraProperties + m._rawJSON = json.RawMessage(data) return nil } @@ -3553,7 +4271,12 @@ type MetricsEmbedData struct { // the fields in the dataset Fields []*MetricsEmbedDataFieldsItem `json:"fields,omitempty" url:"fields,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (m *MetricsEmbedData) GetExtraProperties() map[string]interface{} { + return m.extraProperties } func (m *MetricsEmbedData) UnmarshalJSON(data []byte) error { @@ -3563,6 +4286,13 @@ func (m *MetricsEmbedData) UnmarshalJSON(data []byte) error { return err } *m = MetricsEmbedData(value) + + extraProperties, err := core.ExtractExtraProperties(data, *m) + if err != nil { + return err + } + m.extraProperties = extraProperties + m._rawJSON = json.RawMessage(data) return nil } @@ -3585,7 +4315,12 @@ type MetricsEmbedDataFieldsItem struct { // the number of times the field appears in the dataset Count *float64 `json:"count,omitempty" url:"count,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (m *MetricsEmbedDataFieldsItem) GetExtraProperties() map[string]interface{} { + return m.extraProperties } func (m *MetricsEmbedDataFieldsItem) UnmarshalJSON(data []byte) error { @@ -3595,6 +4330,13 @@ func (m *MetricsEmbedDataFieldsItem) UnmarshalJSON(data []byte) error { return err } *m = MetricsEmbedDataFieldsItem(value) + + extraProperties, err := core.ExtractExtraProperties(data, *m) + if err != nil { + return err + } + m.extraProperties = extraProperties + m._rawJSON = json.RawMessage(data) return nil } @@ -3634,7 +4376,12 @@ type NonStreamedChatResponse struct { Prompt *string `json:"prompt,omitempty" url:"prompt,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (n *NonStreamedChatResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NonStreamedChatResponse) UnmarshalJSON(data []byte) error { @@ -3644,6 +4391,13 @@ func (n *NonStreamedChatResponse) UnmarshalJSON(data []byte) error { return err } *n = NonStreamedChatResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n._rawJSON = json.RawMessage(data) return nil } @@ -3660,11 +4414,57 @@ func (n *NonStreamedChatResponse) String() string { return fmt.Sprintf("%#v", n) } +type NotImplementedErrorBody struct { + Data *string `json:"data,omitempty" url:"data,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (n *NotImplementedErrorBody) GetExtraProperties() map[string]interface{} { + return n.extraProperties +} + +func (n *NotImplementedErrorBody) UnmarshalJSON(data []byte) error { + type unmarshaler NotImplementedErrorBody + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *n = NotImplementedErrorBody(value) + + extraProperties, err := core.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + + n._rawJSON = json.RawMessage(data) + return nil +} + +func (n *NotImplementedErrorBody) String() string { + if len(n._rawJSON) > 0 { + if value, err := core.StringifyJSON(n._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(n); err == nil { + return value + } + return fmt.Sprintf("%#v", n) +} + 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" url:"redirect_url,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (o *OAuthAuthorizeResponse) GetExtraProperties() map[string]interface{} { + return o.extraProperties } func (o *OAuthAuthorizeResponse) UnmarshalJSON(data []byte) error { @@ -3674,6 +4474,13 @@ func (o *OAuthAuthorizeResponse) UnmarshalJSON(data []byte) error { return err } *o = OAuthAuthorizeResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *o) + if err != nil { + return err + } + o.extraProperties = extraProperties + o._rawJSON = json.RawMessage(data) return nil } @@ -3694,7 +4501,12 @@ type ParseInfo struct { Separator *string `json:"separator,omitempty" url:"separator,omitempty"` Delimiter *string `json:"delimiter,omitempty" url:"delimiter,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (p *ParseInfo) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *ParseInfo) UnmarshalJSON(data []byte) error { @@ -3704,6 +4516,13 @@ func (p *ParseInfo) UnmarshalJSON(data []byte) error { return err } *p = ParseInfo(value) + + extraProperties, err := core.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p._rawJSON = json.RawMessage(data) return nil } @@ -3768,7 +4587,12 @@ type RerankRequestDocumentsItemText struct { // The text of the document to rerank. Text string `json:"text" url:"text"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (r *RerankRequestDocumentsItemText) GetExtraProperties() map[string]interface{} { + return r.extraProperties } func (r *RerankRequestDocumentsItemText) UnmarshalJSON(data []byte) error { @@ -3778,6 +4602,13 @@ func (r *RerankRequestDocumentsItemText) UnmarshalJSON(data []byte) error { return err } *r = RerankRequestDocumentsItemText(value) + + extraProperties, err := core.ExtractExtraProperties(data, *r) + if err != nil { + return err + } + r.extraProperties = extraProperties + r._rawJSON = json.RawMessage(data) return nil } @@ -3800,7 +4631,12 @@ type RerankResponse struct { Results []*RerankResponseResultsItem `json:"results,omitempty" url:"results,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (r *RerankResponse) GetExtraProperties() map[string]interface{} { + return r.extraProperties } func (r *RerankResponse) UnmarshalJSON(data []byte) error { @@ -3810,6 +4646,13 @@ func (r *RerankResponse) UnmarshalJSON(data []byte) error { return err } *r = RerankResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *r) + if err != nil { + return err + } + r.extraProperties = extraProperties + r._rawJSON = json.RawMessage(data) return nil } @@ -3834,7 +4677,12 @@ type RerankResponseResultsItem struct { // Relevance scores are normalized to be in the range `[0, 1]`. Scores close to `1` indicate a high relevance to the query, and scores closer to `0` indicate low relevance. It is not accurate to assume a score of 0.9 means the document is 2x more relevant than a document with a score of 0.45 RelevanceScore float64 `json:"relevance_score" url:"relevance_score"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (r *RerankResponseResultsItem) GetExtraProperties() map[string]interface{} { + return r.extraProperties } func (r *RerankResponseResultsItem) UnmarshalJSON(data []byte) error { @@ -3844,6 +4692,13 @@ func (r *RerankResponseResultsItem) UnmarshalJSON(data []byte) error { return err } *r = RerankResponseResultsItem(value) + + extraProperties, err := core.ExtractExtraProperties(data, *r) + if err != nil { + return err + } + r.extraProperties = extraProperties + r._rawJSON = json.RawMessage(data) return nil } @@ -3865,7 +4720,12 @@ type RerankResponseResultsItemDocument struct { // The text of the document to rerank Text string `json:"text" url:"text"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (r *RerankResponseResultsItemDocument) GetExtraProperties() map[string]interface{} { + return r.extraProperties } func (r *RerankResponseResultsItemDocument) UnmarshalJSON(data []byte) error { @@ -3875,6 +4735,13 @@ func (r *RerankResponseResultsItemDocument) UnmarshalJSON(data []byte) error { return err } *r = RerankResponseResultsItemDocument(value) + + extraProperties, err := core.ExtractExtraProperties(data, *r) + if err != nil { + return err + } + r.extraProperties = extraProperties + r._rawJSON = json.RawMessage(data) return nil } @@ -3905,7 +4772,12 @@ type RerankerDataMetrics struct { // The sum of all hard negatives of valid eval examples. NumEvalHardNegatives *int64 `json:"num_eval_hard_negatives,omitempty" url:"num_eval_hard_negatives,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (r *RerankerDataMetrics) GetExtraProperties() map[string]interface{} { + return r.extraProperties } func (r *RerankerDataMetrics) UnmarshalJSON(data []byte) error { @@ -3915,6 +4787,13 @@ func (r *RerankerDataMetrics) UnmarshalJSON(data []byte) error { return err } *r = RerankerDataMetrics(value) + + extraProperties, err := core.ExtractExtraProperties(data, *r) + if err != nil { + return err + } + r.extraProperties = extraProperties + r._rawJSON = json.RawMessage(data) return nil } @@ -3940,7 +4819,12 @@ type SingleGeneration struct { // Only returned if `return_likelihoods` is set to `GENERATION` or `ALL`. The likelihood refers to the average log-likelihood of the entire specified string, which is useful for [evaluating the performance of your model](likelihood-eval), especially if you've created a [custom model](/docs/training-custom-models). Individual token likelihoods provide the log-likelihood of each token. The first token will not have a likelihood. TokenLikelihoods []*SingleGenerationTokenLikelihoodsItem `json:"token_likelihoods,omitempty" url:"token_likelihoods,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (s *SingleGeneration) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SingleGeneration) UnmarshalJSON(data []byte) error { @@ -3950,6 +4834,13 @@ func (s *SingleGeneration) UnmarshalJSON(data []byte) error { return err } *s = SingleGeneration(value) + + extraProperties, err := core.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s._rawJSON = json.RawMessage(data) return nil } @@ -3974,7 +4865,12 @@ type SingleGenerationInStream struct { Index *int `json:"index,omitempty" url:"index,omitempty"` FinishReason FinishReason `json:"finish_reason" url:"finish_reason"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (s *SingleGenerationInStream) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SingleGenerationInStream) UnmarshalJSON(data []byte) error { @@ -3984,6 +4880,13 @@ func (s *SingleGenerationInStream) UnmarshalJSON(data []byte) error { return err } *s = SingleGenerationInStream(value) + + extraProperties, err := core.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s._rawJSON = json.RawMessage(data) return nil } @@ -4004,7 +4907,12 @@ type SingleGenerationTokenLikelihoodsItem struct { Token string `json:"token" url:"token"` Likelihood float64 `json:"likelihood" url:"likelihood"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (s *SingleGenerationTokenLikelihoodsItem) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SingleGenerationTokenLikelihoodsItem) UnmarshalJSON(data []byte) error { @@ -4014,6 +4922,13 @@ func (s *SingleGenerationTokenLikelihoodsItem) UnmarshalJSON(data []byte) error return err } *s = SingleGenerationTokenLikelihoodsItem(value) + + extraProperties, err := core.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s._rawJSON = json.RawMessage(data) return nil } @@ -4040,6 +4955,7 @@ type StreamedChatResponse struct { CitationGeneration *ChatCitationGenerationEvent ToolCallsGeneration *ChatToolCallsGenerationEvent StreamEnd *ChatStreamEndEvent + ToolCallsChunk *ChatToolCallsChunkEvent } func (s *StreamedChatResponse) UnmarshalJSON(data []byte) error { @@ -4093,80 +5009,40 @@ func (s *StreamedChatResponse) UnmarshalJSON(data []byte) error { return err } s.StreamEnd = value + case "tool-calls-chunk": + value := new(ChatToolCallsChunkEvent) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + s.ToolCallsChunk = value } return nil } func (s StreamedChatResponse) MarshalJSON() ([]byte, error) { if s.StreamStart != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatStreamStartEvent - }{ - EventType: "stream-start", - ChatStreamStartEvent: s.StreamStart, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.StreamStart, "event_type", "stream-start") } if s.SearchQueriesGeneration != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatSearchQueriesGenerationEvent - }{ - EventType: "search-queries-generation", - ChatSearchQueriesGenerationEvent: s.SearchQueriesGeneration, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.SearchQueriesGeneration, "event_type", "search-queries-generation") } if s.SearchResults != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatSearchResultsEvent - }{ - EventType: "search-results", - ChatSearchResultsEvent: s.SearchResults, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.SearchResults, "event_type", "search-results") } if s.TextGeneration != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatTextGenerationEvent - }{ - EventType: "text-generation", - ChatTextGenerationEvent: s.TextGeneration, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.TextGeneration, "event_type", "text-generation") } if s.CitationGeneration != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatCitationGenerationEvent - }{ - EventType: "citation-generation", - ChatCitationGenerationEvent: s.CitationGeneration, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.CitationGeneration, "event_type", "citation-generation") } if s.ToolCallsGeneration != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatToolCallsGenerationEvent - }{ - EventType: "tool-calls-generation", - ChatToolCallsGenerationEvent: s.ToolCallsGeneration, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.ToolCallsGeneration, "event_type", "tool-calls-generation") } if s.StreamEnd != nil { - var marshaler = struct { - EventType string `json:"event_type"` - *ChatStreamEndEvent - }{ - EventType: "stream-end", - ChatStreamEndEvent: s.StreamEnd, - } - return json.Marshal(marshaler) + return core.MarshalJSONWithExtraProperty(s.StreamEnd, "event_type", "stream-end") + } + if s.ToolCallsChunk != nil { + return core.MarshalJSONWithExtraProperty(s.ToolCallsChunk, "event_type", "tool-calls-chunk") } return nil, fmt.Errorf("type %T does not define a non-empty union type", s) } @@ -4179,6 +5055,7 @@ type StreamedChatResponseVisitor interface { VisitCitationGeneration(*ChatCitationGenerationEvent) error VisitToolCallsGeneration(*ChatToolCallsGenerationEvent) error VisitStreamEnd(*ChatStreamEndEvent) error + VisitToolCallsChunk(*ChatToolCallsChunkEvent) error } func (s *StreamedChatResponse) Accept(visitor StreamedChatResponseVisitor) error { @@ -4203,6 +5080,9 @@ func (s *StreamedChatResponse) Accept(visitor StreamedChatResponseVisitor) error if s.StreamEnd != nil { return visitor.VisitStreamEnd(s.StreamEnd) } + if s.ToolCallsChunk != nil { + return visitor.VisitToolCallsChunk(s.ToolCallsChunk) + } return fmt.Errorf("type %T does not define a non-empty union type", s) } @@ -4288,7 +5168,12 @@ type SummarizeResponse struct { Summary *string `json:"summary,omitempty" url:"summary,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (s *SummarizeResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SummarizeResponse) UnmarshalJSON(data []byte) error { @@ -4298,6 +5183,13 @@ func (s *SummarizeResponse) UnmarshalJSON(data []byte) error { return err } *s = SummarizeResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s._rawJSON = json.RawMessage(data) return nil } @@ -4320,7 +5212,12 @@ type TokenizeResponse struct { TokenStrings []string `json:"token_strings,omitempty" url:"token_strings,omitempty"` Meta *ApiMeta `json:"meta,omitempty" url:"meta,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *TokenizeResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *TokenizeResponse) UnmarshalJSON(data []byte) error { @@ -4330,6 +5227,13 @@ func (t *TokenizeResponse) UnmarshalJSON(data []byte) error { return err } *t = TokenizeResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4349,7 +5253,12 @@ func (t *TokenizeResponse) String() string { type TooManyRequestsErrorBody struct { Data *string `json:"data,omitempty" url:"data,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *TooManyRequestsErrorBody) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *TooManyRequestsErrorBody) UnmarshalJSON(data []byte) error { @@ -4359,6 +5268,13 @@ func (t *TooManyRequestsErrorBody) UnmarshalJSON(data []byte) error { return err } *t = TooManyRequestsErrorBody(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4395,7 +5311,12 @@ type Tool struct { // ``` ParameterDefinitions map[string]*ToolParameterDefinitionsValue `json:"parameter_definitions,omitempty" url:"parameter_definitions,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *Tool) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *Tool) UnmarshalJSON(data []byte) error { @@ -4405,6 +5326,13 @@ func (t *Tool) UnmarshalJSON(data []byte) error { return err } *t = Tool(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4428,7 +5356,12 @@ type ToolCall struct { // The name and value of the parameters to use when invoking a tool. Parameters map[string]interface{} `json:"parameters,omitempty" url:"parameters,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *ToolCall) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ToolCall) UnmarshalJSON(data []byte) error { @@ -4438,6 +5371,13 @@ func (t *ToolCall) UnmarshalJSON(data []byte) error { return err } *t = ToolCall(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4454,11 +5394,65 @@ func (t *ToolCall) String() string { return fmt.Sprintf("%#v", t) } +// Contains the chunk of the tool call generation in the stream. +type ToolCallDelta struct { + // Name of the tool call + Name *string `json:"name,omitempty" url:"name,omitempty"` + // Index of the tool call generated + Index *float64 `json:"index,omitempty" url:"index,omitempty"` + // Chunk of the tool parameters + Parameters *string `json:"parameters,omitempty" url:"parameters,omitempty"` + // Chunk of the tool plan text + Text *string `json:"text,omitempty" url:"text,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *ToolCallDelta) GetExtraProperties() map[string]interface{} { + return t.extraProperties +} + +func (t *ToolCallDelta) UnmarshalJSON(data []byte) error { + type unmarshaler ToolCallDelta + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *t = ToolCallDelta(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + + t._rawJSON = json.RawMessage(data) + return nil +} + +func (t *ToolCallDelta) String() string { + if len(t._rawJSON) > 0 { + if value, err := core.StringifyJSON(t._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(t); err == nil { + return value + } + return fmt.Sprintf("%#v", t) +} + // Represents tool result in the chat history. type ToolMessage struct { ToolResults []*ToolResult `json:"tool_results,omitempty" url:"tool_results,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *ToolMessage) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ToolMessage) UnmarshalJSON(data []byte) error { @@ -4468,6 +5462,13 @@ func (t *ToolMessage) UnmarshalJSON(data []byte) error { return err } *t = ToolMessage(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4492,7 +5493,12 @@ type ToolParameterDefinitionsValue struct { // Denotes whether the parameter is always present (required) or not. Defaults to not required. Required *bool `json:"required,omitempty" url:"required,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *ToolParameterDefinitionsValue) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ToolParameterDefinitionsValue) UnmarshalJSON(data []byte) error { @@ -4502,6 +5508,13 @@ func (t *ToolParameterDefinitionsValue) UnmarshalJSON(data []byte) error { return err } *t = ToolParameterDefinitionsValue(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4522,7 +5535,12 @@ type ToolResult struct { Call *ToolCall `json:"call,omitempty" url:"call,omitempty"` Outputs []map[string]interface{} `json:"outputs,omitempty" url:"outputs,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *ToolResult) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ToolResult) UnmarshalJSON(data []byte) error { @@ -4532,6 +5550,13 @@ func (t *ToolResult) UnmarshalJSON(data []byte) error { return err } *t = ToolResult(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t._rawJSON = json.RawMessage(data) return nil } @@ -4548,10 +5573,56 @@ func (t *ToolResult) String() string { return fmt.Sprintf("%#v", t) } +type UnprocessableEntityErrorBody struct { + Data *string `json:"data,omitempty" url:"data,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (u *UnprocessableEntityErrorBody) GetExtraProperties() map[string]interface{} { + return u.extraProperties +} + +func (u *UnprocessableEntityErrorBody) UnmarshalJSON(data []byte) error { + type unmarshaler UnprocessableEntityErrorBody + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *u = UnprocessableEntityErrorBody(value) + + extraProperties, err := core.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + + u._rawJSON = json.RawMessage(data) + return nil +} + +func (u *UnprocessableEntityErrorBody) 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 UpdateConnectorResponse struct { Connector *Connector `json:"connector,omitempty" url:"connector,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (u *UpdateConnectorResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UpdateConnectorResponse) UnmarshalJSON(data []byte) error { @@ -4561,6 +5632,13 @@ func (u *UpdateConnectorResponse) UnmarshalJSON(data []byte) error { return err } *u = UpdateConnectorResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u._rawJSON = json.RawMessage(data) return nil } @@ -4587,7 +5665,12 @@ type DatasetsCreateResponseDatasetPartsItem struct { // the kind of dataset part PartKind *string `json:"part_kind,omitempty" url:"part_kind,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (d *DatasetsCreateResponseDatasetPartsItem) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DatasetsCreateResponseDatasetPartsItem) UnmarshalJSON(data []byte) error { @@ -4597,6 +5680,13 @@ func (d *DatasetsCreateResponseDatasetPartsItem) UnmarshalJSON(data []byte) erro return err } *d = DatasetsCreateResponseDatasetPartsItem(value) + + extraProperties, err := core.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d._rawJSON = json.RawMessage(data) return nil }