diff --git a/internal/protoveneer/cmd/protoveneer/protoveneer.go b/internal/protoveneer/cmd/protoveneer/protoveneer.go index d34ba8b01a8..a0bcba76ce1 100644 --- a/internal/protoveneer/cmd/protoveneer/protoveneer.go +++ b/internal/protoveneer/cmd/protoveneer/protoveneer.go @@ -797,6 +797,12 @@ var externalTypes = []*externalType{ convertTo: "support.MapToStructPB", convertFrom: "support.MapFromStructPB", }, + { + qualifiedName: "any", + replaces: "*structpb.Value", + convertTo: "support.MapToValuePB", + convertFrom: "support.MapFromValuePB", + }, } var protoTypeToExternalType = map[string]*externalType{} diff --git a/vertexai/genai/aiplatformpb_veneer.gen.go b/vertexai/genai/aiplatformpb_veneer.gen.go index a8879083f95..f75c3464bbf 100644 --- a/vertexai/genai/aiplatformpb_veneer.gen.go +++ b/vertexai/genai/aiplatformpb_veneer.gen.go @@ -24,13 +24,14 @@ import ( "cloud.google.com/go/vertexai/internal/support" ) -// Blob contains raw media bytes. +// Blob contains content blob. // -// Text should not be sent as raw bytes, use the 'text' field. +// It's preferred to send as [text][google.cloud.aiplatform.v1beta1.Part.text] +// directly rather than raw bytes. type Blob struct { // Required. The IANA standard MIME type of the source data. MIMEType string - // Required. Raw bytes for media formats. + // Required. Raw bytes. Data []byte } @@ -64,12 +65,19 @@ const ( BlockedReasonSafety BlockedReason = 1 // BlockedReasonOther means candidates blocked due to other reason. BlockedReasonOther BlockedReason = 2 + // BlockedReasonBlocklist means candidates blocked due to the terms which are included from the + // terminology blocklist. + BlockedReasonBlocklist BlockedReason = 3 + // BlockedReasonProhibitedContent means candidates blocked due to prohibited content. + BlockedReasonProhibitedContent BlockedReason = 4 ) var namesForBlockedReason = map[BlockedReason]string{ - BlockedReasonUnspecified: "BlockedReasonUnspecified", - BlockedReasonSafety: "BlockedReasonSafety", - BlockedReasonOther: "BlockedReasonOther", + BlockedReasonUnspecified: "BlockedReasonUnspecified", + BlockedReasonSafety: "BlockedReasonSafety", + BlockedReasonOther: "BlockedReasonOther", + BlockedReasonBlocklist: "BlockedReasonBlocklist", + BlockedReasonProhibitedContent: "BlockedReasonProhibitedContent", } func (v BlockedReason) String() string { @@ -379,8 +387,8 @@ func (FunctionCall) fromProto(p *pb.FunctionCall) *FunctionCall { type FunctionDeclaration struct { // Required. The name of the function to call. // Must start with a letter or an underscore. - // Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum - // length of 64. + // Must be a-z, A-Z, 0-9, or contain underscores, dots and dashes, with a + // maximum length of 64. Name string // Optional. Description and purpose of the function. // Model uses it to decide how and whether to call the function. @@ -389,8 +397,10 @@ type FunctionDeclaration struct { // format. Reflects the Open API 3.03 Parameter Object. string Key: the name // of the parameter. Parameter names are case sensitive. Schema Value: the // Schema defining the type used for the parameter. For function with no - // parameters, this can be left unset. Example with 1 required and 1 optional - // parameter: type: OBJECT properties: + // parameters, this can be left unset. Parameter names must start with a + // letter or an underscore and must only contain chars a-z, A-Z, 0-9, or + // underscores with a maximum length of 64. Example with 1 required and 1 + // optional parameter: type: OBJECT properties: // // param1: // type: STRING @@ -400,6 +410,10 @@ type FunctionDeclaration struct { // required: // - param1 Parameters *Schema + // Optional. Describes the output from this function in JSON Schema format. + // Reflects the Open API 3.03 Response Object. The Schema defines the type + // used for the response value of the function. + Response *Schema } func (v *FunctionDeclaration) toProto() *pb.FunctionDeclaration { @@ -410,6 +424,7 @@ func (v *FunctionDeclaration) toProto() *pb.FunctionDeclaration { Name: v.Name, Description: v.Description, Parameters: v.Parameters.toProto(), + Response: v.Response.toProto(), } } @@ -421,6 +436,7 @@ func (FunctionDeclaration) fromProto(p *pb.FunctionDeclaration) *FunctionDeclara Name: p.Name, Description: p.Description, Parameters: (Schema{}).fromProto(p.Parameters), + Response: (Schema{}).fromProto(p.Response), } } @@ -504,6 +520,18 @@ type GenerationConfig struct { MaxOutputTokens *int32 // Optional. Stop sequences. StopSequences []string + // Optional. Positive penalties. + PresencePenalty *float32 + // Optional. Frequency penalties. + FrequencyPenalty *float32 + // Optional. Output response mimetype of the generated candidate text. + // Supported mimetype: + // - `text/plain`: (default) Text output. + // - `application/json`: JSON response in the candidates. + // The model needs to be prompted to output the appropriate response type, + // otherwise the behavior is undefined. + // This is a preview feature. + ResponseMimeType string } func (v *GenerationConfig) toProto() *pb.GenerationConfig { @@ -511,12 +539,15 @@ func (v *GenerationConfig) toProto() *pb.GenerationConfig { return nil } return &pb.GenerationConfig{ - Temperature: v.Temperature, - TopP: v.TopP, - TopK: int32pToFloat32p(v.TopK), - CandidateCount: v.CandidateCount, - MaxOutputTokens: v.MaxOutputTokens, - StopSequences: v.StopSequences, + Temperature: v.Temperature, + TopP: v.TopP, + TopK: int32pToFloat32p(v.TopK), + CandidateCount: v.CandidateCount, + MaxOutputTokens: v.MaxOutputTokens, + StopSequences: v.StopSequences, + PresencePenalty: v.PresencePenalty, + FrequencyPenalty: v.FrequencyPenalty, + ResponseMimeType: v.ResponseMimeType, } } @@ -525,15 +556,43 @@ func (GenerationConfig) fromProto(p *pb.GenerationConfig) *GenerationConfig { return nil } return &GenerationConfig{ - Temperature: p.Temperature, - TopP: p.TopP, - TopK: float32pToInt32p(p.TopK), - CandidateCount: p.CandidateCount, - MaxOutputTokens: p.MaxOutputTokens, - StopSequences: p.StopSequences, + Temperature: p.Temperature, + TopP: p.TopP, + TopK: float32pToInt32p(p.TopK), + CandidateCount: p.CandidateCount, + MaxOutputTokens: p.MaxOutputTokens, + StopSequences: p.StopSequences, + PresencePenalty: p.PresencePenalty, + FrequencyPenalty: p.FrequencyPenalty, + ResponseMimeType: p.ResponseMimeType, } } +// HarmBlockMethod specifies probability vs severity. +type HarmBlockMethod int32 + +const ( + // HarmBlockMethodSafetysettingHarmBlockMethodUnspecified means the harm block method is unspecified. + HarmBlockMethodSafetysettingHarmBlockMethodUnspecified HarmBlockMethod = 0 + // HarmBlockMethodSafetysettingSeverity means the harm block method uses both probability and severity scores. + HarmBlockMethodSafetysettingSeverity HarmBlockMethod = 1 + // HarmBlockMethodSafetysettingProbability means the harm block method uses the probability score. + HarmBlockMethodSafetysettingProbability HarmBlockMethod = 2 +) + +var namesForHarmBlockMethod = map[HarmBlockMethod]string{ + HarmBlockMethodSafetysettingHarmBlockMethodUnspecified: "HarmBlockMethodSafetysettingHarmBlockMethodUnspecified", + HarmBlockMethodSafetysettingSeverity: "HarmBlockMethodSafetysettingSeverity", + HarmBlockMethodSafetysettingProbability: "HarmBlockMethodSafetysettingProbability", +} + +func (v HarmBlockMethod) String() string { + if n, ok := namesForHarmBlockMethod[v]; ok { + return n + } + return fmt.Sprintf("HarmBlockMethod(%d)", v) +} + // HarmBlockThreshold specifies probability based thresholds levels for blocking. type HarmBlockThreshold int32 @@ -627,7 +686,7 @@ func (v HarmProbability) String() string { return fmt.Sprintf("HarmProbability(%d)", v) } -// HarmSeverity is harm severity levels. +// HarmSeverity specifies harm severity levels. type HarmSeverity int32 const ( @@ -741,6 +800,9 @@ type SafetySetting struct { Category HarmCategory // Required. The harm block threshold. Threshold HarmBlockThreshold + // Optional. Specify if the threshold is used for probability or severity + // score. If not specified, the threshold is used for probability score. + Method HarmBlockMethod } func (v *SafetySetting) toProto() *pb.SafetySetting { @@ -750,6 +812,7 @@ func (v *SafetySetting) toProto() *pb.SafetySetting { return &pb.SafetySetting{ Category: pb.HarmCategory(v.Category), Threshold: pb.SafetySetting_HarmBlockThreshold(v.Threshold), + Method: pb.SafetySetting_HarmBlockMethod(v.Method), } } @@ -760,6 +823,7 @@ func (SafetySetting) fromProto(p *pb.SafetySetting) *SafetySetting { return &SafetySetting{ Category: HarmCategory(p.Category), Threshold: HarmBlockThreshold(p.Threshold), + Method: HarmBlockMethod(p.Method), } } @@ -773,23 +837,51 @@ type Schema struct { // Optional. The format of the data. // Supported formats: // - // for NUMBER type: float, double - // for INTEGER type: int32, int64 + // for NUMBER type: "float", "double" + // for INTEGER type: "int32", "int64" + // for STRING type: "email", "byte", etc Format string + // Optional. The title of the Schema. + Title string // Optional. The description of the data. Description string // Optional. Indicates if the value may be null. Nullable bool - // Optional. Schema of the elements of Type.ARRAY. + // Optional. Default value of the data. + Default any + // Optional. SCHEMA FIELDS FOR TYPE ARRAY + // Schema of the elements of Type.ARRAY. Items *Schema + // Optional. Minimum number of the elements for Type.ARRAY. + MinItems int64 + // Optional. Maximum number of the elements for Type.ARRAY. + MaxItems int64 // Optional. Possible values of the element of Type.STRING with enum format. // For example we can define an Enum Direction as : // {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]} Enum []string - // Optional. Properties of Type.OBJECT. + // Optional. SCHEMA FIELDS FOR TYPE OBJECT + // Properties of Type.OBJECT. Properties map[string]*Schema // Optional. Required properties of Type.OBJECT. Required []string + // Optional. Minimum number of the properties for Type.OBJECT. + MinProperties int64 + // Optional. Maximum number of the properties for Type.OBJECT. + MaxProperties int64 + // Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER + // Minimum value of the Type.INTEGER and Type.NUMBER + Minimum float64 + // Optional. Maximum value of the Type.INTEGER and Type.NUMBER + Maximum float64 + // Optional. SCHEMA FIELDS FOR TYPE STRING + // Minimum length of the Type.STRING + MinLength int64 + // Optional. Maximum length of the Type.STRING + MaxLength int64 + // Optional. Pattern of the Type.STRING to restrict a string to a regular + // expression. + Pattern string } func (v *Schema) toProto() *pb.Schema { @@ -797,14 +889,25 @@ func (v *Schema) toProto() *pb.Schema { return nil } return &pb.Schema{ - Type: pb.Type(v.Type), - Format: v.Format, - Description: v.Description, - Nullable: v.Nullable, - Items: v.Items.toProto(), - Enum: v.Enum, - Properties: support.TransformMapValues(v.Properties, (*Schema).toProto), - Required: v.Required, + Type: pb.Type(v.Type), + Format: v.Format, + Title: v.Title, + Description: v.Description, + Nullable: v.Nullable, + Default: support.MapToValuePB(v.Default), + Items: v.Items.toProto(), + MinItems: v.MinItems, + MaxItems: v.MaxItems, + Enum: v.Enum, + Properties: support.TransformMapValues(v.Properties, (*Schema).toProto), + Required: v.Required, + MinProperties: v.MinProperties, + MaxProperties: v.MaxProperties, + Minimum: v.Minimum, + Maximum: v.Maximum, + MinLength: v.MinLength, + MaxLength: v.MaxLength, + Pattern: v.Pattern, } } @@ -813,14 +916,25 @@ func (Schema) fromProto(p *pb.Schema) *Schema { return nil } return &Schema{ - Type: Type(p.Type), - Format: p.Format, - Description: p.Description, - Nullable: p.Nullable, - Items: (Schema{}).fromProto(p.Items), - Enum: p.Enum, - Properties: support.TransformMapValues(p.Properties, (Schema{}).fromProto), - Required: p.Required, + Type: Type(p.Type), + Format: p.Format, + Title: p.Title, + Description: p.Description, + Nullable: p.Nullable, + Default: support.MapFromValuePB(p.Default), + Items: (Schema{}).fromProto(p.Items), + MinItems: p.MinItems, + MaxItems: p.MaxItems, + Enum: p.Enum, + Properties: support.TransformMapValues(p.Properties, (Schema{}).fromProto), + Required: p.Required, + MinProperties: p.MinProperties, + MaxProperties: p.MaxProperties, + Minimum: p.Minimum, + Maximum: p.Maximum, + MinLength: p.MinLength, + MaxLength: p.MaxLength, + Pattern: p.Pattern, } } diff --git a/vertexai/genai/config.yaml b/vertexai/genai/config.yaml index f223835508a..864f9009bf0 100644 --- a/vertexai/genai/config.yaml +++ b/vertexai/genai/config.yaml @@ -30,6 +30,13 @@ types: protoPrefix: SafetyRating_ docVerb: specifies + SafetySetting_HarmBlockMethod: + name: HarmBlockMethod + protoPrefix: SafetyRating_ + docVerb: specifies + valueNames: + SafetyRating_HARM_BLOCK_METHOD: HarmBlockMethodUnspecified + Candidate_FinishReason: name: FinishReason protoPrefix: Candidate_ diff --git a/vertexai/genai/content.go b/vertexai/genai/content.go index 22d4e8ed8a3..ae2aa9423d9 100644 --- a/vertexai/genai/content.go +++ b/vertexai/genai/content.go @@ -134,3 +134,6 @@ func (c *GenerationConfig) SetTopP(x float32) { c.TopP = &x } // SetTopK sets the TopK field. func (c *GenerationConfig) SetTopK(x int32) { c.TopK = &x } + +// SetResponseMimeType sets the ResponseMimeType field. +func (c *GenerationConfig) SetResponseMimeType(x string) { c.ResponseMimeType = x } diff --git a/vertexai/internal/support/support.go b/vertexai/internal/support/support.go index 5e74f3bf939..d9ab309bcb9 100644 --- a/vertexai/internal/support/support.go +++ b/vertexai/internal/support/support.go @@ -110,3 +110,74 @@ func MapFromStructPB(p *structpb.Struct) map[string]any { } return p.AsMap() } + +// MapToValuePB converts any into a structpb.Value. +func MapToValuePB(m any) *structpb.Value { + if m == nil { + return nil + } + + switch m := m.(type) { + case bool: + return &structpb.Value{Kind: &structpb.Value_BoolValue{BoolValue: m}} + case int32: + return &structpb.Value{Kind: &structpb.Value_NumberValue{NumberValue: float64(m)}} + case int64: + return &structpb.Value{Kind: &structpb.Value_NumberValue{NumberValue: float64(m)}} + case float32: + return &structpb.Value{Kind: &structpb.Value_NumberValue{NumberValue: float64(m)}} + case float64: + return &structpb.Value{Kind: &structpb.Value_NumberValue{NumberValue: m}} + case string: + return &structpb.Value{Kind: &structpb.Value_StringValue{StringValue: m}} + case []any: + var values []*structpb.Value + for _, v := range m { + values = append(values, MapToValuePB(v)) + } + return &structpb.Value{Kind: &structpb.Value_ListValue{ListValue: &structpb.ListValue{Values: values}}} + case map[string]any: + fields := make(map[string]*structpb.Value) + for k, v := range m { + fields[k] = MapToValuePB(v) + } + return &structpb.Value{Kind: &structpb.Value_StructValue{StructValue: &structpb.Struct{Fields: fields}}} + default: + // Unsupported type, handle as needed (e.g., return nil or error) + return nil // Modify as needed based on your error handling strategy + } +} + +// MapFromValuePB converts a structpb.Value to any. +func MapFromValuePB(p *structpb.Value) any { + if p == nil { + return nil + } + + switch p.Kind { + case nil: + // Handle nil value (e.g., return nil or a specific value) + return nil // Modify as needed + case &structpb.Value_StringValue{}: + return p.GetStringValue() // Handle single string value + case &structpb.Value_NumberValue{}: + return p.GetNumberValue() // Handle single numeric value + case &structpb.Value_BoolValue{}: + return p.GetBoolValue() // Handle single boolean value + case &structpb.Value_ListValue{}: + result := make([]any, len(p.GetListValue().GetValues())) + for i, val := range p.GetListValue().GetValues() { + result[i] = MapFromValuePB(val) // Convert list elements recursively + } + return result + case &structpb.Value_StructValue{}: + result := make(map[string]any) + for k, v := range p.GetStructValue().GetFields() { + result[k] = MapFromValuePB(v) // Convert struct fields recursively + } + return result + default: + // Unsupported type, handle as needed (e.g., return nil or error) + return nil // Modify as needed based on your error handling strategy + } +}