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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
// This file is @generated by prost-build.
/// Information about a Generative Language Model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Model {
/// Required. The resource name of the `Model`. Refer to [Model
/// variants](<https://ai.google.dev/gemini-api/docs/models/gemini#model-variations>)
/// for all allowed values.
///
/// Format: `models/{model}` with a `{model}` naming convention of:
///
/// * "{base_model_id}-{version}"
///
/// Examples:
///
/// * `models/gemini-1.5-flash-001`
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// Required. The name of the base model, pass this to the generation request.
///
/// Examples:
///
/// * `gemini-1.5-flash`
#[prost(string, tag = "2")]
pub base_model_id: ::prost::alloc::string::String,
/// Required. The version number of the model.
///
/// This represents the major version (`1.0` or `1.5`)
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
/// The human-readable name of the model. E.g. "Gemini 1.5 Flash".
///
/// The name can be up to 128 characters long and can consist of any UTF-8
/// characters.
#[prost(string, tag = "4")]
pub display_name: ::prost::alloc::string::String,
/// A short description of the model.
#[prost(string, tag = "5")]
pub description: ::prost::alloc::string::String,
/// Maximum number of input tokens allowed for this model.
#[prost(int32, tag = "6")]
pub input_token_limit: i32,
/// Maximum number of output tokens available for this model.
#[prost(int32, tag = "7")]
pub output_token_limit: i32,
/// The model's supported generation methods.
///
/// The corresponding API method names are defined as Pascal case
/// strings, such as `generateMessage` and `generateContent`.
#[prost(string, repeated, tag = "8")]
pub supported_generation_methods: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
/// Controls the randomness of the output.
///
/// Values can range over `\[0.0,max_temperature\]`, inclusive. A higher value
/// will produce responses that are more varied, while a value closer to `0.0`
/// will typically result in less surprising responses from the model.
/// This value specifies default to be used by the backend while making the
/// call to the model.
#[prost(float, optional, tag = "9")]
pub temperature: ::core::option::Option<f32>,
/// The maximum temperature this model can use.
#[prost(float, optional, tag = "13")]
pub max_temperature: ::core::option::Option<f32>,
/// For [Nucleus
/// sampling](<https://ai.google.dev/gemini-api/docs/prompting-strategies#top-p>).
///
/// Nucleus sampling considers the smallest set of tokens whose probability
/// sum is at least `top_p`.
/// This value specifies default to be used by the backend while making the
/// call to the model.
#[prost(float, optional, tag = "10")]
pub top_p: ::core::option::Option<f32>,
/// For Top-k sampling.
///
/// Top-k sampling considers the set of `top_k` most probable tokens.
/// This value specifies default to be used by the backend while making the
/// call to the model.
/// If empty, indicates the model doesn't use top-k sampling, and `top_k` isn't
/// allowed as a generation parameter.
#[prost(int32, optional, tag = "11")]
pub top_k: ::core::option::Option<i32>,
}
/// 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.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Content {
/// Ordered `Parts` that constitute a single message. Parts may have different
/// MIME types.
#[prost(message, repeated, tag = "1")]
pub parts: ::prost::alloc::vec::Vec<Part>,
/// 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.
#[prost(string, tag = "2")]
pub role: ::prost::alloc::string::String,
}
/// A datatype containing media that is part of a multi-part `Content` message.
///
/// A `Part` consists of data which has an associated datatype. A `Part` can only
/// contain one of the accepted types in `Part.data`.
///
/// A `Part` must have a fixed IANA MIME type identifying the type and subtype
/// of the media if the `inline_data` field is filled with raw bytes.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Part {
#[prost(oneof = "part::Data", tags = "2, 3")]
pub data: ::core::option::Option<part::Data>,
}
/// Nested message and enum types in `Part`.
pub mod part {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Data {
/// Inline text.
#[prost(string, tag = "2")]
Text(::prost::alloc::string::String),
/// Inline media bytes.
#[prost(message, tag = "3")]
InlineData(super::Blob),
}
}
/// Raw media bytes.
///
/// Text should not be sent as raw bytes, use the 'text' field.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Blob {
/// The IANA standard MIME type of the source data.
/// Examples:
/// - image/png
/// - image/jpeg
/// If an unsupported MIME type is provided, an error will be returned. For a
/// complete list of supported types, see [Supported file
/// formats](<https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats>).
#[prost(string, tag = "1")]
pub mime_type: ::prost::alloc::string::String,
/// Raw bytes for media formats.
#[prost(bytes = "bytes", tag = "2")]
pub data: ::prost::bytes::Bytes,
}
/// Request for getting information about a specific Model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetModelRequest {
/// Required. The resource name of the model.
///
/// This name should match a model name returned by the `ListModels` method.
///
/// Format: `models/{model}`
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
}
/// Request for listing all Models.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListModelsRequest {
/// The maximum number of `Models` to return (per page).
///
/// If unspecified, 50 models will be returned per page.
/// This method returns at most 1000 models per page, even if you pass a larger
/// page_size.
#[prost(int32, tag = "2")]
pub page_size: i32,
/// A page token, received from a previous `ListModels` call.
///
/// Provide the `page_token` returned by one request as an argument to the next
/// request to retrieve the next page.
///
/// When paginating, all other parameters provided to `ListModels` must match
/// the call that provided the page token.
#[prost(string, tag = "3")]
pub page_token: ::prost::alloc::string::String,
}
/// Response from `ListModel` containing a paginated list of Models.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListModelsResponse {
/// The returned Models.
#[prost(message, repeated, tag = "1")]
pub models: ::prost::alloc::vec::Vec<Model>,
/// A token, which can be sent as `page_token` to retrieve the next page.
///
/// If this field is omitted, there are no more pages.
#[prost(string, tag = "2")]
pub next_page_token: ::prost::alloc::string::String,
}
/// Generated client implementations.
pub mod model_service_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// Provides methods for getting metadata information about Generative Models.
#[derive(Debug, Clone)]
pub struct ModelServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl<T> ModelServiceClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> ModelServiceClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
ModelServiceClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// Gets information about a specific `Model` such as its version number, token
/// limits,
/// [parameters](https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters)
/// and other metadata. Refer to the [Gemini models
/// guide](https://ai.google.dev/gemini-api/docs/models/gemini) for detailed
/// model information.
pub async fn get_model(
&mut self,
request: impl tonic::IntoRequest<super::GetModelRequest>,
) -> std::result::Result<tonic::Response<super::Model>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.ModelService/GetModel",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.ModelService",
"GetModel",
),
);
self.inner.unary(req, path, codec).await
}
/// Lists the [`Model`s](https://ai.google.dev/gemini-api/docs/models/gemini)
/// available through the Gemini API.
pub async fn list_models(
&mut self,
request: impl tonic::IntoRequest<super::ListModelsRequest>,
) -> std::result::Result<
tonic::Response<super::ListModelsResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.ModelService/ListModels",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.ModelService",
"ListModels",
),
);
self.inner.unary(req, path, codec).await
}
}
}
/// Safety rating for a piece of content.
///
/// The safety rating contains the category of harm and the
/// harm probability level in that category for a piece of content.
/// Content is classified for safety across a number of
/// harm categories and the probability of the harm classification is included
/// here.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct SafetyRating {
/// Required. The category for this rating.
#[prost(enumeration = "HarmCategory", tag = "3")]
pub category: i32,
/// Required. The probability of harm for this content.
#[prost(enumeration = "safety_rating::HarmProbability", tag = "4")]
pub probability: i32,
/// Was this content blocked because of this rating?
#[prost(bool, tag = "5")]
pub blocked: bool,
}
/// Nested message and enum types in `SafetyRating`.
pub mod safety_rating {
/// The probability that a piece of content is harmful.
///
/// The classification system gives the probability of the content being
/// unsafe. This does not indicate the severity of harm for a piece of content.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum HarmProbability {
/// Probability is unspecified.
Unspecified = 0,
/// Content has a negligible chance of being unsafe.
Negligible = 1,
/// Content has a low chance of being unsafe.
Low = 2,
/// Content has a medium chance of being unsafe.
Medium = 3,
/// Content has a high chance of being unsafe.
High = 4,
}
impl HarmProbability {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
HarmProbability::Unspecified => "HARM_PROBABILITY_UNSPECIFIED",
HarmProbability::Negligible => "NEGLIGIBLE",
HarmProbability::Low => "LOW",
HarmProbability::Medium => "MEDIUM",
HarmProbability::High => "HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"HARM_PROBABILITY_UNSPECIFIED" => Some(Self::Unspecified),
"NEGLIGIBLE" => Some(Self::Negligible),
"LOW" => Some(Self::Low),
"MEDIUM" => Some(Self::Medium),
"HIGH" => Some(Self::High),
_ => None,
}
}
}
}
/// Safety setting, affecting the safety-blocking behavior.
///
/// Passing a safety setting for a category changes the allowed probability that
/// content is blocked.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct SafetySetting {
/// Required. The category for this setting.
#[prost(enumeration = "HarmCategory", tag = "3")]
pub category: i32,
/// Required. Controls the probability threshold at which harm is blocked.
#[prost(enumeration = "safety_setting::HarmBlockThreshold", tag = "4")]
pub threshold: i32,
}
/// Nested message and enum types in `SafetySetting`.
pub mod safety_setting {
/// Block at and beyond a specified harm probability.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum HarmBlockThreshold {
/// Threshold is unspecified.
Unspecified = 0,
/// Content with NEGLIGIBLE will be allowed.
BlockLowAndAbove = 1,
/// Content with NEGLIGIBLE and LOW will be allowed.
BlockMediumAndAbove = 2,
/// Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed.
BlockOnlyHigh = 3,
/// All content will be allowed.
BlockNone = 4,
}
impl HarmBlockThreshold {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
HarmBlockThreshold::Unspecified => "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
HarmBlockThreshold::BlockLowAndAbove => "BLOCK_LOW_AND_ABOVE",
HarmBlockThreshold::BlockMediumAndAbove => "BLOCK_MEDIUM_AND_ABOVE",
HarmBlockThreshold::BlockOnlyHigh => "BLOCK_ONLY_HIGH",
HarmBlockThreshold::BlockNone => "BLOCK_NONE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"HARM_BLOCK_THRESHOLD_UNSPECIFIED" => Some(Self::Unspecified),
"BLOCK_LOW_AND_ABOVE" => Some(Self::BlockLowAndAbove),
"BLOCK_MEDIUM_AND_ABOVE" => Some(Self::BlockMediumAndAbove),
"BLOCK_ONLY_HIGH" => Some(Self::BlockOnlyHigh),
"BLOCK_NONE" => Some(Self::BlockNone),
_ => None,
}
}
}
}
/// The category of a rating.
///
/// These categories cover various kinds of harms that developers
/// may wish to adjust.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum HarmCategory {
/// Category is unspecified.
Unspecified = 0,
/// Negative or harmful comments targeting identity and/or protected attribute.
Derogatory = 1,
/// Content that is rude, disrespectful, or profane.
Toxicity = 2,
/// Describes scenarios depicting violence against an individual or group, or
/// general descriptions of gore.
Violence = 3,
/// Contains references to sexual acts or other lewd content.
Sexual = 4,
/// Promotes unchecked medical advice.
Medical = 5,
/// Dangerous content that promotes, facilitates, or encourages harmful acts.
Dangerous = 6,
/// Harasment content.
Harassment = 7,
/// Hate speech and content.
HateSpeech = 8,
/// Sexually explicit content.
SexuallyExplicit = 9,
/// Dangerous content.
DangerousContent = 10,
}
impl HarmCategory {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
HarmCategory::Unspecified => "HARM_CATEGORY_UNSPECIFIED",
HarmCategory::Derogatory => "HARM_CATEGORY_DEROGATORY",
HarmCategory::Toxicity => "HARM_CATEGORY_TOXICITY",
HarmCategory::Violence => "HARM_CATEGORY_VIOLENCE",
HarmCategory::Sexual => "HARM_CATEGORY_SEXUAL",
HarmCategory::Medical => "HARM_CATEGORY_MEDICAL",
HarmCategory::Dangerous => "HARM_CATEGORY_DANGEROUS",
HarmCategory::Harassment => "HARM_CATEGORY_HARASSMENT",
HarmCategory::HateSpeech => "HARM_CATEGORY_HATE_SPEECH",
HarmCategory::SexuallyExplicit => "HARM_CATEGORY_SEXUALLY_EXPLICIT",
HarmCategory::DangerousContent => "HARM_CATEGORY_DANGEROUS_CONTENT",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"HARM_CATEGORY_UNSPECIFIED" => Some(Self::Unspecified),
"HARM_CATEGORY_DEROGATORY" => Some(Self::Derogatory),
"HARM_CATEGORY_TOXICITY" => Some(Self::Toxicity),
"HARM_CATEGORY_VIOLENCE" => Some(Self::Violence),
"HARM_CATEGORY_SEXUAL" => Some(Self::Sexual),
"HARM_CATEGORY_MEDICAL" => Some(Self::Medical),
"HARM_CATEGORY_DANGEROUS" => Some(Self::Dangerous),
"HARM_CATEGORY_HARASSMENT" => Some(Self::Harassment),
"HARM_CATEGORY_HATE_SPEECH" => Some(Self::HateSpeech),
"HARM_CATEGORY_SEXUALLY_EXPLICIT" => Some(Self::SexuallyExplicit),
"HARM_CATEGORY_DANGEROUS_CONTENT" => Some(Self::DangerousContent),
_ => None,
}
}
}
/// A collection of source attributions for a piece of content.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CitationMetadata {
/// Citations to sources for a specific response.
#[prost(message, repeated, tag = "1")]
pub citation_sources: ::prost::alloc::vec::Vec<CitationSource>,
}
/// A citation to a source for a portion of a specific response.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CitationSource {
/// Optional. Start of segment of the response that is attributed to this
/// source.
///
/// Index indicates the start of the segment, measured in bytes.
#[prost(int32, optional, tag = "1")]
pub start_index: ::core::option::Option<i32>,
/// Optional. End of the attributed segment, exclusive.
#[prost(int32, optional, tag = "2")]
pub end_index: ::core::option::Option<i32>,
/// Optional. URI that is attributed as a source for a portion of the text.
#[prost(string, optional, tag = "3")]
pub uri: ::core::option::Option<::prost::alloc::string::String>,
/// Optional. License for the GitHub project that is attributed as a source for
/// segment.
///
/// License info is required for code citations.
#[prost(string, optional, tag = "4")]
pub license: ::core::option::Option<::prost::alloc::string::String>,
}
/// Request to generate a completion from the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateContentRequest {
/// Required. The name of the `Model` to use for generating the completion.
///
/// Format: `name=models/{model}`.
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. The content of the current conversation with the model.
///
/// For single-turn queries, this is a single instance. For multi-turn queries
/// like [chat](<https://ai.google.dev/gemini-api/docs/text-generation#chat>),
/// this is a repeated field that contains the conversation history and the
/// latest request.
#[prost(message, repeated, tag = "2")]
pub contents: ::prost::alloc::vec::Vec<Content>,
/// Optional. A list of unique `SafetySetting` instances for blocking unsafe
/// content.
///
/// This will be enforced on the `GenerateContentRequest.contents` and
/// `GenerateContentResponse.candidates`. There should not be more than one
/// setting for each `SafetyCategory` type. The API will block any contents and
/// responses that fail to meet the thresholds set by these settings. This list
/// overrides the default settings for each `SafetyCategory` specified in the
/// safety_settings. If there is no `SafetySetting` for a given
/// `SafetyCategory` provided in the list, the API will use the default safety
/// setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH,
/// HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT,
/// HARM_CATEGORY_HARASSMENT are supported. Refer to the
/// [guide](<https://ai.google.dev/gemini-api/docs/safety-settings>)
/// for detailed information on available safety settings. Also refer to the
/// [Safety guidance](<https://ai.google.dev/gemini-api/docs/safety-guidance>) to
/// learn how to incorporate safety considerations in your AI applications.
#[prost(message, repeated, tag = "3")]
pub safety_settings: ::prost::alloc::vec::Vec<SafetySetting>,
/// Optional. Configuration options for model generation and outputs.
#[prost(message, optional, tag = "4")]
pub generation_config: ::core::option::Option<GenerationConfig>,
}
/// Configuration options for model generation and outputs. Not all parameters
/// are configurable for every model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerationConfig {
/// Optional. Number of generated responses to return.
///
/// Currently, this value can only be set to 1. If unset, this will default
/// to 1.
#[prost(int32, optional, tag = "1")]
pub candidate_count: ::core::option::Option<i32>,
/// Optional. The set of character sequences (up to 5) that will stop output
/// generation. If specified, the API will stop at the first appearance of a
/// `stop_sequence`. The stop sequence will not be included as part of the
/// response.
#[prost(string, repeated, tag = "2")]
pub stop_sequences: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Optional. The maximum number of tokens to include in a response candidate.
///
/// Note: The default value varies by model, see the `Model.output_token_limit`
/// attribute of the `Model` returned from the `getModel` function.
#[prost(int32, optional, tag = "4")]
pub max_output_tokens: ::core::option::Option<i32>,
/// Optional. Controls the randomness of the output.
///
/// Note: The default value varies by model, see the `Model.temperature`
/// attribute of the `Model` returned from the `getModel` function.
///
/// Values can range from \[0.0, 2.0\].
#[prost(float, optional, tag = "5")]
pub temperature: ::core::option::Option<f32>,
/// Optional. The maximum cumulative probability of tokens to consider when
/// sampling.
///
/// The model uses combined Top-k and Top-p (nucleus) sampling.
///
/// Tokens are sorted based on their assigned probabilities so that only the
/// most likely tokens are considered. Top-k sampling directly limits the
/// maximum number of tokens to consider, while Nucleus sampling limits the
/// number of tokens based on the cumulative probability.
///
/// Note: The default value varies by `Model` and is specified by
/// the`Model.top_p` attribute returned from the `getModel` function. An empty
/// `top_k` attribute indicates that the model doesn't apply top-k sampling
/// and doesn't allow setting `top_k` on requests.
#[prost(float, optional, tag = "6")]
pub top_p: ::core::option::Option<f32>,
/// Optional. The maximum number of tokens to consider when sampling.
///
/// Gemini models use Top-p (nucleus) sampling or a combination of Top-k and
/// nucleus sampling. Top-k sampling considers the set of `top_k` most probable
/// tokens. Models running with nucleus sampling don't allow top_k setting.
///
/// Note: The default value varies by `Model` and is specified by
/// the`Model.top_p` attribute returned from the `getModel` function. An empty
/// `top_k` attribute indicates that the model doesn't apply top-k sampling
/// and doesn't allow setting `top_k` on requests.
#[prost(int32, optional, tag = "7")]
pub top_k: ::core::option::Option<i32>,
}
/// Response from the model supporting multiple candidate responses.
///
/// Safety ratings and content filtering are reported for both
/// prompt in `GenerateContentResponse.prompt_feedback` and for each candidate
/// in `finish_reason` and in `safety_ratings`. The API:
/// - Returns either all requested candidates or none of them
/// - Returns no candidates at all only if there was something wrong with the
/// prompt (check `prompt_feedback`)
/// - Reports feedback on each candidate in `finish_reason` and
/// `safety_ratings`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateContentResponse {
/// Candidate responses from the model.
#[prost(message, repeated, tag = "1")]
pub candidates: ::prost::alloc::vec::Vec<Candidate>,
/// Returns the prompt's feedback related to the content filters.
#[prost(message, optional, tag = "2")]
pub prompt_feedback: ::core::option::Option<
generate_content_response::PromptFeedback,
>,
/// Output only. Metadata on the generation requests' token usage.
#[prost(message, optional, tag = "3")]
pub usage_metadata: ::core::option::Option<generate_content_response::UsageMetadata>,
}
/// Nested message and enum types in `GenerateContentResponse`.
pub mod generate_content_response {
/// A set of the feedback metadata the prompt specified in
/// `GenerateContentRequest.content`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PromptFeedback {
/// Optional. If set, the prompt was blocked and no candidates are returned.
/// Rephrase the prompt.
#[prost(enumeration = "prompt_feedback::BlockReason", tag = "1")]
pub block_reason: i32,
/// Ratings for safety of the prompt.
/// There is at most one rating per category.
#[prost(message, repeated, tag = "2")]
pub safety_ratings: ::prost::alloc::vec::Vec<super::SafetyRating>,
}
/// Nested message and enum types in `PromptFeedback`.
pub mod prompt_feedback {
/// Specifies the reason why the prompt was blocked.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum BlockReason {
/// Default value. This value is unused.
Unspecified = 0,
/// Prompt was blocked due to safety reasons. Inspect `safety_ratings`
/// to understand which safety category blocked it.
Safety = 1,
/// Prompt was blocked due to unknown reasons.
Other = 2,
/// Prompt was blocked due to the terms which are included from the
/// terminology blocklist.
Blocklist = 3,
/// Prompt was blocked due to prohibited content.
ProhibitedContent = 4,
}
impl BlockReason {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
BlockReason::Unspecified => "BLOCK_REASON_UNSPECIFIED",
BlockReason::Safety => "SAFETY",
BlockReason::Other => "OTHER",
BlockReason::Blocklist => "BLOCKLIST",
BlockReason::ProhibitedContent => "PROHIBITED_CONTENT",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"BLOCK_REASON_UNSPECIFIED" => Some(Self::Unspecified),
"SAFETY" => Some(Self::Safety),
"OTHER" => Some(Self::Other),
"BLOCKLIST" => Some(Self::Blocklist),
"PROHIBITED_CONTENT" => Some(Self::ProhibitedContent),
_ => None,
}
}
}
}
/// Metadata on the generation request's token usage.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct UsageMetadata {
/// Number of tokens in the prompt. When `cached_content` is set, this is
/// still the total effective prompt size meaning this includes the number of
/// tokens in the cached content.
#[prost(int32, tag = "1")]
pub prompt_token_count: i32,
/// Total number of tokens across all the generated response candidates.
#[prost(int32, tag = "2")]
pub candidates_token_count: i32,
/// Total token count for the generation request (prompt + response
/// candidates).
#[prost(int32, tag = "3")]
pub total_token_count: i32,
}
}
/// A response candidate generated from the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Candidate {
/// Output only. Index of the candidate in the list of response candidates.
#[prost(int32, optional, tag = "3")]
pub index: ::core::option::Option<i32>,
/// Output only. Generated content returned from the model.
#[prost(message, optional, tag = "1")]
pub content: ::core::option::Option<Content>,
/// Optional. Output only. The reason why the model stopped generating tokens.
///
/// If empty, the model has not stopped generating tokens.
#[prost(enumeration = "candidate::FinishReason", tag = "2")]
pub finish_reason: i32,
/// List of ratings for the safety of a response candidate.
///
/// There is at most one rating per category.
#[prost(message, repeated, tag = "5")]
pub safety_ratings: ::prost::alloc::vec::Vec<SafetyRating>,
/// Output only. Citation information for model-generated candidate.
///
/// This field may be populated with recitation information for any text
/// included in the `content`. These are passages that are "recited" from
/// copyrighted material in the foundational LLM's training data.
#[prost(message, optional, tag = "6")]
pub citation_metadata: ::core::option::Option<CitationMetadata>,
/// Output only. Token count for this candidate.
#[prost(int32, tag = "7")]
pub token_count: i32,
}
/// Nested message and enum types in `Candidate`.
pub mod candidate {
/// Defines the reason why the model stopped generating tokens.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum FinishReason {
/// Default value. This value is unused.
Unspecified = 0,
/// Natural stop point of the model or provided stop sequence.
Stop = 1,
/// The maximum number of tokens as specified in the request was reached.
MaxTokens = 2,
/// The response candidate content was flagged for safety reasons.
Safety = 3,
/// The response candidate content was flagged for recitation reasons.
Recitation = 4,
/// The response candidate content was flagged for using an unsupported
/// language.
Language = 6,
/// Unknown reason.
Other = 5,
/// Token generation stopped because the content contains forbidden terms.
Blocklist = 7,
/// Token generation stopped for potentially containing prohibited content.
ProhibitedContent = 8,
/// Token generation stopped because the content potentially contains
/// Sensitive Personally Identifiable Information (SPII).
Spii = 9,
/// The function call generated by the model is invalid.
MalformedFunctionCall = 10,
}
impl FinishReason {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
FinishReason::Unspecified => "FINISH_REASON_UNSPECIFIED",
FinishReason::Stop => "STOP",
FinishReason::MaxTokens => "MAX_TOKENS",
FinishReason::Safety => "SAFETY",
FinishReason::Recitation => "RECITATION",
FinishReason::Language => "LANGUAGE",
FinishReason::Other => "OTHER",
FinishReason::Blocklist => "BLOCKLIST",
FinishReason::ProhibitedContent => "PROHIBITED_CONTENT",
FinishReason::Spii => "SPII",
FinishReason::MalformedFunctionCall => "MALFORMED_FUNCTION_CALL",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"FINISH_REASON_UNSPECIFIED" => Some(Self::Unspecified),
"STOP" => Some(Self::Stop),
"MAX_TOKENS" => Some(Self::MaxTokens),
"SAFETY" => Some(Self::Safety),
"RECITATION" => Some(Self::Recitation),
"LANGUAGE" => Some(Self::Language),
"OTHER" => Some(Self::Other),
"BLOCKLIST" => Some(Self::Blocklist),
"PROHIBITED_CONTENT" => Some(Self::ProhibitedContent),
"SPII" => Some(Self::Spii),
"MALFORMED_FUNCTION_CALL" => Some(Self::MalformedFunctionCall),
_ => None,
}
}
}
}
/// Request containing the `Content` for the model to embed.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EmbedContentRequest {
/// Required. The model's resource name. This serves as an ID for the Model to
/// use.
///
/// This name should match a model name returned by the `ListModels` method.
///
/// Format: `models/{model}`
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. The content to embed. Only the `parts.text` fields will be
/// counted.
#[prost(message, optional, tag = "2")]
pub content: ::core::option::Option<Content>,
/// Optional. Optional task type for which the embeddings will be used. Can
/// only be set for `models/embedding-001`.
#[prost(enumeration = "TaskType", optional, tag = "3")]
pub task_type: ::core::option::Option<i32>,
/// Optional. An optional title for the text. Only applicable when TaskType is
/// `RETRIEVAL_DOCUMENT`.
///
/// Note: Specifying a `title` for `RETRIEVAL_DOCUMENT` provides better quality
/// embeddings for retrieval.
#[prost(string, optional, tag = "4")]
pub title: ::core::option::Option<::prost::alloc::string::String>,
/// Optional. Optional reduced dimension for the output embedding. If set,
/// excessive values in the output embedding are truncated from the end.
/// Supported by newer models since 2024 only. You cannot set this value if
/// using the earlier model (`models/embedding-001`).
#[prost(int32, optional, tag = "5")]
pub output_dimensionality: ::core::option::Option<i32>,
}
/// A list of floats representing an embedding.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ContentEmbedding {
/// The embedding values.
#[prost(float, repeated, tag = "1")]
pub values: ::prost::alloc::vec::Vec<f32>,
}
/// The response to an `EmbedContentRequest`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EmbedContentResponse {
/// Output only. The embedding generated from the input content.
#[prost(message, optional, tag = "1")]
pub embedding: ::core::option::Option<ContentEmbedding>,
}
/// Batch request to get embeddings from the model for a list of prompts.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BatchEmbedContentsRequest {
/// Required. The model's resource name. This serves as an ID for the Model to
/// use.
///
/// This name should match a model name returned by the `ListModels` method.
///
/// Format: `models/{model}`
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. Embed requests for the batch. The model in each of these requests
/// must match the model specified `BatchEmbedContentsRequest.model`.
#[prost(message, repeated, tag = "2")]
pub requests: ::prost::alloc::vec::Vec<EmbedContentRequest>,
}
/// The response to a `BatchEmbedContentsRequest`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BatchEmbedContentsResponse {
/// Output only. The embeddings for each request, in the same order as provided
/// in the batch request.
#[prost(message, repeated, tag = "1")]
pub embeddings: ::prost::alloc::vec::Vec<ContentEmbedding>,
}
/// Counts the number of tokens in the `prompt` sent to a model.
///
/// Models may tokenize text differently, so each model may return a different
/// `token_count`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CountTokensRequest {
/// Required. The model's resource name. This serves as an ID for the Model to
/// use.
///
/// This name should match a model name returned by the `ListModels` method.
///
/// Format: `models/{model}`
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Optional. The input given to the model as a prompt. This field is ignored
/// when `generate_content_request` is set.
#[prost(message, repeated, tag = "2")]
pub contents: ::prost::alloc::vec::Vec<Content>,
/// Optional. The overall input given to the `Model`. This includes the prompt
/// as well as other model steering information like [system
/// instructions](<https://ai.google.dev/gemini-api/docs/system-instructions>),
/// and/or function declarations for [function
/// calling](<https://ai.google.dev/gemini-api/docs/function-calling>).
/// `Model`s/`Content`s and `generate_content_request`s are mutually
/// exclusive. You can either send `Model` + `Content`s or a
/// `generate_content_request`, but never both.
#[prost(message, optional, tag = "3")]
pub generate_content_request: ::core::option::Option<GenerateContentRequest>,
}
/// A response from `CountTokens`.
///
/// It returns the model's `token_count` for the `prompt`.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct CountTokensResponse {
/// The number of tokens that the `Model` tokenizes the `prompt` into. Always
/// non-negative.
#[prost(int32, tag = "1")]
pub total_tokens: i32,
}
/// Type of task for which the embedding will be used.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TaskType {
/// Unset value, which will default to one of the other enum values.
Unspecified = 0,
/// Specifies the given text is a query in a search/retrieval setting.
RetrievalQuery = 1,
/// Specifies the given text is a document from the corpus being searched.
RetrievalDocument = 2,
/// Specifies the given text will be used for STS.
SemanticSimilarity = 3,
/// Specifies that the given text will be classified.
Classification = 4,
/// Specifies that the embeddings will be used for clustering.
Clustering = 5,
/// Specifies that the given text will be used for question answering.
QuestionAnswering = 6,
/// Specifies that the given text will be used for fact verification.
FactVerification = 7,
}
impl TaskType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
TaskType::Unspecified => "TASK_TYPE_UNSPECIFIED",
TaskType::RetrievalQuery => "RETRIEVAL_QUERY",
TaskType::RetrievalDocument => "RETRIEVAL_DOCUMENT",
TaskType::SemanticSimilarity => "SEMANTIC_SIMILARITY",
TaskType::Classification => "CLASSIFICATION",
TaskType::Clustering => "CLUSTERING",
TaskType::QuestionAnswering => "QUESTION_ANSWERING",
TaskType::FactVerification => "FACT_VERIFICATION",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TASK_TYPE_UNSPECIFIED" => Some(Self::Unspecified),
"RETRIEVAL_QUERY" => Some(Self::RetrievalQuery),
"RETRIEVAL_DOCUMENT" => Some(Self::RetrievalDocument),
"SEMANTIC_SIMILARITY" => Some(Self::SemanticSimilarity),
"CLASSIFICATION" => Some(Self::Classification),
"CLUSTERING" => Some(Self::Clustering),
"QUESTION_ANSWERING" => Some(Self::QuestionAnswering),
"FACT_VERIFICATION" => Some(Self::FactVerification),
_ => None,
}
}
}
/// Generated client implementations.
pub mod generative_service_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// API for using Large Models that generate multimodal content and have
/// additional capabilities beyond text generation.
#[derive(Debug, Clone)]
pub struct GenerativeServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl<T> GenerativeServiceClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> GenerativeServiceClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
GenerativeServiceClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// Generates a model response given an input `GenerateContentRequest`.
/// Refer to the [text generation
/// guide](https://ai.google.dev/gemini-api/docs/text-generation) for detailed
/// usage information. Input capabilities differ between models, including
/// tuned models. Refer to the [model
/// guide](https://ai.google.dev/gemini-api/docs/models/gemini) and [tuning
/// guide](https://ai.google.dev/gemini-api/docs/model-tuning) for details.
pub async fn generate_content(
&mut self,
request: impl tonic::IntoRequest<super::GenerateContentRequest>,
) -> std::result::Result<
tonic::Response<super::GenerateContentResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.GenerativeService/GenerateContent",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.GenerativeService",
"GenerateContent",
),
);
self.inner.unary(req, path, codec).await
}
/// Generates a [streamed
/// response](https://ai.google.dev/gemini-api/docs/text-generation?lang=python#generate-a-text-stream)
/// from the model given an input `GenerateContentRequest`.
pub async fn stream_generate_content(
&mut self,
request: impl tonic::IntoRequest<super::GenerateContentRequest>,
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::GenerateContentResponse>>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.GenerativeService/StreamGenerateContent",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.GenerativeService",
"StreamGenerateContent",
),
);
self.inner.server_streaming(req, path, codec).await
}
/// Generates a text embedding vector from the input `Content` using the
/// specified [Gemini Embedding
/// model](https://ai.google.dev/gemini-api/docs/models/gemini#text-embedding).
pub async fn embed_content(
&mut self,
request: impl tonic::IntoRequest<super::EmbedContentRequest>,
) -> std::result::Result<
tonic::Response<super::EmbedContentResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.GenerativeService/EmbedContent",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.GenerativeService",
"EmbedContent",
),
);
self.inner.unary(req, path, codec).await
}
/// Generates multiple embedding vectors from the input `Content` which
/// consists of a batch of strings represented as `EmbedContentRequest`
/// objects.
pub async fn batch_embed_contents(
&mut self,
request: impl tonic::IntoRequest<super::BatchEmbedContentsRequest>,
) -> std::result::Result<
tonic::Response<super::BatchEmbedContentsResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.GenerativeService/BatchEmbedContents",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.GenerativeService",
"BatchEmbedContents",
),
);
self.inner.unary(req, path, codec).await
}
/// Runs a model's tokenizer on input `Content` and returns the token count.
/// Refer to the [tokens guide](https://ai.google.dev/gemini-api/docs/tokens)
/// to learn more about tokens.
pub async fn count_tokens(
&mut self,
request: impl tonic::IntoRequest<super::CountTokensRequest>,
) -> std::result::Result<
tonic::Response<super::CountTokensResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.ai.generativelanguage.v1.GenerativeService/CountTokens",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1.GenerativeService",
"CountTokens",
),
);
self.inner.unary(req, path, codec).await
}
}
}