-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
aiplatformpb_veneer.gen.go
1045 lines (955 loc) · 32.7 KB
/
aiplatformpb_veneer.gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file was generated by protoveneer. DO NOT EDIT.
package genai
import (
"fmt"
pb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb"
"cloud.google.com/go/civil"
"cloud.google.com/go/vertexai/internal/support"
)
// Blob contains content blob.
//
// 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.
Data []byte
}
func (v *Blob) toProto() *pb.Blob {
if v == nil {
return nil
}
return &pb.Blob{
MimeType: v.MIMEType,
Data: v.Data,
}
}
func (Blob) fromProto(p *pb.Blob) *Blob {
if p == nil {
return nil
}
return &Blob{
MIMEType: p.MimeType,
Data: p.Data,
}
}
// BlockedReason is blocked reason enumeration.
type BlockedReason int32
const (
// BlockedReasonUnspecified means unspecified blocked reason.
BlockedReasonUnspecified BlockedReason = 0
// BlockedReasonSafety means candidates blocked due to safety.
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",
BlockedReasonBlocklist: "BlockedReasonBlocklist",
BlockedReasonProhibitedContent: "BlockedReasonProhibitedContent",
}
func (v BlockedReason) String() string {
if n, ok := namesForBlockedReason[v]; ok {
return n
}
return fmt.Sprintf("BlockedReason(%d)", v)
}
// Candidate is a response candidate generated from the model.
type Candidate struct {
// Output only. Index of the candidate.
Index int32
// Output only. Content parts of the candidate.
Content *Content
// Output only. The reason why the model stopped generating tokens.
// If empty, the model has not stopped generating the tokens.
FinishReason FinishReason
// Output only. List of ratings for the safety of a response candidate.
//
// There is at most one rating per category.
SafetyRatings []*SafetyRating
// Output only. Describes the reason the mode stopped generating tokens in
// more detail. This is only filled when `finish_reason` is set.
FinishMessage string
// Output only. Source attribution of the generated content.
CitationMetadata *CitationMetadata
}
func (v *Candidate) toProto() *pb.Candidate {
if v == nil {
return nil
}
return &pb.Candidate{
Index: v.Index,
Content: v.Content.toProto(),
FinishReason: pb.Candidate_FinishReason(v.FinishReason),
SafetyRatings: support.TransformSlice(v.SafetyRatings, (*SafetyRating).toProto),
FinishMessage: support.AddrOrNil(v.FinishMessage),
CitationMetadata: v.CitationMetadata.toProto(),
}
}
func (Candidate) fromProto(p *pb.Candidate) *Candidate {
if p == nil {
return nil
}
return &Candidate{
Index: p.Index,
Content: (Content{}).fromProto(p.Content),
FinishReason: FinishReason(p.FinishReason),
SafetyRatings: support.TransformSlice(p.SafetyRatings, (SafetyRating{}).fromProto),
FinishMessage: support.DerefOrZero(p.FinishMessage),
CitationMetadata: (CitationMetadata{}).fromProto(p.CitationMetadata),
}
}
// Citation contains source attributions for content.
type Citation struct {
// Output only. Start index into the content.
StartIndex int32
// Output only. End index into the content.
EndIndex int32
// Output only. Url reference of the attribution.
URI string
// Output only. Title of the attribution.
Title string
// Output only. License of the attribution.
License string
// Output only. Publication date of the attribution.
PublicationDate civil.Date
}
func (v *Citation) toProto() *pb.Citation {
if v == nil {
return nil
}
return &pb.Citation{
StartIndex: v.StartIndex,
EndIndex: v.EndIndex,
Uri: v.URI,
Title: v.Title,
License: v.License,
PublicationDate: support.CivilDateToProto(v.PublicationDate),
}
}
func (Citation) fromProto(p *pb.Citation) *Citation {
if p == nil {
return nil
}
return &Citation{
StartIndex: p.StartIndex,
EndIndex: p.EndIndex,
URI: p.Uri,
Title: p.Title,
License: p.License,
PublicationDate: support.CivilDateFromProto(p.PublicationDate),
}
}
// CitationMetadata is a collection of source attributions for a piece of content.
type CitationMetadata struct {
// Output only. List of citations.
Citations []*Citation
}
func (v *CitationMetadata) toProto() *pb.CitationMetadata {
if v == nil {
return nil
}
return &pb.CitationMetadata{
Citations: support.TransformSlice(v.Citations, (*Citation).toProto),
}
}
func (CitationMetadata) fromProto(p *pb.CitationMetadata) *CitationMetadata {
if p == nil {
return nil
}
return &CitationMetadata{
Citations: support.TransformSlice(p.Citations, (Citation{}).fromProto),
}
}
// Content is the base structured datatype containing multi-part content of a message.
//
// A `Content` includes a `role` field designating the producer of the `Content`
// and a `parts` field containing multi-part data that contains the content of
// the message turn.
type Content struct {
// Optional. The producer of the content. Must be either 'user' or 'model'.
//
// Useful to set for multi-turn conversations, otherwise can be left blank
// or unset.
Role string
// Required. Ordered `Parts` that constitute a single message. Parts may have
// different IANA MIME types.
Parts []Part
}
func (v *Content) toProto() *pb.Content {
if v == nil {
return nil
}
return &pb.Content{
Role: v.Role,
Parts: support.TransformSlice(v.Parts, partToProto),
}
}
func (Content) fromProto(p *pb.Content) *Content {
if p == nil {
return nil
}
return &Content{
Role: p.Role,
Parts: support.TransformSlice(p.Parts, partFromProto),
}
}
// CountTokensResponse is response message for
// [PredictionService.CountTokens][google.cloud.aiplatform.v1beta1.PredictionService.CountTokens].
type CountTokensResponse struct {
// The total number of tokens counted across all instances from the request.
TotalTokens int32
// The total number of billable characters counted across all instances from
// the request.
TotalBillableCharacters int32
}
func (v *CountTokensResponse) toProto() *pb.CountTokensResponse {
if v == nil {
return nil
}
return &pb.CountTokensResponse{
TotalTokens: v.TotalTokens,
TotalBillableCharacters: v.TotalBillableCharacters,
}
}
func (CountTokensResponse) fromProto(p *pb.CountTokensResponse) *CountTokensResponse {
if p == nil {
return nil
}
return &CountTokensResponse{
TotalTokens: p.TotalTokens,
TotalBillableCharacters: p.TotalBillableCharacters,
}
}
// FileData is URI based data.
type FileData struct {
// Required. The IANA standard MIME type of the source data.
MIMEType string
// Required. URI.
FileURI string
}
func (v *FileData) toProto() *pb.FileData {
if v == nil {
return nil
}
return &pb.FileData{
MimeType: v.MIMEType,
FileUri: v.FileURI,
}
}
func (FileData) fromProto(p *pb.FileData) *FileData {
if p == nil {
return nil
}
return &FileData{
MIMEType: p.MimeType,
FileURI: p.FileUri,
}
}
// FinishReason is the reason why the model stopped generating tokens.
// If empty, the model has not stopped generating the tokens.
type FinishReason int32
const (
// FinishReasonUnspecified means the finish reason is unspecified.
FinishReasonUnspecified FinishReason = 0
// FinishReasonStop means natural stop point of the model or provided stop sequence.
FinishReasonStop FinishReason = 1
// FinishReasonMaxTokens means the maximum number of tokens as specified in the request was reached.
FinishReasonMaxTokens FinishReason = 2
// FinishReasonSafety means the token generation was stopped as the response was flagged for safety
// reasons. NOTE: When streaming the Candidate.content will be empty if
// content filters blocked the output.
FinishReasonSafety FinishReason = 3
// FinishReasonRecitation means the token generation was stopped as the response was flagged for
// unauthorized citations.
FinishReasonRecitation FinishReason = 4
// FinishReasonOther means all other reasons that stopped the token generation
FinishReasonOther FinishReason = 5
// FinishReasonBlocklist means the token generation was stopped as the response was flagged for the
// terms which are included from the terminology blocklist.
FinishReasonBlocklist FinishReason = 6
// FinishReasonProhibitedContent means the token generation was stopped as the response was flagged for
// the prohibited contents.
FinishReasonProhibitedContent FinishReason = 7
// FinishReasonSpii means the token generation was stopped as the response was flagged for
// Sensitive Personally Identifiable Information (SPII) contents.
FinishReasonSpii FinishReason = 8
)
var namesForFinishReason = map[FinishReason]string{
FinishReasonUnspecified: "FinishReasonUnspecified",
FinishReasonStop: "FinishReasonStop",
FinishReasonMaxTokens: "FinishReasonMaxTokens",
FinishReasonSafety: "FinishReasonSafety",
FinishReasonRecitation: "FinishReasonRecitation",
FinishReasonOther: "FinishReasonOther",
FinishReasonBlocklist: "FinishReasonBlocklist",
FinishReasonProhibitedContent: "FinishReasonProhibitedContent",
FinishReasonSpii: "FinishReasonSpii",
}
func (v FinishReason) String() string {
if n, ok := namesForFinishReason[v]; ok {
return n
}
return fmt.Sprintf("FinishReason(%d)", v)
}
// FunctionCall is a predicted [FunctionCall] returned from the model that contains a string
// representing the [FunctionDeclaration.name] and a structured JSON object
// containing the parameters and their values.
type FunctionCall struct {
// Required. The name of the function to call.
// Matches [FunctionDeclaration.name].
Name string
// Optional. Required. The function parameters and values in JSON object
// format. See [FunctionDeclaration.parameters] for parameter details.
Args map[string]any
}
func (v *FunctionCall) toProto() *pb.FunctionCall {
if v == nil {
return nil
}
return &pb.FunctionCall{
Name: v.Name,
Args: support.MapToStructPB(v.Args),
}
}
func (FunctionCall) fromProto(p *pb.FunctionCall) *FunctionCall {
if p == nil {
return nil
}
return &FunctionCall{
Name: p.Name,
Args: support.MapFromStructPB(p.Args),
}
}
// FunctionDeclaration is structured representation of a function declaration as defined by the
// [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included
// in this declaration are the function name and parameters. This
// FunctionDeclaration is a representation of a block of code that can be used
// as a `Tool` by the model and executed by the client.
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, 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.
Description string
// Optional. Describes the parameters to this function in JSON Schema Object
// 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. 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
// param2:
// type: INTEGER
//
// 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 {
if v == nil {
return nil
}
return &pb.FunctionDeclaration{
Name: v.Name,
Description: v.Description,
Parameters: v.Parameters.toProto(),
Response: v.Response.toProto(),
}
}
func (FunctionDeclaration) fromProto(p *pb.FunctionDeclaration) *FunctionDeclaration {
if p == nil {
return nil
}
return &FunctionDeclaration{
Name: p.Name,
Description: p.Description,
Parameters: (Schema{}).fromProto(p.Parameters),
Response: (Schema{}).fromProto(p.Response),
}
}
// FunctionResponse is the result output from a [FunctionCall] that contains a string representing
// the [FunctionDeclaration.name] and a structured JSON object containing any
// output from the function is used as context to the model. This should contain
// the result of a [FunctionCall] made based on model prediction.
type FunctionResponse struct {
// Required. The name of the function to call.
// Matches [FunctionDeclaration.name] and [FunctionCall.name].
Name string
// Required. The function response in JSON object format.
Response map[string]any
}
func (v *FunctionResponse) toProto() *pb.FunctionResponse {
if v == nil {
return nil
}
return &pb.FunctionResponse{
Name: v.Name,
Response: support.MapToStructPB(v.Response),
}
}
func (FunctionResponse) fromProto(p *pb.FunctionResponse) *FunctionResponse {
if p == nil {
return nil
}
return &FunctionResponse{
Name: p.Name,
Response: support.MapFromStructPB(p.Response),
}
}
// GenerateContentResponse is the response from a GenerateContent or GenerateContentStream call.
type GenerateContentResponse struct {
// Output only. Generated candidates.
Candidates []*Candidate
// Output only. Content filter results for a prompt sent in the request.
// Note: Sent only in the first stream chunk.
// Only happens when no candidates were generated due to content violations.
PromptFeedback *PromptFeedback
// Usage metadata about the response(s).
UsageMetadata *UsageMetadata
}
func (v *GenerateContentResponse) toProto() *pb.GenerateContentResponse {
if v == nil {
return nil
}
return &pb.GenerateContentResponse{
Candidates: support.TransformSlice(v.Candidates, (*Candidate).toProto),
PromptFeedback: v.PromptFeedback.toProto(),
UsageMetadata: v.UsageMetadata.toProto(),
}
}
func (GenerateContentResponse) fromProto(p *pb.GenerateContentResponse) *GenerateContentResponse {
if p == nil {
return nil
}
return &GenerateContentResponse{
Candidates: support.TransformSlice(p.Candidates, (Candidate{}).fromProto),
PromptFeedback: (PromptFeedback{}).fromProto(p.PromptFeedback),
UsageMetadata: (UsageMetadata{}).fromProto(p.UsageMetadata),
}
}
// GenerationConfig is generation config.
type GenerationConfig struct {
// Optional. Controls the randomness of predictions.
Temperature *float32
// Optional. If specified, nucleus sampling will be used.
TopP *float32
// Optional. If specified, top-k sampling will be used.
TopK *int32
// Optional. Number of candidates to generate.
CandidateCount *int32
// Optional. The maximum number of output tokens to generate per message.
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 {
if v == nil {
return nil
}
return &pb.GenerationConfig{
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,
}
}
func (GenerationConfig) fromProto(p *pb.GenerationConfig) *GenerationConfig {
if p == nil {
return nil
}
return &GenerationConfig{
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
const (
// HarmBlockUnspecified means unspecified harm block threshold.
HarmBlockUnspecified HarmBlockThreshold = 0
// HarmBlockLowAndAbove means block low threshold and above (i.e. block more).
HarmBlockLowAndAbove HarmBlockThreshold = 1
// HarmBlockMediumAndAbove means block medium threshold and above.
HarmBlockMediumAndAbove HarmBlockThreshold = 2
// HarmBlockOnlyHigh means block only high threshold (i.e. block less).
HarmBlockOnlyHigh HarmBlockThreshold = 3
// HarmBlockNone means block none.
HarmBlockNone HarmBlockThreshold = 4
)
var namesForHarmBlockThreshold = map[HarmBlockThreshold]string{
HarmBlockUnspecified: "HarmBlockUnspecified",
HarmBlockLowAndAbove: "HarmBlockLowAndAbove",
HarmBlockMediumAndAbove: "HarmBlockMediumAndAbove",
HarmBlockOnlyHigh: "HarmBlockOnlyHigh",
HarmBlockNone: "HarmBlockNone",
}
func (v HarmBlockThreshold) String() string {
if n, ok := namesForHarmBlockThreshold[v]; ok {
return n
}
return fmt.Sprintf("HarmBlockThreshold(%d)", v)
}
// HarmCategory specifies harm categories that will block the content.
type HarmCategory int32
const (
// HarmCategoryUnspecified means the harm category is unspecified.
HarmCategoryUnspecified HarmCategory = 0
// HarmCategoryHateSpeech means the harm category is hate speech.
HarmCategoryHateSpeech HarmCategory = 1
// HarmCategoryDangerousContent means the harm category is dangerous content.
HarmCategoryDangerousContent HarmCategory = 2
// HarmCategoryHarassment means the harm category is harassment.
HarmCategoryHarassment HarmCategory = 3
// HarmCategorySexuallyExplicit means the harm category is sexually explicit content.
HarmCategorySexuallyExplicit HarmCategory = 4
)
var namesForHarmCategory = map[HarmCategory]string{
HarmCategoryUnspecified: "HarmCategoryUnspecified",
HarmCategoryHateSpeech: "HarmCategoryHateSpeech",
HarmCategoryDangerousContent: "HarmCategoryDangerousContent",
HarmCategoryHarassment: "HarmCategoryHarassment",
HarmCategorySexuallyExplicit: "HarmCategorySexuallyExplicit",
}
func (v HarmCategory) String() string {
if n, ok := namesForHarmCategory[v]; ok {
return n
}
return fmt.Sprintf("HarmCategory(%d)", v)
}
// HarmProbability specifies harm probability levels in the content.
type HarmProbability int32
const (
// HarmProbabilityUnspecified means harm probability unspecified.
HarmProbabilityUnspecified HarmProbability = 0
// HarmProbabilityNegligible means negligible level of harm.
HarmProbabilityNegligible HarmProbability = 1
// HarmProbabilityLow means low level of harm.
HarmProbabilityLow HarmProbability = 2
// HarmProbabilityMedium means medium level of harm.
HarmProbabilityMedium HarmProbability = 3
// HarmProbabilityHigh means high level of harm.
HarmProbabilityHigh HarmProbability = 4
)
var namesForHarmProbability = map[HarmProbability]string{
HarmProbabilityUnspecified: "HarmProbabilityUnspecified",
HarmProbabilityNegligible: "HarmProbabilityNegligible",
HarmProbabilityLow: "HarmProbabilityLow",
HarmProbabilityMedium: "HarmProbabilityMedium",
HarmProbabilityHigh: "HarmProbabilityHigh",
}
func (v HarmProbability) String() string {
if n, ok := namesForHarmProbability[v]; ok {
return n
}
return fmt.Sprintf("HarmProbability(%d)", v)
}
// HarmSeverity specifies harm severity levels.
type HarmSeverity int32
const (
// HarmSeverityUnspecified means harm severity unspecified.
HarmSeverityUnspecified HarmSeverity = 0
// HarmSeverityNegligible means negligible level of harm severity.
HarmSeverityNegligible HarmSeverity = 1
// HarmSeverityLow means low level of harm severity.
HarmSeverityLow HarmSeverity = 2
// HarmSeverityMedium means medium level of harm severity.
HarmSeverityMedium HarmSeverity = 3
// HarmSeverityHigh means high level of harm severity.
HarmSeverityHigh HarmSeverity = 4
)
var namesForHarmSeverity = map[HarmSeverity]string{
HarmSeverityUnspecified: "HarmSeverityUnspecified",
HarmSeverityNegligible: "HarmSeverityNegligible",
HarmSeverityLow: "HarmSeverityLow",
HarmSeverityMedium: "HarmSeverityMedium",
HarmSeverityHigh: "HarmSeverityHigh",
}
func (v HarmSeverity) String() string {
if n, ok := namesForHarmSeverity[v]; ok {
return n
}
return fmt.Sprintf("HarmSeverity(%d)", v)
}
// PromptFeedback contains content filter results for a prompt sent in the request.
type PromptFeedback struct {
// Output only. Blocked reason.
BlockReason BlockedReason
// Output only. Safety ratings.
SafetyRatings []*SafetyRating
// Output only. A readable block reason message.
BlockReasonMessage string
}
func (v *PromptFeedback) toProto() *pb.GenerateContentResponse_PromptFeedback {
if v == nil {
return nil
}
return &pb.GenerateContentResponse_PromptFeedback{
BlockReason: pb.GenerateContentResponse_PromptFeedback_BlockedReason(v.BlockReason),
SafetyRatings: support.TransformSlice(v.SafetyRatings, (*SafetyRating).toProto),
BlockReasonMessage: v.BlockReasonMessage,
}
}
func (PromptFeedback) fromProto(p *pb.GenerateContentResponse_PromptFeedback) *PromptFeedback {
if p == nil {
return nil
}
return &PromptFeedback{
BlockReason: BlockedReason(p.BlockReason),
SafetyRatings: support.TransformSlice(p.SafetyRatings, (SafetyRating{}).fromProto),
BlockReasonMessage: p.BlockReasonMessage,
}
}
// SafetyRating is the safety rating corresponding to the generated content.
type SafetyRating struct {
// Output only. Harm category.
Category HarmCategory
// Output only. Harm probability levels in the content.
Probability HarmProbability
// Output only. Harm probability score.
ProbabilityScore float32
// Output only. Harm severity levels in the content.
Severity HarmSeverity
// Output only. Harm severity score.
SeverityScore float32
// Output only. Indicates whether the content was filtered out because of this
// rating.
Blocked bool
}
func (v *SafetyRating) toProto() *pb.SafetyRating {
if v == nil {
return nil
}
return &pb.SafetyRating{
Category: pb.HarmCategory(v.Category),
Probability: pb.SafetyRating_HarmProbability(v.Probability),
ProbabilityScore: v.ProbabilityScore,
Severity: pb.SafetyRating_HarmSeverity(v.Severity),
SeverityScore: v.SeverityScore,
Blocked: v.Blocked,
}
}
func (SafetyRating) fromProto(p *pb.SafetyRating) *SafetyRating {
if p == nil {
return nil
}
return &SafetyRating{
Category: HarmCategory(p.Category),
Probability: HarmProbability(p.Probability),
ProbabilityScore: p.ProbabilityScore,
Severity: HarmSeverity(p.Severity),
SeverityScore: p.SeverityScore,
Blocked: p.Blocked,
}
}
// SafetySetting is safety settings.
type SafetySetting struct {
// Required. Harm category.
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 {
if v == nil {
return nil
}
return &pb.SafetySetting{
Category: pb.HarmCategory(v.Category),
Threshold: pb.SafetySetting_HarmBlockThreshold(v.Threshold),
Method: pb.SafetySetting_HarmBlockMethod(v.Method),
}
}
func (SafetySetting) fromProto(p *pb.SafetySetting) *SafetySetting {
if p == nil {
return nil
}
return &SafetySetting{
Category: HarmCategory(p.Category),
Threshold: HarmBlockThreshold(p.Threshold),
Method: HarmBlockMethod(p.Method),
}
}
// Schema is used to define the format of input/output data. Represents a select
// subset of an [OpenAPI 3.0 schema
// object](https://spec.openapis.org/oas/v3.0.3#schema). More fields may be
// added in the future as needed.
type Schema struct {
// Optional. The type of the data.
Type Type
// Optional. The format of the data.
// Supported formats:
//
// 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. 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. 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 {
if v == nil {
return nil
}
return &pb.Schema{
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,
}
}
func (Schema) fromProto(p *pb.Schema) *Schema {
if p == nil {
return nil
}
return &Schema{
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,
}
}
// Tool details that the model may use to generate response.
//
// A `Tool` is a piece of code that enables the system to interact with
// external systems to perform an action, or set of actions, outside of
// knowledge and scope of the model. A Tool object should contain exactly
// one type of Tool (e.g FunctionDeclaration, Retrieval or
// GoogleSearchRetrieval).
type Tool struct {
// Optional. Function tool type.
// One or more function declarations to be passed to the model along with the
// current user query. Model may decide to call a subset of these functions
// by populating [FunctionCall][content.part.function_call] in the response.
// User should provide a [FunctionResponse][content.part.function_response]
// for each function call in the next turn. Based on the function responses,
// Model will generate the final response back to the user.
// Maximum 64 function declarations can be provided.
FunctionDeclarations []*FunctionDeclaration
}
func (v *Tool) toProto() *pb.Tool {
if v == nil {
return nil
}
return &pb.Tool{
FunctionDeclarations: support.TransformSlice(v.FunctionDeclarations, (*FunctionDeclaration).toProto),
}
}
func (Tool) fromProto(p *pb.Tool) *Tool {
if p == nil {
return nil
}
return &Tool{
FunctionDeclarations: support.TransformSlice(p.FunctionDeclarations, (FunctionDeclaration{}).fromProto),
}
}
// Type contains the list of OpenAPI data types as defined by
// https://swagger.io/docs/specification/data-models/data-types/
type Type int32
const (
// TypeUnspecified means not specified, should not be used.
TypeUnspecified Type = 0
// TypeString means openAPI string type
TypeString Type = 1
// TypeNumber means openAPI number type
TypeNumber Type = 2
// TypeInteger means openAPI integer type
TypeInteger Type = 3
// TypeBoolean means openAPI boolean type
TypeBoolean Type = 4
// TypeArray means openAPI array type
TypeArray Type = 5
// TypeObject means openAPI object type
TypeObject Type = 6
)
var namesForType = map[Type]string{
TypeUnspecified: "TypeUnspecified",