From 98393d9ad5d6cc5bffa6311922cefdb98ea2cc12 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:31:16 +0000 Subject: [PATCH] SDK regeneration --- client/client.go | 44 ++--- connectors/client.go | 24 +-- core/request_option.go | 2 +- datasets/client.go | 20 +- embedjobs/client.go | 16 +- environments.go | 2 +- finetuning/client/client.go | 28 +-- finetuning/types.go | 49 +++++ models/client.go | 8 +- types.go | 367 +++++++++++++++++------------------- 10 files changed, 290 insertions(+), 270 deletions(-) diff --git a/client/client.go b/client/client.go index 1bc0110..0cdbbd5 100644 --- a/client/client.go +++ b/client/client.go @@ -63,14 +63,14 @@ func (c *Client) ChatStream( ) (*core.Stream[v2.StreamedChatResponse], error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/chat" + endpointURL := baseURL + "/v1/chat" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -187,14 +187,14 @@ func (c *Client) Chat( ) (*v2.NonStreamedChatResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/chat" + endpointURL := baseURL + "/v1/chat" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -318,14 +318,14 @@ func (c *Client) GenerateStream( ) (*core.Stream[v2.GenerateStreamedResponse], error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/generate" + endpointURL := baseURL + "/v1/generate" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -445,14 +445,14 @@ func (c *Client) Generate( ) (*v2.Generation, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/generate" + endpointURL := baseURL + "/v1/generate" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -576,14 +576,14 @@ func (c *Client) Embed( ) (*v2.EmbedResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/embed" + endpointURL := baseURL + "/v1/embed" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -703,14 +703,14 @@ func (c *Client) Rerank( ) (*v2.RerankResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/rerank" + endpointURL := baseURL + "/v1/rerank" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -831,14 +831,14 @@ func (c *Client) Classify( ) (*v2.ClassifyResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/classify" + endpointURL := baseURL + "/v1/classify" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -962,14 +962,14 @@ func (c *Client) Summarize( ) (*v2.SummarizeResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/summarize" + endpointURL := baseURL + "/v1/summarize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -1089,14 +1089,14 @@ func (c *Client) Tokenize( ) (*v2.TokenizeResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/tokenize" + endpointURL := baseURL + "/v1/tokenize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -1216,14 +1216,14 @@ func (c *Client) Detokenize( ) (*v2.DetokenizeResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/detokenize" + endpointURL := baseURL + "/v1/detokenize" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -1342,14 +1342,14 @@ func (c *Client) CheckApiKey( ) (*v2.CheckApiKeyResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/check-api-key" + endpointURL := baseURL + "/v1/check-api-key" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) diff --git a/connectors/client.go b/connectors/client.go index dce1176..40827ab 100644 --- a/connectors/client.go +++ b/connectors/client.go @@ -46,14 +46,14 @@ func (c *Client) List( ) (*v2.ListConnectorsResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/connectors" + endpointURL := baseURL + "/v1/connectors" queryParams, err := core.QueryValues(request) if err != nil { @@ -180,14 +180,14 @@ func (c *Client) Create( ) (*v2.CreateConnectorResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/connectors" + endpointURL := baseURL + "/v1/connectors" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -308,14 +308,14 @@ func (c *Client) Get( ) (*v2.GetConnectorResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -435,14 +435,14 @@ func (c *Client) Delete( ) (v2.DeleteConnectorResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -563,14 +563,14 @@ func (c *Client) Update( ) (*v2.UpdateConnectorResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/connectors/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/connectors/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -692,14 +692,14 @@ func (c *Client) OAuthAuthorize( ) (*v2.OAuthAuthorizeResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/connectors/%v/oauth/authorize", id) + endpointURL := core.EncodeURL(baseURL+"/v1/connectors/%v/oauth/authorize", id) queryParams, err := core.QueryValues(request) if err != nil { diff --git a/core/request_option.go b/core/request_option.go index 69bdfcb..55c7c6c 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.9.0") + headers.Set("X-Fern-SDK-Version", "v2.10.0") return headers } diff --git a/datasets/client.go b/datasets/client.go index 9b57ef8..a3e300c 100644 --- a/datasets/client.go +++ b/datasets/client.go @@ -47,14 +47,14 @@ func (c *Client) List( ) (*v2.DatasetsListResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/datasets" + endpointURL := baseURL + "/v1/datasets" queryParams, err := core.QueryValues(request) if err != nil { @@ -183,14 +183,14 @@ func (c *Client) Create( ) (*v2.DatasetsCreateResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/datasets" + endpointURL := baseURL + "/v1/datasets" queryParams, err := core.QueryValues(request) if err != nil { @@ -348,14 +348,14 @@ func (c *Client) GetUsage( ) (*v2.DatasetsGetUsageResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/datasets/usage" + endpointURL := baseURL + "/v1/datasets/usage" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -474,14 +474,14 @@ func (c *Client) Get( ) (*v2.DatasetsGetResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/datasets/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/datasets/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -600,14 +600,14 @@ func (c *Client) Delete( ) (map[string]interface{}, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/datasets/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/datasets/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) diff --git a/embedjobs/client.go b/embedjobs/client.go index ee60a05..2c7fde8 100644 --- a/embedjobs/client.go +++ b/embedjobs/client.go @@ -45,14 +45,14 @@ func (c *Client) List( ) (*v2.ListEmbedJobResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/embed-jobs" + endpointURL := baseURL + "/v1/embed-jobs" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -171,14 +171,14 @@ func (c *Client) Create( ) (*v2.CreateEmbedJobResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/embed-jobs" + endpointURL := baseURL + "/v1/embed-jobs" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -299,14 +299,14 @@ func (c *Client) Get( ) (*v2.EmbedJob, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/embed-jobs/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/embed-jobs/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -426,14 +426,14 @@ func (c *Client) Cancel( ) error { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/embed-jobs/%v/cancel", id) + endpointURL := core.EncodeURL(baseURL+"/v1/embed-jobs/%v/cancel", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) diff --git a/environments.go b/environments.go index 1acfc88..50aa841 100644 --- a/environments.go +++ b/environments.go @@ -9,5 +9,5 @@ package api var Environments = struct { Production string }{ - Production: "https://api.cohere.com/v1", + Production: "https://api.cohere.com", } diff --git a/finetuning/client/client.go b/finetuning/client/client.go index 29aaba7..fde2f0e 100644 --- a/finetuning/client/client.go +++ b/finetuning/client/client.go @@ -46,14 +46,14 @@ func (c *Client) ListFinetunedModels( ) (*finetuning.ListFinetunedModelsResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/finetuning/finetuned-models" + endpointURL := baseURL + "/v1/finetuning/finetuned-models" queryParams, err := core.QueryValues(request) if err != nil { @@ -144,14 +144,14 @@ func (c *Client) CreateFinetunedModel( ) (*finetuning.CreateFinetunedModelResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/finetuning/finetuned-models" + endpointURL := baseURL + "/v1/finetuning/finetuned-models" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -236,14 +236,14 @@ func (c *Client) GetFinetunedModel( ) (*finetuning.GetFinetunedModelResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -327,14 +327,14 @@ func (c *Client) DeleteFinetunedModel( ) (finetuning.DeleteFinetunedModelResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -419,14 +419,14 @@ func (c *Client) UpdateFinetunedModel( ) (*finetuning.UpdateFinetunedModelResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v", id) + endpointURL := core.EncodeURL(baseURL+"/v1/finetuning/finetuned-models/%v", id) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -512,14 +512,14 @@ func (c *Client) ListEvents( ) (*finetuning.ListEventsResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v/events", finetunedModelId) + endpointURL := core.EncodeURL(baseURL+"/v1/finetuning/finetuned-models/%v/events", finetunedModelId) queryParams, err := core.QueryValues(request) if err != nil { @@ -612,14 +612,14 @@ func (c *Client) ListTrainingStepMetrics( ) (*finetuning.ListTrainingStepMetricsResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/finetuning/finetuned-models/%v/training-step-metrics", finetunedModelId) + endpointURL := core.EncodeURL(baseURL+"/v1/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 14b1f23..f01ac32 100644 --- a/finetuning/types.go +++ b/finetuning/types.go @@ -546,6 +546,8 @@ type Settings struct { Hyperparameters *Hyperparameters `json:"hyperparameters,omitempty" url:"hyperparameters,omitempty"` // read-only. Whether the model is single-label or multi-label (only for classification). MultiLabel *bool `json:"multi_label,omitempty" url:"multi_label,omitempty"` + // The Weights & Biases configuration. + Wandb *WandbConfig `json:"wandb,omitempty" url:"wandb,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -776,3 +778,50 @@ func (u *UpdateFinetunedModelResponse) String() string { } return fmt.Sprintf("%#v", u) } + +// The Weights & Biases configuration. +type WandbConfig struct { + // The WandB project name to be used during training. + Project string `json:"project" url:"project"` + // The WandB API key to be used during training. + ApiKey string `json:"api_key" url:"api_key"` + // The WandB entity name to be used during training. + Entity *string `json:"entity,omitempty" url:"entity,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (w *WandbConfig) GetExtraProperties() map[string]interface{} { + return w.extraProperties +} + +func (w *WandbConfig) UnmarshalJSON(data []byte) error { + type unmarshaler WandbConfig + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *w = WandbConfig(value) + + extraProperties, err := core.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + + w._rawJSON = json.RawMessage(data) + return nil +} + +func (w *WandbConfig) String() string { + if len(w._rawJSON) > 0 { + if value, err := core.StringifyJSON(w._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(w); err == nil { + return value + } + return fmt.Sprintf("%#v", w) +} diff --git a/models/client.go b/models/client.go index 4e2acf9..88bdd06 100644 --- a/models/client.go +++ b/models/client.go @@ -46,14 +46,14 @@ func (c *Client) Get( ) (*v2.GetModelResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/models/%v", model) + endpointURL := core.EncodeURL(baseURL+"/v1/models/%v", model) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -172,14 +172,14 @@ func (c *Client) List( ) (*v2.ListModelsResponse, error) { options := core.NewRequestOptions(opts...) - baseURL := "https://api.cohere.com/v1" + baseURL := "https://api.cohere.com" if c.baseURL != "" { baseURL = c.baseURL } if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := baseURL + "/models" + endpointURL := baseURL + "/v1/models" queryParams, err := core.QueryValues(request) if err != nil { diff --git a/types.go b/types.go index 95061ab..752e7d9 100644 --- a/types.go +++ b/types.go @@ -55,7 +55,7 @@ type ChatRequest struct { 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). + // When specified, the model's reply will be enriched with information found by querying each of the connectors (RAG). // Compatible Deployments: Cohere Platform Connectors []*ChatConnector `json:"connectors,omitempty" url:"-"` // Defaults to `false`. @@ -168,16 +168,9 @@ type ChatRequest struct { // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments 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:"-"` - // Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models. - // - // The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`. - // - // A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure. - // - // **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length. - ResponseFormat *ChatRequestResponseFormat `json:"response_format,omitempty" url:"-"` - stream bool + ForceSingleStep *bool `json:"force_single_step,omitempty" url:"-"` + ResponseFormat *ResponseFormat `json:"response_format,omitempty" url:"-"` + stream bool } func (c *ChatRequest) Stream() bool { @@ -253,7 +246,7 @@ type ChatStreamRequest struct { 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). + // When specified, the model's reply will be enriched with information found by querying each of the connectors (RAG). // Compatible Deployments: Cohere Platform Connectors []*ChatConnector `json:"connectors,omitempty" url:"-"` // Defaults to `false`. @@ -366,16 +359,9 @@ type ChatStreamRequest struct { // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments 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:"-"` - // Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models. - // - // The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`. - // - // A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure. - // - // **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length. - ResponseFormat *ChatStreamRequestResponseFormat `json:"response_format,omitempty" url:"-"` - stream bool + ForceSingleStep *bool `json:"force_single_step,omitempty" url:"-"` + ResponseFormat *ResponseFormat `json:"response_format,omitempty" url:"-"` + stream bool } func (c *ChatStreamRequest) Stream() bool { @@ -1268,94 +1254,6 @@ func (c ChatRequestPromptTruncation) Ptr() *ChatRequestPromptTruncation { return &c } -// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models. -// -// The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`. -// -// A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure. -// -// **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length. -type ChatRequestResponseFormat struct { - // When set to JSON, the model will return valid JSON. Note that running out of tokens will result in an invalid JSON. - Type ChatRequestResponseFormatType `json:"type" url:"type"` - // [BETA] A JSON schema object that the output will adhere to. There are some restrictions we have on the schema, refer to [our guide]() for more information. - // Example (required name and age object): - // - // ```json - // - // { - // "type": "object", - // "properties": { - // "name": { "type": "string" }, - // "age": { "type": "integer" } - // }, - // "required": ["name", "age"] - // } - // - // ``` - Schema map[string]interface{} `json:"schema,omitempty" url:"schema,omitempty"` - - extraProperties map[string]interface{} - _rawJSON json.RawMessage -} - -func (c *ChatRequestResponseFormat) GetExtraProperties() map[string]interface{} { - return c.extraProperties -} - -func (c *ChatRequestResponseFormat) UnmarshalJSON(data []byte) error { - type unmarshaler ChatRequestResponseFormat - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *c = ChatRequestResponseFormat(value) - - extraProperties, err := core.ExtractExtraProperties(data, *c) - if err != nil { - return err - } - c.extraProperties = extraProperties - - c._rawJSON = json.RawMessage(data) - return nil -} - -func (c *ChatRequestResponseFormat) 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) -} - -// When set to JSON, the model will return valid JSON. Note that running out of tokens will result in an invalid JSON. -type ChatRequestResponseFormatType string - -const ( - ChatRequestResponseFormatTypeText ChatRequestResponseFormatType = "text" - ChatRequestResponseFormatTypeJsonObject ChatRequestResponseFormatType = "json_object" -) - -func NewChatRequestResponseFormatTypeFromString(s string) (ChatRequestResponseFormatType, error) { - switch s { - case "text": - return ChatRequestResponseFormatTypeText, nil - case "json_object": - return ChatRequestResponseFormatTypeJsonObject, nil - } - var t ChatRequestResponseFormatType - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (c ChatRequestResponseFormatType) Ptr() *ChatRequestResponseFormatType { - return &c -} - 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"` @@ -1813,94 +1711,6 @@ func (c ChatStreamRequestPromptTruncation) Ptr() *ChatStreamRequestPromptTruncat return &c } -// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models. -// -// The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`. -// -// A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure. -// -// **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length. -type ChatStreamRequestResponseFormat struct { - // When set to JSON, the model will return valid JSON. Note that running out of tokens will result in an invalid JSON. - Type ChatStreamRequestResponseFormatType `json:"type" url:"type"` - // [BETA] A JSON schema object that the output will adhere to. There are some restrictions we have on the schema, refer to [our guide]() for more information. - // Example (required name and age object): - // - // ```json - // - // { - // "type": "object", - // "properties": { - // "name": { "type": "string" }, - // "age": { "type": "integer" } - // }, - // "required": ["name", "age"] - // } - // - // ``` - Schema map[string]interface{} `json:"schema,omitempty" url:"schema,omitempty"` - - extraProperties map[string]interface{} - _rawJSON json.RawMessage -} - -func (c *ChatStreamRequestResponseFormat) GetExtraProperties() map[string]interface{} { - return c.extraProperties -} - -func (c *ChatStreamRequestResponseFormat) UnmarshalJSON(data []byte) error { - type unmarshaler ChatStreamRequestResponseFormat - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *c = ChatStreamRequestResponseFormat(value) - - extraProperties, err := core.ExtractExtraProperties(data, *c) - if err != nil { - return err - } - c.extraProperties = extraProperties - - c._rawJSON = json.RawMessage(data) - return nil -} - -func (c *ChatStreamRequestResponseFormat) 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) -} - -// When set to JSON, the model will return valid JSON. Note that running out of tokens will result in an invalid JSON. -type ChatStreamRequestResponseFormatType string - -const ( - ChatStreamRequestResponseFormatTypeText ChatStreamRequestResponseFormatType = "text" - ChatStreamRequestResponseFormatTypeJsonObject ChatStreamRequestResponseFormatType = "json_object" -) - -func NewChatStreamRequestResponseFormatTypeFromString(s string) (ChatStreamRequestResponseFormatType, error) { - switch s { - case "text": - return ChatStreamRequestResponseFormatTypeText, nil - case "json_object": - return ChatStreamRequestResponseFormatTypeJsonObject, nil - } - var t ChatStreamRequestResponseFormatType - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (c ChatStreamRequestResponseFormatType) Ptr() *ChatStreamRequestResponseFormatType { - return &c -} - type ChatStreamStartEvent struct { // Unique identifier for the generated reply. Useful for submitting feedback. GenerationId string `json:"generation_id" url:"generation_id"` @@ -4166,6 +3976,64 @@ func (g *GetModelResponse) String() string { return fmt.Sprintf("%#v", g) } +type JsonResponseFormat struct { + // [BETA] A JSON schema object that the output will adhere to. There are some restrictions we have on the schema, refer to [our guide](/docs/structured-outputs-json#schema-constraints) for more information. + // Example (required name and age object): + // + // ```json + // + // { + // "type": "object", + // "properties": { + // "name": { "type": "string" }, + // "age": { "type": "integer" } + // }, + // "required": ["name", "age"] + // } + // + // ``` + // + // **Note**: This field must not be specified when the `type` is set to `"text"`. + Schema map[string]interface{} `json:"schema,omitempty" url:"schema,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (j *JsonResponseFormat) GetExtraProperties() map[string]interface{} { + return j.extraProperties +} + +func (j *JsonResponseFormat) UnmarshalJSON(data []byte) error { + type unmarshaler JsonResponseFormat + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *j = JsonResponseFormat(value) + + extraProperties, err := core.ExtractExtraProperties(data, *j) + if err != nil { + return err + } + j.extraProperties = extraProperties + + j._rawJSON = json.RawMessage(data) + return nil +} + +func (j *JsonResponseFormat) String() string { + if len(j._rawJSON) > 0 { + if value, err := core.StringifyJSON(j._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(j); err == nil { + return value + } + return fmt.Sprintf("%#v", j) +} + type LabelMetric struct { // Total number of examples for this label TotalExamples *int64 `json:"total_examples,omitempty" url:"total_examples,omitempty"` @@ -4968,6 +4836,70 @@ func (r *RerankerDataMetrics) String() string { return fmt.Sprintf("%#v", r) } +// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models. +// +// The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`. +// +// A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure. +// +// **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length. +// **Limitation**: The parameter is not supported in RAG mode (when any of `connectors`, `documents`, `tools`, `tool_results` are provided). +type ResponseFormat struct { + Type string + Text *TextResponseFormat + JsonObject *JsonResponseFormat +} + +func (r *ResponseFormat) UnmarshalJSON(data []byte) error { + var unmarshaler struct { + Type string `json:"type"` + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + r.Type = unmarshaler.Type + switch unmarshaler.Type { + case "text": + value := new(TextResponseFormat) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + r.Text = value + case "json_object": + value := new(JsonResponseFormat) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + r.JsonObject = value + } + return nil +} + +func (r ResponseFormat) MarshalJSON() ([]byte, error) { + if r.Text != nil { + return core.MarshalJSONWithExtraProperty(r.Text, "type", "text") + } + if r.JsonObject != nil { + return core.MarshalJSONWithExtraProperty(r.JsonObject, "type", "json_object") + } + return nil, fmt.Errorf("type %T does not define a non-empty union type", r) +} + +type ResponseFormatVisitor interface { + VisitText(*TextResponseFormat) error + VisitJsonObject(*JsonResponseFormat) error +} + +func (r *ResponseFormat) Accept(visitor ResponseFormatVisitor) error { + if r.Text != nil { + return visitor.VisitText(r.Text) + } + if r.JsonObject != nil { + return visitor.VisitJsonObject(r.JsonObject) + } + return fmt.Errorf("type %T does not define a non-empty union type", r) +} + type SingleGeneration struct { Id string `json:"id" url:"id"` Text string `json:"text" url:"text"` @@ -5364,6 +5296,45 @@ func (s *SummarizeResponse) String() string { return fmt.Sprintf("%#v", s) } +type TextResponseFormat struct { + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (t *TextResponseFormat) GetExtraProperties() map[string]interface{} { + return t.extraProperties +} + +func (t *TextResponseFormat) UnmarshalJSON(data []byte) error { + type unmarshaler TextResponseFormat + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *t = TextResponseFormat(value) + + extraProperties, err := core.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + + t._rawJSON = json.RawMessage(data) + return nil +} + +func (t *TextResponseFormat) 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) +} + type TokenizeResponse struct { // An array of tokens, where each token is an integer. Tokens []int `json:"tokens,omitempty" url:"tokens,omitempty"`