diff --git a/core/request_option.go b/core/request_option.go index dee627b..4ce0dc1 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -61,7 +61,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.12.2") + headers.Set("X-Fern-SDK-Version", "v2.12.3") return headers } diff --git a/finetuning.go b/finetuning.go index fdacc91..368ba4c 100644 --- a/finetuning.go +++ b/finetuning.go @@ -63,7 +63,7 @@ type FinetuningUpdateFinetunedModelRequest struct { UpdatedAt *time.Time `json:"updated_at,omitempty" url:"-"` // Timestamp for the completed fine-tuning. CompletedAt *time.Time `json:"completed_at,omitempty" url:"-"` - // Timestamp for the latest request to this fine-tuned model. + // Deprecated: Timestamp for the latest request to this fine-tuned model. LastUsed *time.Time `json:"last_used,omitempty" url:"-"` } diff --git a/finetuning/types.go b/finetuning/types.go index e1d3c71..3b828c0 100644 --- a/finetuning/types.go +++ b/finetuning/types.go @@ -227,7 +227,7 @@ type FinetunedModel struct { UpdatedAt *time.Time `json:"updated_at,omitempty" url:"updated_at,omitempty"` // read-only. Timestamp for the completed fine-tuning. CompletedAt *time.Time `json:"completed_at,omitempty" url:"completed_at,omitempty"` - // read-only. Timestamp for the latest request to this fine-tuned model. + // read-only. Deprecated: Timestamp for the latest request to this fine-tuned model. LastUsed *time.Time `json:"last_used,omitempty" url:"last_used,omitempty"` extraProperties map[string]interface{} @@ -687,7 +687,7 @@ func (s Status) Ptr() *Status { // // - STRATEGY_UNSPECIFIED: Unspecified strategy. // - STRATEGY_VANILLA: Deprecated: Serve the fine-tuned model on a dedicated GPU. -// - STRATEGY_TFEW: Serve the fine-tuned model on a shared GPU. +// - STRATEGY_TFEW: Deprecated: Serve the fine-tuned model on a shared GPU. type Strategy string const ( diff --git a/types.go b/types.go index 398a4f4..ee700b1 100644 --- a/types.go +++ b/types.go @@ -206,6 +206,8 @@ type ChatRequest struct { // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/docs/command-r-plus#august-2024-release) and newer. // + // **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. + // // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments SafetyMode *ChatRequestSafetyMode `json:"safety_mode,omitempty" url:"-"` stream bool @@ -435,6 +437,8 @@ type ChatStreamRequest struct { // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/docs/command-r-plus#august-2024-release) and newer. // + // **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. + // // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments SafetyMode *ChatStreamRequestSafetyMode `json:"safety_mode,omitempty" url:"-"` stream bool @@ -592,11 +596,11 @@ type GenerateRequest struct { // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. 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`. + // One of `GENERATION|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. + // WARNING: `ALL` is deprecated, and will be removed in a future release. 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:"-"` @@ -691,11 +695,11 @@ type GenerateStreamRequest struct { // // Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. 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`. + // One of `GENERATION|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. + // WARNING: `ALL` is deprecated, and will be removed in a future release. 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:"-"` @@ -730,7 +734,7 @@ 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` + // The identifier of the model to use, eg `rerank-v3.5`. Model *string `json:"model,omitempty" url:"-"` // The search query Query string `json:"query" url:"-"` @@ -2361,6 +2365,8 @@ func (c ChatRequestPromptTruncation) Ptr() *ChatRequestPromptTruncation { // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/docs/command-r-plus#august-2024-release) and newer. // +// **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. +// // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments type ChatRequestSafetyMode string @@ -2945,6 +2951,8 @@ func (c ChatStreamRequestPromptTruncation) Ptr() *ChatStreamRequestPromptTruncat // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/docs/command-r-plus#august-2024-release) and newer. // +// **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. +// // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments type ChatStreamRequestSafetyMode string @@ -3099,7 +3107,7 @@ func (c *ChatToolCallDeltaEvent) String() string { } type ChatToolCallDeltaEventDelta struct { - ToolCall *ChatToolCallDeltaEventDeltaToolCall `json:"tool_call,omitempty" url:"tool_call,omitempty"` + Message *ChatToolCallDeltaEventDeltaMessage `json:"message,omitempty" url:"message,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -3139,24 +3147,24 @@ func (c *ChatToolCallDeltaEventDelta) String() string { return fmt.Sprintf("%#v", c) } -type ChatToolCallDeltaEventDeltaToolCall struct { - Function *ChatToolCallDeltaEventDeltaToolCallFunction `json:"function,omitempty" url:"function,omitempty"` +type ChatToolCallDeltaEventDeltaMessage struct { + ToolCalls *ChatToolCallDeltaEventDeltaMessageToolCalls `json:"tool_calls,omitempty" url:"tool_calls,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallDeltaEventDeltaToolCall) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallDeltaEventDeltaMessage) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallDeltaEventDeltaToolCall) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallDeltaEventDeltaToolCall +func (c *ChatToolCallDeltaEventDeltaMessage) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallDeltaEventDeltaMessage var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallDeltaEventDeltaToolCall(value) + *c = ChatToolCallDeltaEventDeltaMessage(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3168,7 +3176,7 @@ func (c *ChatToolCallDeltaEventDeltaToolCall) UnmarshalJSON(data []byte) error { return nil } -func (c *ChatToolCallDeltaEventDeltaToolCall) String() string { +func (c *ChatToolCallDeltaEventDeltaMessage) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3180,24 +3188,24 @@ func (c *ChatToolCallDeltaEventDeltaToolCall) String() string { return fmt.Sprintf("%#v", c) } -type ChatToolCallDeltaEventDeltaToolCallFunction struct { - Arguments *string `json:"arguments,omitempty" url:"arguments,omitempty"` +type ChatToolCallDeltaEventDeltaMessageToolCalls struct { + Function *ChatToolCallDeltaEventDeltaMessageToolCallsFunction `json:"function,omitempty" url:"function,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallDeltaEventDeltaToolCallFunction) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallDeltaEventDeltaMessageToolCalls) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallDeltaEventDeltaToolCallFunction) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallDeltaEventDeltaToolCallFunction +func (c *ChatToolCallDeltaEventDeltaMessageToolCalls) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallDeltaEventDeltaMessageToolCalls var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallDeltaEventDeltaToolCallFunction(value) + *c = ChatToolCallDeltaEventDeltaMessageToolCalls(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3209,7 +3217,7 @@ func (c *ChatToolCallDeltaEventDeltaToolCallFunction) UnmarshalJSON(data []byte) return nil } -func (c *ChatToolCallDeltaEventDeltaToolCallFunction) String() string { +func (c *ChatToolCallDeltaEventDeltaMessageToolCalls) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3221,25 +3229,24 @@ func (c *ChatToolCallDeltaEventDeltaToolCallFunction) String() string { return fmt.Sprintf("%#v", c) } -// A streamed event delta which signifies a tool call has finished streaming. -type ChatToolCallEndEvent struct { - Index *int `json:"index,omitempty" url:"index,omitempty"` +type ChatToolCallDeltaEventDeltaMessageToolCallsFunction struct { + Arguments *string `json:"arguments,omitempty" url:"arguments,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallEndEvent) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallDeltaEventDeltaMessageToolCallsFunction) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallEndEvent) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallEndEvent +func (c *ChatToolCallDeltaEventDeltaMessageToolCallsFunction) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallDeltaEventDeltaMessageToolCallsFunction var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallEndEvent(value) + *c = ChatToolCallDeltaEventDeltaMessageToolCallsFunction(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3251,7 +3258,7 @@ func (c *ChatToolCallEndEvent) UnmarshalJSON(data []byte) error { return nil } -func (c *ChatToolCallEndEvent) String() string { +func (c *ChatToolCallDeltaEventDeltaMessageToolCallsFunction) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3263,26 +3270,25 @@ func (c *ChatToolCallEndEvent) String() string { return fmt.Sprintf("%#v", c) } -// A streamed event delta which signifies a tool call has started streaming. -type ChatToolCallStartEvent struct { - Index *int `json:"index,omitempty" url:"index,omitempty"` - Delta *ChatToolCallStartEventDelta `json:"delta,omitempty" url:"delta,omitempty"` +// A streamed event delta which signifies a tool call has finished streaming. +type ChatToolCallEndEvent struct { + Index *int `json:"index,omitempty" url:"index,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallStartEvent) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallEndEvent) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallStartEvent) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallStartEvent +func (c *ChatToolCallEndEvent) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallEndEvent var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallStartEvent(value) + *c = ChatToolCallEndEvent(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3294,7 +3300,7 @@ func (c *ChatToolCallStartEvent) UnmarshalJSON(data []byte) error { return nil } -func (c *ChatToolCallStartEvent) String() string { +func (c *ChatToolCallEndEvent) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3306,24 +3312,26 @@ func (c *ChatToolCallStartEvent) String() string { return fmt.Sprintf("%#v", c) } -type ChatToolCallStartEventDelta struct { - ToolCall *ChatToolCallStartEventDeltaToolCall `json:"tool_call,omitempty" url:"tool_call,omitempty"` +// A streamed event delta which signifies a tool call has started streaming. +type ChatToolCallStartEvent struct { + Index *int `json:"index,omitempty" url:"index,omitempty"` + Delta *ChatToolCallStartEventDelta `json:"delta,omitempty" url:"delta,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallStartEventDelta) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallStartEvent) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallStartEventDelta) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallStartEventDelta +func (c *ChatToolCallStartEvent) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallStartEvent var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallStartEventDelta(value) + *c = ChatToolCallStartEvent(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3335,7 +3343,7 @@ func (c *ChatToolCallStartEventDelta) UnmarshalJSON(data []byte) error { return nil } -func (c *ChatToolCallStartEventDelta) String() string { +func (c *ChatToolCallStartEvent) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3347,26 +3355,24 @@ func (c *ChatToolCallStartEventDelta) String() string { return fmt.Sprintf("%#v", c) } -type ChatToolCallStartEventDeltaToolCall struct { - Id *string `json:"id,omitempty" url:"id,omitempty"` - Type *string `json:"type,omitempty" url:"type,omitempty"` - Function *ChatToolCallStartEventDeltaToolCallFunction `json:"function,omitempty" url:"function,omitempty"` +type ChatToolCallStartEventDelta struct { + Message *ChatToolCallStartEventDeltaMessage `json:"message,omitempty" url:"message,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallStartEventDeltaToolCall) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallStartEventDelta) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallStartEventDeltaToolCall) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallStartEventDeltaToolCall +func (c *ChatToolCallStartEventDelta) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallStartEventDelta var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallStartEventDeltaToolCall(value) + *c = ChatToolCallStartEventDelta(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3378,7 +3384,7 @@ func (c *ChatToolCallStartEventDeltaToolCall) UnmarshalJSON(data []byte) error { return nil } -func (c *ChatToolCallStartEventDeltaToolCall) String() string { +func (c *ChatToolCallStartEventDelta) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3390,25 +3396,24 @@ func (c *ChatToolCallStartEventDeltaToolCall) String() string { return fmt.Sprintf("%#v", c) } -type ChatToolCallStartEventDeltaToolCallFunction struct { - Name *string `json:"name,omitempty" url:"name,omitempty"` - Arguments *string `json:"arguments,omitempty" url:"arguments,omitempty"` +type ChatToolCallStartEventDeltaMessage struct { + ToolCalls *ToolCallV2 `json:"tool_calls,omitempty" url:"tool_calls,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage } -func (c *ChatToolCallStartEventDeltaToolCallFunction) GetExtraProperties() map[string]interface{} { +func (c *ChatToolCallStartEventDeltaMessage) GetExtraProperties() map[string]interface{} { return c.extraProperties } -func (c *ChatToolCallStartEventDeltaToolCallFunction) UnmarshalJSON(data []byte) error { - type unmarshaler ChatToolCallStartEventDeltaToolCallFunction +func (c *ChatToolCallStartEventDeltaMessage) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolCallStartEventDeltaMessage var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *c = ChatToolCallStartEventDeltaToolCallFunction(value) + *c = ChatToolCallStartEventDeltaMessage(value) extraProperties, err := core.ExtractExtraProperties(data, *c) if err != nil { @@ -3420,7 +3425,7 @@ func (c *ChatToolCallStartEventDeltaToolCallFunction) UnmarshalJSON(data []byte) return nil } -func (c *ChatToolCallStartEventDeltaToolCallFunction) String() string { +func (c *ChatToolCallStartEventDeltaMessage) String() string { if len(c._rawJSON) > 0 { if value, err := core.StringifyJSON(c._rawJSON); err == nil { return value @@ -3560,7 +3565,7 @@ func (c *ChatToolPlanDeltaEvent) String() string { } type ChatToolPlanDeltaEventDelta struct { - ToolPlan *string `json:"tool_plan,omitempty" url:"tool_plan,omitempty"` + Message *ChatToolPlanDeltaEventDeltaMessage `json:"message,omitempty" url:"message,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -3600,6 +3605,47 @@ func (c *ChatToolPlanDeltaEventDelta) String() string { return fmt.Sprintf("%#v", c) } +type ChatToolPlanDeltaEventDeltaMessage struct { + ToolPlan *string `json:"tool_plan,omitempty" url:"tool_plan,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ChatToolPlanDeltaEventDeltaMessage) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ChatToolPlanDeltaEventDeltaMessage) UnmarshalJSON(data []byte) error { + type unmarshaler ChatToolPlanDeltaEventDeltaMessage + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ChatToolPlanDeltaEventDeltaMessage(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ChatToolPlanDeltaEventDeltaMessage) 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 CheckApiKeyResponse struct { Valid bool `json:"valid" url:"valid"` OrganizationId *string `json:"organization_id,omitempty" url:"organization_id,omitempty"` @@ -3737,6 +3783,8 @@ func (c *CitationEndEvent) String() string { type CitationOptions struct { // 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, `"fast"` results or no results. + // + // **Note**: `command-r7b-12-2024` only supports `"fast"` and `"off"` modes. Its default is `"fast"`. Mode *CitationOptionsMode `json:"mode,omitempty" url:"mode,omitempty"` extraProperties map[string]interface{} @@ -3779,6 +3827,8 @@ func (c *CitationOptions) String() string { // 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, `"fast"` results or no results. +// +// **Note**: `command-r7b-12-2024` only supports `"fast"` and `"off"` modes. Its default is `"fast"`. type CitationOptionsMode string const ( @@ -5626,11 +5676,11 @@ func (g *GatewayTimeoutErrorBody) String() string { 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`. +// One of `GENERATION|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. +// WARNING: `ALL` is deprecated, and will be removed in a future release. type GenerateRequestReturnLikelihoods string const ( @@ -5857,11 +5907,11 @@ func (g *GenerateStreamEvent) String() string { 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`. +// One of `GENERATION|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. +// WARNING: `ALL` is deprecated, and will be removed in a future release. type GenerateStreamRequestReturnLikelihoods string const ( @@ -7697,6 +7747,7 @@ type StreamedChatResponseV2 struct { CitationStart *CitationStartEvent CitationEnd *CitationEndEvent MessageEnd *ChatMessageEndEvent + Debug *ChatDebugEvent } func (s *StreamedChatResponseV2) UnmarshalJSON(data []byte) error { @@ -7777,6 +7828,12 @@ func (s *StreamedChatResponseV2) UnmarshalJSON(data []byte) error { return err } s.MessageEnd = value + case "debug": + value := new(ChatDebugEvent) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + s.Debug = value } return nil } @@ -7815,6 +7872,9 @@ func (s StreamedChatResponseV2) MarshalJSON() ([]byte, error) { if s.MessageEnd != nil { return core.MarshalJSONWithExtraProperty(s.MessageEnd, "type", "message-end") } + if s.Debug != nil { + return core.MarshalJSONWithExtraProperty(s.Debug, "type", "debug") + } return nil, fmt.Errorf("type %T does not define a non-empty union type", s) } @@ -7830,6 +7890,7 @@ type StreamedChatResponseV2Visitor interface { VisitCitationStart(*CitationStartEvent) error VisitCitationEnd(*CitationEndEvent) error VisitMessageEnd(*ChatMessageEndEvent) error + VisitDebug(*ChatDebugEvent) error } func (s *StreamedChatResponseV2) Accept(visitor StreamedChatResponseV2Visitor) error { @@ -7866,6 +7927,9 @@ func (s *StreamedChatResponseV2) Accept(visitor StreamedChatResponseV2Visitor) e if s.MessageEnd != nil { return visitor.VisitMessageEnd(s.MessageEnd) } + if s.Debug != nil { + return visitor.VisitDebug(s.Debug) + } return fmt.Errorf("type %T does not define a non-empty union type", s) } diff --git a/v_2.go b/v_2.go index 62581f8..1d2f02f 100644 --- a/v_2.go +++ b/v_2.go @@ -9,6 +9,14 @@ import ( ) type V2ChatRequest struct { + // Defaults to `false`. + // + // When `true`, the response will be a SSE stream of events. The final event will contain the complete response, and will have an `event_type` of `"stream-end"`. + // + // Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated. + // + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments + // // The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model. Model string `json:"model" url:"-"` Messages ChatMessages `json:"messages,omitempty" url:"-"` @@ -16,6 +24,10 @@ type V2ChatRequest struct { // // When `tools` is passed (without `tool_results`), the `text` content in the response will be empty 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. Tools []*ToolV2 `json:"tools,omitempty" url:"-"` + // When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools). + // + // **Note**: The first few requests with a new set of tools will take longer to process. + StrictTools *bool `json:"strict_tools,omitempty" url:"-"` // A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata. Documents []*V2ChatRequestDocumentsItem `json:"documents,omitempty" url:"-"` CitationOptions *CitationOptions `json:"citation_options,omitempty" url:"-"` @@ -26,6 +38,8 @@ type V2ChatRequest struct { // Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters. // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer. + // + // **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. SafetyMode *V2ChatRequestSafetyMode `json:"safety_mode,omitempty" url:"-"` // The maximum number of tokens the model will generate as part of the response. // @@ -58,7 +72,7 @@ type V2ChatRequest struct { P *float64 `json:"p,omitempty" url:"-"` // Whether to return the prompt in the response. ReturnPrompt *bool `json:"return_prompt,omitempty" url:"-"` - // Whether to return the log probabilities of the generated tokens. Defaults to false. + // Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response. Logprobs *bool `json:"logprobs,omitempty" url:"-"` stream bool } @@ -91,6 +105,14 @@ func (v *V2ChatRequest) MarshalJSON() ([]byte, error) { } type V2ChatStreamRequest struct { + // Defaults to `false`. + // + // When `true`, the response will be a SSE stream of events. The final event will contain the complete response, and will have an `event_type` of `"stream-end"`. + // + // Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated. + // + // Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments + // // The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model. Model string `json:"model" url:"-"` Messages ChatMessages `json:"messages,omitempty" url:"-"` @@ -98,6 +120,10 @@ type V2ChatStreamRequest struct { // // When `tools` is passed (without `tool_results`), the `text` content in the response will be empty 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. Tools []*ToolV2 `json:"tools,omitempty" url:"-"` + // When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools). + // + // **Note**: The first few requests with a new set of tools will take longer to process. + StrictTools *bool `json:"strict_tools,omitempty" url:"-"` // A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata. Documents []*V2ChatStreamRequestDocumentsItem `json:"documents,omitempty" url:"-"` CitationOptions *CitationOptions `json:"citation_options,omitempty" url:"-"` @@ -108,6 +134,8 @@ type V2ChatStreamRequest struct { // Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters. // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer. + // + // **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. SafetyMode *V2ChatStreamRequestSafetyMode `json:"safety_mode,omitempty" url:"-"` // The maximum number of tokens the model will generate as part of the response. // @@ -140,7 +168,7 @@ type V2ChatStreamRequest struct { P *float64 `json:"p,omitempty" url:"-"` // Whether to return the prompt in the response. ReturnPrompt *bool `json:"return_prompt,omitempty" url:"-"` - // Whether to return the log probabilities of the generated tokens. Defaults to false. + // Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response. Logprobs *bool `json:"logprobs,omitempty" url:"-"` stream bool } @@ -195,7 +223,7 @@ type V2EmbedRequest struct { // * `embed-multilingual-v2.0` 768 Model string `json:"model" url:"-"` InputType EmbedInputType `json:"input_type" 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. + // Specifies the types of embeddings you want to get back. Can be one or more of the following types. // // * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models. // * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models. @@ -212,26 +240,24 @@ type V2EmbedRequest struct { } type V2RerankRequest 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` + // The identifier of the model to use, eg `rerank-v3.5`. Model string `json:"model" url:"-"` // The search 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. + // A list of texts that will be compared to the `query`. + // For optimal performance we recommend against sending more than 1,000 documents in a single request. // - // The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000. + // **Note**: long documents will automatically be truncated to the value of `max_tokens_per_doc`. // - // We recommend a maximum of 1,000 documents for optimal endpoint performance. - Documents []*V2RerankRequestDocumentsItem `json:"documents,omitempty" url:"-"` - // The number of most relevant documents or indices to return, defaults to the length of the documents + // **Note**: structured data should be formatted as YAML strings for best performance. + Documents []string `json:"documents,omitempty" url:"-"` + // Limits the number of returned rerank results to the specified value. If not passed, all the rerank results will be returned. 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:"-"` // - 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:"-"` - // The maximum number of chunks to produce internally from a document - MaxChunksPerDoc *int `json:"max_chunks_per_doc,omitempty" url:"-"` + // Defaults to `4096`. Long documents will be automatically truncated to the specified number of tokens. + MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty" url:"-"` } type V2ChatRequestDocumentsItem struct { @@ -284,6 +310,8 @@ func (v *V2ChatRequestDocumentsItem) Accept(visitor V2ChatRequestDocumentsItemVi // Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters. // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer. +// +// **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. type V2ChatRequestSafetyMode string const ( @@ -359,6 +387,8 @@ func (v *V2ChatStreamRequestDocumentsItem) Accept(visitor V2ChatStreamRequestDoc // Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters. // // **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer. +// +// **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes. type V2ChatStreamRequestSafetyMode string const ( @@ -414,50 +444,6 @@ func (v V2EmbedRequestTruncate) Ptr() *V2EmbedRequestTruncate { return &v } -type V2RerankRequestDocumentsItem struct { - String string - RerankDocument RerankDocument -} - -func (v *V2RerankRequestDocumentsItem) UnmarshalJSON(data []byte) error { - var valueString string - if err := json.Unmarshal(data, &valueString); err == nil { - v.String = valueString - return nil - } - var valueRerankDocument RerankDocument - if err := json.Unmarshal(data, &valueRerankDocument); err == nil { - v.RerankDocument = valueRerankDocument - return nil - } - return fmt.Errorf("%s cannot be deserialized as a %T", data, v) -} - -func (v V2RerankRequestDocumentsItem) MarshalJSON() ([]byte, error) { - if v.String != "" { - return json.Marshal(v.String) - } - if v.RerankDocument != nil { - return json.Marshal(v.RerankDocument) - } - return nil, fmt.Errorf("type %T does not include a non-empty union type", v) -} - -type V2RerankRequestDocumentsItemVisitor interface { - VisitString(string) error - VisitRerankDocument(RerankDocument) error -} - -func (v *V2RerankRequestDocumentsItem) Accept(visitor V2RerankRequestDocumentsItemVisitor) error { - if v.String != "" { - return visitor.VisitString(v.String) - } - if v.RerankDocument != nil { - return visitor.VisitRerankDocument(v.RerankDocument) - } - return fmt.Errorf("type %T does not include a non-empty union type", v) -} - type V2RerankResponse struct { Id *string `json:"id,omitempty" url:"id,omitempty"` // An ordered list of ranked documents