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
// 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`.
///
/// Format: `models/{model}` with a `{model}` naming convention of:
///
/// * "{base_model_id}-{version}"
///
/// Examples:
///
/// * `models/chat-bison-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:
///
/// * `chat-bison`
#[prost(string, tag = "2")]
pub base_model_id: ::prost::alloc::string::String,
/// Required. The version number of the model.
///
/// This represents the major version
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
/// The human-readable name of the model. E.g. "Chat Bison".
///
/// 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 method names are defined as Pascal case
/// strings, such as `generateMessage` which correspond to API methods.
#[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,1.0\]`, inclusive. A value closer to `1.0` 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>,
/// For Nucleus sampling.
///
/// 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.
#[prost(int32, optional, tag = "11")]
pub top_k: ::core::option::Option<i32>,
}
/// 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).
///
/// The service may return fewer models.
/// If unspecified, at most 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.
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.v1beta2.ModelService/GetModel",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.ModelService",
"GetModel",
),
);
self.inner.unary(req, path, codec).await
}
/// Lists models available through the 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.v1beta2.ModelService/ListModels",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.ModelService",
"ListModels",
),
);
self.inner.unary(req, path, codec).await
}
}
}
/// 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>,
}
/// Content filtering metadata associated with processing a single request.
///
/// ContentFilter contains a reason and an optional supporting string. The reason
/// may be unspecified.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ContentFilter {
/// The reason content was blocked during request processing.
#[prost(enumeration = "content_filter::BlockedReason", tag = "1")]
pub reason: i32,
/// A string that describes the filtering behavior in more detail.
#[prost(string, optional, tag = "2")]
pub message: ::core::option::Option<::prost::alloc::string::String>,
}
/// Nested message and enum types in `ContentFilter`.
pub mod content_filter {
/// A list of reasons why content may have been blocked.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum BlockedReason {
/// A blocked reason was not specified.
Unspecified = 0,
/// Content was blocked by safety settings.
Safety = 1,
/// Content was blocked, but the reason is uncategorized.
Other = 2,
}
impl BlockedReason {
/// 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 {
BlockedReason::Unspecified => "BLOCKED_REASON_UNSPECIFIED",
BlockedReason::Safety => "SAFETY",
BlockedReason::Other => "OTHER",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"BLOCKED_REASON_UNSPECIFIED" => Some(Self::Unspecified),
"SAFETY" => Some(Self::Safety),
"OTHER" => Some(Self::Other),
_ => None,
}
}
}
}
/// Safety feedback for an entire request.
///
/// This field is populated if content in the input and/or response is blocked
/// due to safety settings. SafetyFeedback may not exist for every HarmCategory.
/// Each SafetyFeedback will return the safety settings used by the request as
/// well as the lowest HarmProbability that should be allowed in order to return
/// a result.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct SafetyFeedback {
/// Safety rating evaluated from content.
#[prost(message, optional, tag = "1")]
pub rating: ::core::option::Option<SafetyRating>,
/// Safety settings applied to the request.
#[prost(message, optional, tag = "2")]
pub setting: ::core::option::Option<SafetySetting>,
}
/// 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,
}
/// 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 proability 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,
}
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",
}
}
/// 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),
_ => 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, disrepspectful, or profane.
Toxicity = 2,
/// Describes scenarios depictng 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,
}
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",
}
}
/// 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),
_ => None,
}
}
}
/// Request to generate a text completion response from the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateTextRequest {
/// Required. The model name to use with the format name=models/{model}.
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. The free-form input text given to the model as a prompt.
///
/// Given a prompt, the model will generate a TextCompletion response it
/// predicts as the completion of the input text.
#[prost(message, optional, tag = "2")]
pub prompt: ::core::option::Option<TextPrompt>,
/// Controls the randomness of the output.
/// Note: The default value varies by model, see the `Model.temperature`
/// attribute of the `Model` returned the `getModel` function.
///
/// Values can range from \[0.0,1.0\],
/// inclusive. A value closer to 1.0 will produce responses that are more
/// varied and creative, while a value closer to 0.0 will typically result in
/// more straightforward responses from the model.
#[prost(float, optional, tag = "3")]
pub temperature: ::core::option::Option<f32>,
/// Number of generated responses to return.
///
/// This value must be between \[1, 8\], inclusive. If unset, this will default
/// to 1.
#[prost(int32, optional, tag = "4")]
pub candidate_count: ::core::option::Option<i32>,
/// The maximum number of tokens to include in a candidate.
///
/// If unset, this will default to 64.
#[prost(int32, optional, tag = "5")]
pub max_output_tokens: ::core::option::Option<i32>,
/// The maximum cumulative probability of tokens to consider when sampling.
///
/// The model uses combined Top-k and nucleus sampling.
///
/// Tokens are sorted based on their assigned probabilities so that only the
/// most liekly tokens are considered. Top-k sampling directly limits the
/// maximum number of tokens to consider, while Nucleus sampling limits number
/// of tokens based on the cumulative probability.
///
/// Note: The default value varies by model, see the `Model.top_p`
/// attribute of the `Model` returned the `getModel` function.
#[prost(float, optional, tag = "6")]
pub top_p: ::core::option::Option<f32>,
/// The maximum number of tokens to consider when sampling.
///
/// The model uses combined Top-k and nucleus sampling.
///
/// Top-k sampling considers the set of `top_k` most probable tokens.
/// Defaults to 40.
///
/// Note: The default value varies by model, see the `Model.top_k`
/// attribute of the `Model` returned the `getModel` function.
#[prost(int32, optional, tag = "7")]
pub top_k: ::core::option::Option<i32>,
/// A list of unique `SafetySetting` instances for blocking unsafe content.
///
/// that will be enforced on the `GenerateTextRequest.prompt` and
/// `GenerateTextResponse.candidates`. There should not be more than one
/// setting for each `SafetyCategory` type. The API will block any prompts 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.
#[prost(message, repeated, tag = "8")]
pub safety_settings: ::prost::alloc::vec::Vec<SafetySetting>,
/// 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 = "9")]
pub stop_sequences: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// The response from the model, including candidate completions.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateTextResponse {
/// Candidate responses from the model.
#[prost(message, repeated, tag = "1")]
pub candidates: ::prost::alloc::vec::Vec<TextCompletion>,
/// A set of content filtering metadata for the prompt and response
/// text.
///
/// This indicates which `SafetyCategory`(s) blocked a
/// candidate from this response, the lowest `HarmProbability`
/// that triggered a block, and the HarmThreshold setting for that category.
/// This indicates the smallest change to the `SafetySettings` that would be
/// necessary to unblock at least 1 response.
///
/// The blocking is configured by the `SafetySettings` in the request (or the
/// default `SafetySettings` of the API).
#[prost(message, repeated, tag = "3")]
pub filters: ::prost::alloc::vec::Vec<ContentFilter>,
/// Returns any safety feedback related to content filtering.
#[prost(message, repeated, tag = "4")]
pub safety_feedback: ::prost::alloc::vec::Vec<SafetyFeedback>,
}
/// Text given to the model as a prompt.
///
/// The Model will use this TextPrompt to Generate a text completion.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TextPrompt {
/// Required. The prompt text.
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
}
/// Output text returned from a model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TextCompletion {
/// Output only. The generated text returned from the model.
#[prost(string, tag = "1")]
pub output: ::prost::alloc::string::String,
/// Ratings for the safety of a response.
///
/// There is at most one rating per category.
#[prost(message, repeated, tag = "2")]
pub safety_ratings: ::prost::alloc::vec::Vec<SafetyRating>,
/// Output only. Citation information for model-generated `output` in this
/// `TextCompletion`.
///
/// This field may be populated with attribution information for any text
/// included in the `output`.
#[prost(message, optional, tag = "3")]
pub citation_metadata: ::core::option::Option<CitationMetadata>,
}
/// Request to get a text embedding from the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EmbedTextRequest {
/// Required. The model name to use with the format model=models/{model}.
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. The free-form input text that the model will turn into an
/// embedding.
#[prost(string, tag = "2")]
pub text: ::prost::alloc::string::String,
}
/// The response to a EmbedTextRequest.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EmbedTextResponse {
/// Output only. The embedding generated from the input text.
#[prost(message, optional, tag = "1")]
pub embedding: ::core::option::Option<Embedding>,
}
/// A list of floats representing the embedding.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Embedding {
/// The embedding values.
#[prost(float, repeated, tag = "1")]
pub value: ::prost::alloc::vec::Vec<f32>,
}
/// Generated client implementations.
pub mod text_service_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// API for using Generative Language Models (GLMs) trained to generate text.
///
/// Also known as Large Language Models (LLM)s, these generate text given an
/// input prompt from the user.
#[derive(Debug, Clone)]
pub struct TextServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl<T> TextServiceClient<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,
) -> TextServiceClient<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,
{
TextServiceClient::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 response from the model given an input message.
pub async fn generate_text(
&mut self,
request: impl tonic::IntoRequest<super::GenerateTextRequest>,
) -> std::result::Result<
tonic::Response<super::GenerateTextResponse>,
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.v1beta2.TextService/GenerateText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.TextService",
"GenerateText",
),
);
self.inner.unary(req, path, codec).await
}
/// Generates an embedding from the model given an input message.
pub async fn embed_text(
&mut self,
request: impl tonic::IntoRequest<super::EmbedTextRequest>,
) -> std::result::Result<
tonic::Response<super::EmbedTextResponse>,
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.v1beta2.TextService/EmbedText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.TextService",
"EmbedText",
),
);
self.inner.unary(req, path, codec).await
}
}
}
/// Request to generate a message response from the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateMessageRequest {
/// Required. The name of the model to use.
///
/// Format: `name=models/{model}`.
#[prost(string, tag = "1")]
pub model: ::prost::alloc::string::String,
/// Required. The structured textual input given to the model as a prompt.
///
/// Given a
/// prompt, the model will return what it predicts is the next message in the
/// discussion.
#[prost(message, optional, tag = "2")]
pub prompt: ::core::option::Option<MessagePrompt>,
/// Optional. Controls the randomness of the output.
///
/// Values can range over `\[0.0,1.0\]`,
/// inclusive. A value closer to `1.0` will produce responses that are more
/// varied, while a value closer to `0.0` will typically result in
/// less surprising responses from the model.
#[prost(float, optional, tag = "3")]
pub temperature: ::core::option::Option<f32>,
/// Optional. The number of generated response messages to return.
///
/// This value must be between
/// `\[1, 8\]`, inclusive. If unset, this will default to `1`.
#[prost(int32, optional, tag = "4")]
pub candidate_count: ::core::option::Option<i32>,
/// Optional. The maximum cumulative probability of tokens to consider when
/// sampling.
///
/// The model uses combined Top-k and nucleus sampling.
///
/// Nucleus sampling considers the smallest set of tokens whose probability
/// sum is at least `top_p`.
#[prost(float, optional, tag = "5")]
pub top_p: ::core::option::Option<f32>,
/// Optional. The maximum number of tokens to consider when sampling.
///
/// The model uses combined Top-k and nucleus sampling.
///
/// Top-k sampling considers the set of `top_k` most probable tokens.
#[prost(int32, optional, tag = "6")]
pub top_k: ::core::option::Option<i32>,
}
/// The response from the model.
///
/// This includes candidate messages and
/// conversation history in the form of chronologically-ordered messages.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateMessageResponse {
/// Candidate response messages from the model.
#[prost(message, repeated, tag = "1")]
pub candidates: ::prost::alloc::vec::Vec<Message>,
/// The conversation history used by the model.
#[prost(message, repeated, tag = "2")]
pub messages: ::prost::alloc::vec::Vec<Message>,
/// A set of content filtering metadata for the prompt and response
/// text.
///
/// This indicates which `SafetyCategory`(s) blocked a
/// candidate from this response, the lowest `HarmProbability`
/// that triggered a block, and the HarmThreshold setting for that category.
#[prost(message, repeated, tag = "3")]
pub filters: ::prost::alloc::vec::Vec<ContentFilter>,
}
/// The base unit of structured text.
///
/// A `Message` includes an `author` and the `content` of
/// the `Message`.
///
/// The `author` is used to tag messages when they are fed to the
/// model as text.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Message {
/// Optional. The author of this Message.
///
/// This serves as a key for tagging
/// the content of this Message when it is fed to the model as text.
///
/// The author can be any alphanumeric string.
#[prost(string, tag = "1")]
pub author: ::prost::alloc::string::String,
/// Required. The text content of the structured `Message`.
#[prost(string, tag = "2")]
pub content: ::prost::alloc::string::String,
/// Output only. Citation information for model-generated `content` in this
/// `Message`.
///
/// If this `Message` was generated as output from the model, this field may be
/// populated with attribution information for any text included in the
/// `content`. This field is used only on output.
#[prost(message, optional, tag = "3")]
pub citation_metadata: ::core::option::Option<CitationMetadata>,
}
/// All of the structured input text passed to the model as a prompt.
///
/// A `MessagePrompt` contains a structured set of fields that provide context
/// for the conversation, examples of user input/model output message pairs that
/// prime the model to respond in different ways, and the conversation history
/// or list of messages representing the alternating turns of the conversation
/// between the user and the model.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MessagePrompt {
/// Optional. Text that should be provided to the model first to ground the
/// response.
///
/// If not empty, this `context` will be given to the model first before the
/// `examples` and `messages`. When using a `context` be sure to provide it
/// with every request to maintain continuity.
///
/// This field can be a description of your prompt to the model to help provide
/// context and guide the responses. Examples: "Translate the phrase from
/// English to French." or "Given a statement, classify the sentiment as happy,
/// sad or neutral."
///
/// Anything included in this field will take precedence over message history
/// if the total input size exceeds the model's `input_token_limit` and the
/// input request is truncated.
#[prost(string, tag = "1")]
pub context: ::prost::alloc::string::String,
/// Optional. Examples of what the model should generate.
///
/// This includes both user input and the response that the model should
/// emulate.
///
/// These `examples` are treated identically to conversation messages except
/// that they take precedence over the history in `messages`:
/// If the total input size exceeds the model's `input_token_limit` the input
/// will be truncated. Items will be dropped from `messages` before `examples`.
#[prost(message, repeated, tag = "2")]
pub examples: ::prost::alloc::vec::Vec<Example>,
/// Required. A snapshot of the recent conversation history sorted
/// chronologically.
///
/// Turns alternate between two authors.
///
/// If the total input size exceeds the model's `input_token_limit` the input
/// will be truncated: The oldest items will be dropped from `messages`.
#[prost(message, repeated, tag = "3")]
pub messages: ::prost::alloc::vec::Vec<Message>,
}
/// An input/output example used to instruct the Model.
///
/// It demonstrates how the model should respond or format its response.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Example {
/// Required. An example of an input `Message` from the user.
#[prost(message, optional, tag = "1")]
pub input: ::core::option::Option<Message>,
/// Required. An example of what the model should output given the input.
#[prost(message, optional, tag = "2")]
pub output: ::core::option::Option<Message>,
}
/// 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 CountMessageTokensRequest {
/// 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 prompt, whose token count is to be returned.
#[prost(message, optional, tag = "2")]
pub prompt: ::core::option::Option<MessagePrompt>,
}
/// A response from `CountMessageTokens`.
///
/// It returns the model's `token_count` for the `prompt`.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct CountMessageTokensResponse {
/// The number of tokens that the `model` tokenizes the `prompt` into.
///
/// Always non-negative.
#[prost(int32, tag = "1")]
pub token_count: i32,
}
/// Generated client implementations.
pub mod discuss_service_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// An API for using Generative Language Models (GLMs) in dialog applications.
///
/// Also known as large language models (LLMs), this API provides models that
/// are trained for multi-turn dialog.
#[derive(Debug, Clone)]
pub struct DiscussServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl<T> DiscussServiceClient<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,
) -> DiscussServiceClient<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,
{
DiscussServiceClient::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 response from the model given an input `MessagePrompt`.
pub async fn generate_message(
&mut self,
request: impl tonic::IntoRequest<super::GenerateMessageRequest>,
) -> std::result::Result<
tonic::Response<super::GenerateMessageResponse>,
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.v1beta2.DiscussService/GenerateMessage",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.DiscussService",
"GenerateMessage",
),
);
self.inner.unary(req, path, codec).await
}
/// Runs a model's tokenizer on a string and returns the token count.
pub async fn count_message_tokens(
&mut self,
request: impl tonic::IntoRequest<super::CountMessageTokensRequest>,
) -> std::result::Result<
tonic::Response<super::CountMessageTokensResponse>,
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.v1beta2.DiscussService/CountMessageTokens",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.ai.generativelanguage.v1beta2.DiscussService",
"CountMessageTokens",
),
);
self.inner.unary(req, path, codec).await
}
}
}