3 3 | /// <p>The tokens used in a message API inference call.</p>
|
4 4 | #[non_exhaustive]
|
5 5 | #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
|
6 6 | pub struct TokenUsage {
|
7 7 | /// <p>The number of tokens sent in the request to the model.</p>
|
8 8 | pub input_tokens: i32,
|
9 9 | /// <p>The number of tokens that the model generated for the request.</p>
|
10 10 | pub output_tokens: i32,
|
11 11 | /// <p>The total of input tokens and tokens generated by the model.</p>
|
12 12 | pub total_tokens: i32,
|
13 + | /// <p>The number of input tokens read from the cache for the request.</p>
|
14 + | pub cache_read_input_tokens: ::std::option::Option<i32>,
|
15 + | /// <p>The number of input tokens written to the cache for the request.</p>
|
16 + | pub cache_write_input_tokens: ::std::option::Option<i32>,
|
13 17 | }
|
14 18 | impl TokenUsage {
|
15 19 | /// <p>The number of tokens sent in the request to the model.</p>
|
16 20 | pub fn input_tokens(&self) -> i32 {
|
17 21 | self.input_tokens
|
18 22 | }
|
19 23 | /// <p>The number of tokens that the model generated for the request.</p>
|
20 24 | pub fn output_tokens(&self) -> i32 {
|
21 25 | self.output_tokens
|
22 26 | }
|
23 27 | /// <p>The total of input tokens and tokens generated by the model.</p>
|
24 28 | pub fn total_tokens(&self) -> i32 {
|
25 29 | self.total_tokens
|
26 30 | }
|
31 + | /// <p>The number of input tokens read from the cache for the request.</p>
|
32 + | pub fn cache_read_input_tokens(&self) -> ::std::option::Option<i32> {
|
33 + | self.cache_read_input_tokens
|
34 + | }
|
35 + | /// <p>The number of input tokens written to the cache for the request.</p>
|
36 + | pub fn cache_write_input_tokens(&self) -> ::std::option::Option<i32> {
|
37 + | self.cache_write_input_tokens
|
38 + | }
|
27 39 | }
|
28 40 | impl TokenUsage {
|
29 41 | /// Creates a new builder-style object to manufacture [`TokenUsage`](crate::types::TokenUsage).
|
30 42 | pub fn builder() -> crate::types::builders::TokenUsageBuilder {
|
31 43 | crate::types::builders::TokenUsageBuilder::default()
|
32 44 | }
|
33 45 | }
|
34 46 |
|
35 47 | /// A builder for [`TokenUsage`](crate::types::TokenUsage).
|
36 48 | #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
|
37 49 | #[non_exhaustive]
|
38 50 | pub struct TokenUsageBuilder {
|
39 51 | pub(crate) input_tokens: ::std::option::Option<i32>,
|
40 52 | pub(crate) output_tokens: ::std::option::Option<i32>,
|
41 53 | pub(crate) total_tokens: ::std::option::Option<i32>,
|
54 + | pub(crate) cache_read_input_tokens: ::std::option::Option<i32>,
|
55 + | pub(crate) cache_write_input_tokens: ::std::option::Option<i32>,
|
42 56 | }
|
43 57 | impl TokenUsageBuilder {
|
44 58 | /// <p>The number of tokens sent in the request to the model.</p>
|
45 59 | /// This field is required.
|
46 60 | pub fn input_tokens(mut self, input: i32) -> Self {
|
47 61 | self.input_tokens = ::std::option::Option::Some(input);
|
48 62 | self
|
49 63 | }
|
50 64 | /// <p>The number of tokens sent in the request to the model.</p>
|
51 65 | pub fn set_input_tokens(mut self, input: ::std::option::Option<i32>) -> Self {
|
52 66 | self.input_tokens = input;
|
53 67 | self
|
54 68 | }
|
55 69 | /// <p>The number of tokens sent in the request to the model.</p>
|
56 70 | pub fn get_input_tokens(&self) -> &::std::option::Option<i32> {
|
57 71 | &self.input_tokens
|
58 72 | }
|
59 73 | /// <p>The number of tokens that the model generated for the request.</p>
|
60 74 | /// This field is required.
|
61 75 | pub fn output_tokens(mut self, input: i32) -> Self {
|
62 76 | self.output_tokens = ::std::option::Option::Some(input);
|
63 77 | self
|
64 78 | }
|
65 79 | /// <p>The number of tokens that the model generated for the request.</p>
|
66 80 | pub fn set_output_tokens(mut self, input: ::std::option::Option<i32>) -> Self {
|
67 81 | self.output_tokens = input;
|
68 82 | self
|
69 83 | }
|
70 84 | /// <p>The number of tokens that the model generated for the request.</p>
|
71 85 | pub fn get_output_tokens(&self) -> &::std::option::Option<i32> {
|
72 86 | &self.output_tokens
|
73 87 | }
|
74 88 | /// <p>The total of input tokens and tokens generated by the model.</p>
|
75 89 | /// This field is required.
|
76 90 | pub fn total_tokens(mut self, input: i32) -> Self {
|
77 91 | self.total_tokens = ::std::option::Option::Some(input);
|
78 92 | self
|
79 93 | }
|
80 94 | /// <p>The total of input tokens and tokens generated by the model.</p>
|
81 95 | pub fn set_total_tokens(mut self, input: ::std::option::Option<i32>) -> Self {
|
82 96 | self.total_tokens = input;
|
83 97 | self
|
84 98 | }
|
85 99 | /// <p>The total of input tokens and tokens generated by the model.</p>
|
86 100 | pub fn get_total_tokens(&self) -> &::std::option::Option<i32> {
|
87 101 | &self.total_tokens
|
88 102 | }
|
103 + | /// <p>The number of input tokens read from the cache for the request.</p>
|
104 + | pub fn cache_read_input_tokens(mut self, input: i32) -> Self {
|
105 + | self.cache_read_input_tokens = ::std::option::Option::Some(input);
|
106 + | self
|
107 + | }
|
108 + | /// <p>The number of input tokens read from the cache for the request.</p>
|
109 + | pub fn set_cache_read_input_tokens(mut self, input: ::std::option::Option<i32>) -> Self {
|
110 + | self.cache_read_input_tokens = input;
|
111 + | self
|
112 + | }
|
113 + | /// <p>The number of input tokens read from the cache for the request.</p>
|
114 + | pub fn get_cache_read_input_tokens(&self) -> &::std::option::Option<i32> {
|
115 + | &self.cache_read_input_tokens
|
116 + | }
|
117 + | /// <p>The number of input tokens written to the cache for the request.</p>
|
118 + | pub fn cache_write_input_tokens(mut self, input: i32) -> Self {
|
119 + | self.cache_write_input_tokens = ::std::option::Option::Some(input);
|
120 + | self
|
121 + | }
|
122 + | /// <p>The number of input tokens written to the cache for the request.</p>
|
123 + | pub fn set_cache_write_input_tokens(mut self, input: ::std::option::Option<i32>) -> Self {
|
124 + | self.cache_write_input_tokens = input;
|
125 + | self
|
126 + | }
|
127 + | /// <p>The number of input tokens written to the cache for the request.</p>
|
128 + | pub fn get_cache_write_input_tokens(&self) -> &::std::option::Option<i32> {
|
129 + | &self.cache_write_input_tokens
|
130 + | }
|
89 131 | /// Consumes the builder and constructs a [`TokenUsage`](crate::types::TokenUsage).
|
90 132 | /// This method will fail if any of the following fields are not set:
|
91 133 | /// - [`input_tokens`](crate::types::builders::TokenUsageBuilder::input_tokens)
|
92 134 | /// - [`output_tokens`](crate::types::builders::TokenUsageBuilder::output_tokens)
|
93 135 | /// - [`total_tokens`](crate::types::builders::TokenUsageBuilder::total_tokens)
|
94 136 | pub fn build(self) -> ::std::result::Result<crate::types::TokenUsage, ::aws_smithy_types::error::operation::BuildError> {
|
95 137 | ::std::result::Result::Ok(crate::types::TokenUsage {
|
96 138 | input_tokens: self.input_tokens.ok_or_else(|| {
|
97 139 | ::aws_smithy_types::error::operation::BuildError::missing_field(
|
98 140 | "input_tokens",
|
99 141 | "input_tokens was not specified but it is required when building TokenUsage",
|
100 142 | )
|
101 143 | })?,
|
102 144 | output_tokens: self.output_tokens.ok_or_else(|| {
|
103 145 | ::aws_smithy_types::error::operation::BuildError::missing_field(
|
104 146 | "output_tokens",
|
105 147 | "output_tokens was not specified but it is required when building TokenUsage",
|
106 148 | )
|
107 149 | })?,
|
108 150 | total_tokens: self.total_tokens.ok_or_else(|| {
|
109 151 | ::aws_smithy_types::error::operation::BuildError::missing_field(
|
110 152 | "total_tokens",
|
111 153 | "total_tokens was not specified but it is required when building TokenUsage",
|
112 154 | )
|
113 155 | })?,
|
156 + | cache_read_input_tokens: self.cache_read_input_tokens,
|
157 + | cache_write_input_tokens: self.cache_write_input_tokens,
|
114 158 | })
|
115 159 | }
|
116 160 | }
|