koichi12 commited on
Commit
607b7b9
·
verified ·
1 Parent(s): 58a2d66

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .venv/lib/python3.11/site-packages/google/api/backend.proto +185 -0
  2. .venv/lib/python3.11/site-packages/google/api/client.proto +462 -0
  3. .venv/lib/python3.11/site-packages/google/api/field_behavior.proto +104 -0
  4. .venv/lib/python3.11/site-packages/google/generativeai/__pycache__/__init__.cpython-311.pyc +0 -0
  5. .venv/lib/python3.11/site-packages/google/generativeai/__pycache__/client.cpython-311.pyc +0 -0
  6. .venv/lib/python3.11/site-packages/google/generativeai/__pycache__/discuss.cpython-311.pyc +0 -0
  7. .venv/lib/python3.11/site-packages/google/generativeai/__pycache__/protos.cpython-311.pyc +0 -0
  8. .venv/lib/python3.11/site-packages/google/generativeai/__pycache__/utils.cpython-311.pyc +0 -0
  9. .venv/lib/python3.11/site-packages/google/generativeai/types/__init__.py +29 -0
  10. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/citation_types.cpython-311.pyc +0 -0
  11. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/file_types.cpython-311.pyc +0 -0
  12. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/generation_types.cpython-311.pyc +0 -0
  13. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/palm_safety_types.cpython-311.pyc +0 -0
  14. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/permission_types.cpython-311.pyc +0 -0
  15. .venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/text_types.cpython-311.pyc +0 -0
  16. .venv/lib/python3.11/site-packages/google/generativeai/types/citation_types.py +42 -0
  17. .venv/lib/python3.11/site-packages/google/generativeai/types/helper_types.py +87 -0
  18. .venv/lib/python3.11/site-packages/google/generativeai/types/retriever_types.py +1698 -0
  19. .venv/lib/python3.11/site-packages/google/logging/type/http_request_pb2.py +47 -0
  20. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/__init__.cpython-311.pyc +0 -0
  21. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/any.cpython-311.pyc +0 -0
  22. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/any_pb2.cpython-311.pyc +0 -0
  23. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/api_pb2.cpython-311.pyc +0 -0
  24. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/descriptor_database.cpython-311.pyc +0 -0
  25. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/descriptor_pool.cpython-311.pyc +0 -0
  26. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/duration.cpython-311.pyc +0 -0
  27. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/empty_pb2.cpython-311.pyc +0 -0
  28. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/json_format.cpython-311.pyc +0 -0
  29. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto.cpython-311.pyc +0 -0
  30. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto_builder.cpython-311.pyc +0 -0
  31. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto_json.cpython-311.pyc +0 -0
  32. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/reflection.cpython-311.pyc +0 -0
  33. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/runtime_version.cpython-311.pyc +0 -0
  34. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/service.cpython-311.pyc +0 -0
  35. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/service_reflection.cpython-311.pyc +0 -0
  36. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/source_context_pb2.cpython-311.pyc +0 -0
  37. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/struct_pb2.cpython-311.pyc +0 -0
  38. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/timestamp.cpython-311.pyc +0 -0
  39. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/timestamp_pb2.cpython-311.pyc +0 -0
  40. .venv/lib/python3.11/site-packages/google/protobuf/__pycache__/wrappers_pb2.cpython-311.pyc +0 -0
  41. .venv/lib/python3.11/site-packages/google/protobuf/compiler/__init__.py +0 -0
  42. .venv/lib/python3.11/site-packages/google/protobuf/compiler/__pycache__/__init__.cpython-311.pyc +0 -0
  43. .venv/lib/python3.11/site-packages/google/protobuf/compiler/__pycache__/plugin_pb2.cpython-311.pyc +0 -0
  44. .venv/lib/python3.11/site-packages/google/protobuf/compiler/plugin_pb2.py +46 -0
  45. .venv/lib/python3.11/site-packages/google/protobuf/internal/__init__.py +7 -0
  46. .venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/__init__.cpython-311.pyc +0 -0
  47. .venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/_parameterized.cpython-311.pyc +0 -0
  48. .venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/api_implementation.cpython-311.pyc +0 -0
  49. .venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/builder.cpython-311.pyc +0 -0
  50. .venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/containers.cpython-311.pyc +0 -0
.venv/lib/python3.11/site-packages/google/api/backend.proto ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2024 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ syntax = "proto3";
16
+
17
+ package google.api;
18
+
19
+ option go_package = "google.golang.org/genproto/googleapis/api/serviceconfig;serviceconfig";
20
+ option java_multiple_files = true;
21
+ option java_outer_classname = "BackendProto";
22
+ option java_package = "com.google.api";
23
+ option objc_class_prefix = "GAPI";
24
+
25
+ // `Backend` defines the backend configuration for a service.
26
+ message Backend {
27
+ // A list of API backend rules that apply to individual API methods.
28
+ //
29
+ // **NOTE:** All service configuration rules follow "last one wins" order.
30
+ repeated BackendRule rules = 1;
31
+ }
32
+
33
+ // A backend rule provides configuration for an individual API element.
34
+ message BackendRule {
35
+ // Path Translation specifies how to combine the backend address with the
36
+ // request path in order to produce the appropriate forwarding URL for the
37
+ // request.
38
+ //
39
+ // Path Translation is applicable only to HTTP-based backends. Backends which
40
+ // do not accept requests over HTTP/HTTPS should leave `path_translation`
41
+ // unspecified.
42
+ enum PathTranslation {
43
+ PATH_TRANSLATION_UNSPECIFIED = 0;
44
+
45
+ // Use the backend address as-is, with no modification to the path. If the
46
+ // URL pattern contains variables, the variable names and values will be
47
+ // appended to the query string. If a query string parameter and a URL
48
+ // pattern variable have the same name, this may result in duplicate keys in
49
+ // the query string.
50
+ //
51
+ // # Examples
52
+ //
53
+ // Given the following operation config:
54
+ //
55
+ // Method path: /api/company/{cid}/user/{uid}
56
+ // Backend address: https://example.cloudfunctions.net/getUser
57
+ //
58
+ // Requests to the following request paths will call the backend at the
59
+ // translated path:
60
+ //
61
+ // Request path: /api/company/widgetworks/user/johndoe
62
+ // Translated:
63
+ // https://example.cloudfunctions.net/getUser?cid=widgetworks&uid=johndoe
64
+ //
65
+ // Request path: /api/company/widgetworks/user/johndoe?timezone=EST
66
+ // Translated:
67
+ // https://example.cloudfunctions.net/getUser?timezone=EST&cid=widgetworks&uid=johndoe
68
+ CONSTANT_ADDRESS = 1;
69
+
70
+ // The request path will be appended to the backend address.
71
+ //
72
+ // # Examples
73
+ //
74
+ // Given the following operation config:
75
+ //
76
+ // Method path: /api/company/{cid}/user/{uid}
77
+ // Backend address: https://example.appspot.com
78
+ //
79
+ // Requests to the following request paths will call the backend at the
80
+ // translated path:
81
+ //
82
+ // Request path: /api/company/widgetworks/user/johndoe
83
+ // Translated:
84
+ // https://example.appspot.com/api/company/widgetworks/user/johndoe
85
+ //
86
+ // Request path: /api/company/widgetworks/user/johndoe?timezone=EST
87
+ // Translated:
88
+ // https://example.appspot.com/api/company/widgetworks/user/johndoe?timezone=EST
89
+ APPEND_PATH_TO_ADDRESS = 2;
90
+ }
91
+
92
+ // Selects the methods to which this rule applies.
93
+ //
94
+ // Refer to [selector][google.api.DocumentationRule.selector] for syntax
95
+ // details.
96
+ string selector = 1;
97
+
98
+ // The address of the API backend.
99
+ //
100
+ // The scheme is used to determine the backend protocol and security.
101
+ // The following schemes are accepted:
102
+ //
103
+ // SCHEME PROTOCOL SECURITY
104
+ // http:// HTTP None
105
+ // https:// HTTP TLS
106
+ // grpc:// gRPC None
107
+ // grpcs:// gRPC TLS
108
+ //
109
+ // It is recommended to explicitly include a scheme. Leaving out the scheme
110
+ // may cause constrasting behaviors across platforms.
111
+ //
112
+ // If the port is unspecified, the default is:
113
+ // - 80 for schemes without TLS
114
+ // - 443 for schemes with TLS
115
+ //
116
+ // For HTTP backends, use [protocol][google.api.BackendRule.protocol]
117
+ // to specify the protocol version.
118
+ string address = 2;
119
+
120
+ // The number of seconds to wait for a response from a request. The default
121
+ // varies based on the request protocol and deployment environment.
122
+ double deadline = 3;
123
+
124
+ // Deprecated, do not use.
125
+ double min_deadline = 4 [deprecated = true];
126
+
127
+ // The number of seconds to wait for the completion of a long running
128
+ // operation. The default is no deadline.
129
+ double operation_deadline = 5;
130
+
131
+ PathTranslation path_translation = 6;
132
+
133
+ // Authentication settings used by the backend.
134
+ //
135
+ // These are typically used to provide service management functionality to
136
+ // a backend served on a publicly-routable URL. The `authentication`
137
+ // details should match the authentication behavior used by the backend.
138
+ //
139
+ // For example, specifying `jwt_audience` implies that the backend expects
140
+ // authentication via a JWT.
141
+ //
142
+ // When authentication is unspecified, the resulting behavior is the same
143
+ // as `disable_auth` set to `true`.
144
+ //
145
+ // Refer to https://developers.google.com/identity/protocols/OpenIDConnect for
146
+ // JWT ID token.
147
+ oneof authentication {
148
+ // The JWT audience is used when generating a JWT ID token for the backend.
149
+ // This ID token will be added in the HTTP "authorization" header, and sent
150
+ // to the backend.
151
+ string jwt_audience = 7;
152
+
153
+ // When disable_auth is true, a JWT ID token won't be generated and the
154
+ // original "Authorization" HTTP header will be preserved. If the header is
155
+ // used to carry the original token and is expected by the backend, this
156
+ // field must be set to true to preserve the header.
157
+ bool disable_auth = 8;
158
+ }
159
+
160
+ // The protocol used for sending a request to the backend.
161
+ // The supported values are "http/1.1" and "h2".
162
+ //
163
+ // The default value is inferred from the scheme in the
164
+ // [address][google.api.BackendRule.address] field:
165
+ //
166
+ // SCHEME PROTOCOL
167
+ // http:// http/1.1
168
+ // https:// http/1.1
169
+ // grpc:// h2
170
+ // grpcs:// h2
171
+ //
172
+ // For secure HTTP backends (https://) that support HTTP/2, set this field
173
+ // to "h2" for improved performance.
174
+ //
175
+ // Configuring this field to non-default values is only supported for secure
176
+ // HTTP backends. This field will be ignored for all other backends.
177
+ //
178
+ // See
179
+ // https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids
180
+ // for more details on the supported values.
181
+ string protocol = 9;
182
+
183
+ // The map between request protocol and the backend address.
184
+ map<string, BackendRule> overrides_by_request_protocol = 10;
185
+ }
.venv/lib/python3.11/site-packages/google/api/client.proto ADDED
@@ -0,0 +1,462 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2024 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ syntax = "proto3";
16
+
17
+ package google.api;
18
+
19
+ import "google/api/launch_stage.proto";
20
+ import "google/protobuf/descriptor.proto";
21
+ import "google/protobuf/duration.proto";
22
+
23
+ option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
24
+ option java_multiple_files = true;
25
+ option java_outer_classname = "ClientProto";
26
+ option java_package = "com.google.api";
27
+ option objc_class_prefix = "GAPI";
28
+
29
+ extend google.protobuf.MethodOptions {
30
+ // A definition of a client library method signature.
31
+ //
32
+ // In client libraries, each proto RPC corresponds to one or more methods
33
+ // which the end user is able to call, and calls the underlying RPC.
34
+ // Normally, this method receives a single argument (a struct or instance
35
+ // corresponding to the RPC request object). Defining this field will
36
+ // add one or more overloads providing flattened or simpler method signatures
37
+ // in some languages.
38
+ //
39
+ // The fields on the method signature are provided as a comma-separated
40
+ // string.
41
+ //
42
+ // For example, the proto RPC and annotation:
43
+ //
44
+ // rpc CreateSubscription(CreateSubscriptionRequest)
45
+ // returns (Subscription) {
46
+ // option (google.api.method_signature) = "name,topic";
47
+ // }
48
+ //
49
+ // Would add the following Java overload (in addition to the method accepting
50
+ // the request object):
51
+ //
52
+ // public final Subscription createSubscription(String name, String topic)
53
+ //
54
+ // The following backwards-compatibility guidelines apply:
55
+ //
56
+ // * Adding this annotation to an unannotated method is backwards
57
+ // compatible.
58
+ // * Adding this annotation to a method which already has existing
59
+ // method signature annotations is backwards compatible if and only if
60
+ // the new method signature annotation is last in the sequence.
61
+ // * Modifying or removing an existing method signature annotation is
62
+ // a breaking change.
63
+ // * Re-ordering existing method signature annotations is a breaking
64
+ // change.
65
+ repeated string method_signature = 1051;
66
+ }
67
+
68
+ extend google.protobuf.ServiceOptions {
69
+ // The hostname for this service.
70
+ // This should be specified with no prefix or protocol.
71
+ //
72
+ // Example:
73
+ //
74
+ // service Foo {
75
+ // option (google.api.default_host) = "foo.googleapi.com";
76
+ // ...
77
+ // }
78
+ string default_host = 1049;
79
+
80
+ // OAuth scopes needed for the client.
81
+ //
82
+ // Example:
83
+ //
84
+ // service Foo {
85
+ // option (google.api.oauth_scopes) = \
86
+ // "https://www.googleapis.com/auth/cloud-platform";
87
+ // ...
88
+ // }
89
+ //
90
+ // If there is more than one scope, use a comma-separated string:
91
+ //
92
+ // Example:
93
+ //
94
+ // service Foo {
95
+ // option (google.api.oauth_scopes) = \
96
+ // "https://www.googleapis.com/auth/cloud-platform,"
97
+ // "https://www.googleapis.com/auth/monitoring";
98
+ // ...
99
+ // }
100
+ string oauth_scopes = 1050;
101
+
102
+ // The API version of this service, which should be sent by version-aware
103
+ // clients to the service. This allows services to abide by the schema and
104
+ // behavior of the service at the time this API version was deployed.
105
+ // The format of the API version must be treated as opaque by clients.
106
+ // Services may use a format with an apparent structure, but clients must
107
+ // not rely on this to determine components within an API version, or attempt
108
+ // to construct other valid API versions. Note that this is for upcoming
109
+ // functionality and may not be implemented for all services.
110
+ //
111
+ // Example:
112
+ //
113
+ // service Foo {
114
+ // option (google.api.api_version) = "v1_20230821_preview";
115
+ // }
116
+ string api_version = 525000001;
117
+ }
118
+
119
+ // Required information for every language.
120
+ message CommonLanguageSettings {
121
+ // Link to automatically generated reference documentation. Example:
122
+ // https://cloud.google.com/nodejs/docs/reference/asset/latest
123
+ string reference_docs_uri = 1 [deprecated = true];
124
+
125
+ // The destination where API teams want this client library to be published.
126
+ repeated ClientLibraryDestination destinations = 2;
127
+
128
+ // Configuration for which RPCs should be generated in the GAPIC client.
129
+ SelectiveGapicGeneration selective_gapic_generation = 3;
130
+ }
131
+
132
+ // Details about how and where to publish client libraries.
133
+ message ClientLibrarySettings {
134
+ // Version of the API to apply these settings to. This is the full protobuf
135
+ // package for the API, ending in the version element.
136
+ // Examples: "google.cloud.speech.v1" and "google.spanner.admin.database.v1".
137
+ string version = 1;
138
+
139
+ // Launch stage of this version of the API.
140
+ LaunchStage launch_stage = 2;
141
+
142
+ // When using transport=rest, the client request will encode enums as
143
+ // numbers rather than strings.
144
+ bool rest_numeric_enums = 3;
145
+
146
+ // Settings for legacy Java features, supported in the Service YAML.
147
+ JavaSettings java_settings = 21;
148
+
149
+ // Settings for C++ client libraries.
150
+ CppSettings cpp_settings = 22;
151
+
152
+ // Settings for PHP client libraries.
153
+ PhpSettings php_settings = 23;
154
+
155
+ // Settings for Python client libraries.
156
+ PythonSettings python_settings = 24;
157
+
158
+ // Settings for Node client libraries.
159
+ NodeSettings node_settings = 25;
160
+
161
+ // Settings for .NET client libraries.
162
+ DotnetSettings dotnet_settings = 26;
163
+
164
+ // Settings for Ruby client libraries.
165
+ RubySettings ruby_settings = 27;
166
+
167
+ // Settings for Go client libraries.
168
+ GoSettings go_settings = 28;
169
+ }
170
+
171
+ // This message configures the settings for publishing [Google Cloud Client
172
+ // libraries](https://cloud.google.com/apis/docs/cloud-client-libraries)
173
+ // generated from the service config.
174
+ message Publishing {
175
+ // A list of API method settings, e.g. the behavior for methods that use the
176
+ // long-running operation pattern.
177
+ repeated MethodSettings method_settings = 2;
178
+
179
+ // Link to a *public* URI where users can report issues. Example:
180
+ // https://issuetracker.google.com/issues/new?component=190865&template=1161103
181
+ string new_issue_uri = 101;
182
+
183
+ // Link to product home page. Example:
184
+ // https://cloud.google.com/asset-inventory/docs/overview
185
+ string documentation_uri = 102;
186
+
187
+ // Used as a tracking tag when collecting data about the APIs developer
188
+ // relations artifacts like docs, packages delivered to package managers,
189
+ // etc. Example: "speech".
190
+ string api_short_name = 103;
191
+
192
+ // GitHub label to apply to issues and pull requests opened for this API.
193
+ string github_label = 104;
194
+
195
+ // GitHub teams to be added to CODEOWNERS in the directory in GitHub
196
+ // containing source code for the client libraries for this API.
197
+ repeated string codeowner_github_teams = 105;
198
+
199
+ // A prefix used in sample code when demarking regions to be included in
200
+ // documentation.
201
+ string doc_tag_prefix = 106;
202
+
203
+ // For whom the client library is being published.
204
+ ClientLibraryOrganization organization = 107;
205
+
206
+ // Client library settings. If the same version string appears multiple
207
+ // times in this list, then the last one wins. Settings from earlier
208
+ // settings with the same version string are discarded.
209
+ repeated ClientLibrarySettings library_settings = 109;
210
+
211
+ // Optional link to proto reference documentation. Example:
212
+ // https://cloud.google.com/pubsub/lite/docs/reference/rpc
213
+ string proto_reference_documentation_uri = 110;
214
+
215
+ // Optional link to REST reference documentation. Example:
216
+ // https://cloud.google.com/pubsub/lite/docs/reference/rest
217
+ string rest_reference_documentation_uri = 111;
218
+ }
219
+
220
+ // Settings for Java client libraries.
221
+ message JavaSettings {
222
+ // The package name to use in Java. Clobbers the java_package option
223
+ // set in the protobuf. This should be used **only** by APIs
224
+ // who have already set the language_settings.java.package_name" field
225
+ // in gapic.yaml. API teams should use the protobuf java_package option
226
+ // where possible.
227
+ //
228
+ // Example of a YAML configuration::
229
+ //
230
+ // publishing:
231
+ // java_settings:
232
+ // library_package: com.google.cloud.pubsub.v1
233
+ string library_package = 1;
234
+
235
+ // Configure the Java class name to use instead of the service's for its
236
+ // corresponding generated GAPIC client. Keys are fully-qualified
237
+ // service names as they appear in the protobuf (including the full
238
+ // the language_settings.java.interface_names" field in gapic.yaml. API
239
+ // teams should otherwise use the service name as it appears in the
240
+ // protobuf.
241
+ //
242
+ // Example of a YAML configuration::
243
+ //
244
+ // publishing:
245
+ // java_settings:
246
+ // service_class_names:
247
+ // - google.pubsub.v1.Publisher: TopicAdmin
248
+ // - google.pubsub.v1.Subscriber: SubscriptionAdmin
249
+ map<string, string> service_class_names = 2;
250
+
251
+ // Some settings.
252
+ CommonLanguageSettings common = 3;
253
+ }
254
+
255
+ // Settings for C++ client libraries.
256
+ message CppSettings {
257
+ // Some settings.
258
+ CommonLanguageSettings common = 1;
259
+ }
260
+
261
+ // Settings for Php client libraries.
262
+ message PhpSettings {
263
+ // Some settings.
264
+ CommonLanguageSettings common = 1;
265
+ }
266
+
267
+ // Settings for Python client libraries.
268
+ message PythonSettings {
269
+ // Experimental features to be included during client library generation.
270
+ // These fields will be deprecated once the feature graduates and is enabled
271
+ // by default.
272
+ message ExperimentalFeatures {
273
+ // Enables generation of asynchronous REST clients if `rest` transport is
274
+ // enabled. By default, asynchronous REST clients will not be generated.
275
+ // This feature will be enabled by default 1 month after launching the
276
+ // feature in preview packages.
277
+ bool rest_async_io_enabled = 1;
278
+
279
+ // Enables generation of protobuf code using new types that are more
280
+ // Pythonic which are included in `protobuf>=5.29.x`. This feature will be
281
+ // enabled by default 1 month after launching the feature in preview
282
+ // packages.
283
+ bool protobuf_pythonic_types_enabled = 2;
284
+ }
285
+
286
+ // Some settings.
287
+ CommonLanguageSettings common = 1;
288
+
289
+ // Experimental features to be included during client library generation.
290
+ ExperimentalFeatures experimental_features = 2;
291
+ }
292
+
293
+ // Settings for Node client libraries.
294
+ message NodeSettings {
295
+ // Some settings.
296
+ CommonLanguageSettings common = 1;
297
+ }
298
+
299
+ // Settings for Dotnet client libraries.
300
+ message DotnetSettings {
301
+ // Some settings.
302
+ CommonLanguageSettings common = 1;
303
+
304
+ // Map from original service names to renamed versions.
305
+ // This is used when the default generated types
306
+ // would cause a naming conflict. (Neither name is
307
+ // fully-qualified.)
308
+ // Example: Subscriber to SubscriberServiceApi.
309
+ map<string, string> renamed_services = 2;
310
+
311
+ // Map from full resource types to the effective short name
312
+ // for the resource. This is used when otherwise resource
313
+ // named from different services would cause naming collisions.
314
+ // Example entry:
315
+ // "datalabeling.googleapis.com/Dataset": "DataLabelingDataset"
316
+ map<string, string> renamed_resources = 3;
317
+
318
+ // List of full resource types to ignore during generation.
319
+ // This is typically used for API-specific Location resources,
320
+ // which should be handled by the generator as if they were actually
321
+ // the common Location resources.
322
+ // Example entry: "documentai.googleapis.com/Location"
323
+ repeated string ignored_resources = 4;
324
+
325
+ // Namespaces which must be aliased in snippets due to
326
+ // a known (but non-generator-predictable) naming collision
327
+ repeated string forced_namespace_aliases = 5;
328
+
329
+ // Method signatures (in the form "service.method(signature)")
330
+ // which are provided separately, so shouldn't be generated.
331
+ // Snippets *calling* these methods are still generated, however.
332
+ repeated string handwritten_signatures = 6;
333
+ }
334
+
335
+ // Settings for Ruby client libraries.
336
+ message RubySettings {
337
+ // Some settings.
338
+ CommonLanguageSettings common = 1;
339
+ }
340
+
341
+ // Settings for Go client libraries.
342
+ message GoSettings {
343
+ // Some settings.
344
+ CommonLanguageSettings common = 1;
345
+ }
346
+
347
+ // Describes the generator configuration for a method.
348
+ message MethodSettings {
349
+ // Describes settings to use when generating API methods that use the
350
+ // long-running operation pattern.
351
+ // All default values below are from those used in the client library
352
+ // generators (e.g.
353
+ // [Java](https://github.com/googleapis/gapic-generator-java/blob/04c2faa191a9b5a10b92392fe8482279c4404803/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java)).
354
+ message LongRunning {
355
+ // Initial delay after which the first poll request will be made.
356
+ // Default value: 5 seconds.
357
+ google.protobuf.Duration initial_poll_delay = 1;
358
+
359
+ // Multiplier to gradually increase delay between subsequent polls until it
360
+ // reaches max_poll_delay.
361
+ // Default value: 1.5.
362
+ float poll_delay_multiplier = 2;
363
+
364
+ // Maximum time between two subsequent poll requests.
365
+ // Default value: 45 seconds.
366
+ google.protobuf.Duration max_poll_delay = 3;
367
+
368
+ // Total polling timeout.
369
+ // Default value: 5 minutes.
370
+ google.protobuf.Duration total_poll_timeout = 4;
371
+ }
372
+
373
+ // The fully qualified name of the method, for which the options below apply.
374
+ // This is used to find the method to apply the options.
375
+ //
376
+ // Example:
377
+ //
378
+ // publishing:
379
+ // method_settings:
380
+ // - selector: google.storage.control.v2.StorageControl.CreateFolder
381
+ // # method settings for CreateFolder...
382
+ string selector = 1;
383
+
384
+ // Describes settings to use for long-running operations when generating
385
+ // API methods for RPCs. Complements RPCs that use the annotations in
386
+ // google/longrunning/operations.proto.
387
+ //
388
+ // Example of a YAML configuration::
389
+ //
390
+ // publishing:
391
+ // method_settings:
392
+ // - selector: google.cloud.speech.v2.Speech.BatchRecognize
393
+ // long_running:
394
+ // initial_poll_delay: 60s # 1 minute
395
+ // poll_delay_multiplier: 1.5
396
+ // max_poll_delay: 360s # 6 minutes
397
+ // total_poll_timeout: 54000s # 90 minutes
398
+ LongRunning long_running = 2;
399
+
400
+ // List of top-level fields of the request message, that should be
401
+ // automatically populated by the client libraries based on their
402
+ // (google.api.field_info).format. Currently supported format: UUID4.
403
+ //
404
+ // Example of a YAML configuration:
405
+ //
406
+ // publishing:
407
+ // method_settings:
408
+ // - selector: google.example.v1.ExampleService.CreateExample
409
+ // auto_populated_fields:
410
+ // - request_id
411
+ repeated string auto_populated_fields = 3;
412
+ }
413
+
414
+ // The organization for which the client libraries are being published.
415
+ // Affects the url where generated docs are published, etc.
416
+ enum ClientLibraryOrganization {
417
+ // Not useful.
418
+ CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED = 0;
419
+
420
+ // Google Cloud Platform Org.
421
+ CLOUD = 1;
422
+
423
+ // Ads (Advertising) Org.
424
+ ADS = 2;
425
+
426
+ // Photos Org.
427
+ PHOTOS = 3;
428
+
429
+ // Street View Org.
430
+ STREET_VIEW = 4;
431
+
432
+ // Shopping Org.
433
+ SHOPPING = 5;
434
+
435
+ // Geo Org.
436
+ GEO = 6;
437
+
438
+ // Generative AI - https://developers.generativeai.google
439
+ GENERATIVE_AI = 7;
440
+ }
441
+
442
+ // To where should client libraries be published?
443
+ enum ClientLibraryDestination {
444
+ // Client libraries will neither be generated nor published to package
445
+ // managers.
446
+ CLIENT_LIBRARY_DESTINATION_UNSPECIFIED = 0;
447
+
448
+ // Generate the client library in a repo under github.com/googleapis,
449
+ // but don't publish it to package managers.
450
+ GITHUB = 10;
451
+
452
+ // Publish the library to package managers like nuget.org and npmjs.com.
453
+ PACKAGE_MANAGER = 20;
454
+ }
455
+
456
+ // This message is used to configure the generation of a subset of the RPCs in
457
+ // a service for client libraries.
458
+ message SelectiveGapicGeneration {
459
+ // An allowlist of the fully qualified names of RPCs that should be included
460
+ // on public client surfaces.
461
+ repeated string methods = 1;
462
+ }
.venv/lib/python3.11/site-packages/google/api/field_behavior.proto ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2024 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ syntax = "proto3";
16
+
17
+ package google.api;
18
+
19
+ import "google/protobuf/descriptor.proto";
20
+
21
+ option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
22
+ option java_multiple_files = true;
23
+ option java_outer_classname = "FieldBehaviorProto";
24
+ option java_package = "com.google.api";
25
+ option objc_class_prefix = "GAPI";
26
+
27
+ extend google.protobuf.FieldOptions {
28
+ // A designation of a specific field behavior (required, output only, etc.)
29
+ // in protobuf messages.
30
+ //
31
+ // Examples:
32
+ //
33
+ // string name = 1 [(google.api.field_behavior) = REQUIRED];
34
+ // State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
35
+ // google.protobuf.Duration ttl = 1
36
+ // [(google.api.field_behavior) = INPUT_ONLY];
37
+ // google.protobuf.Timestamp expire_time = 1
38
+ // [(google.api.field_behavior) = OUTPUT_ONLY,
39
+ // (google.api.field_behavior) = IMMUTABLE];
40
+ repeated google.api.FieldBehavior field_behavior = 1052 [packed = false];
41
+ }
42
+
43
+ // An indicator of the behavior of a given field (for example, that a field
44
+ // is required in requests, or given as output but ignored as input).
45
+ // This **does not** change the behavior in protocol buffers itself; it only
46
+ // denotes the behavior and may affect how API tooling handles the field.
47
+ //
48
+ // Note: This enum **may** receive new values in the future.
49
+ enum FieldBehavior {
50
+ // Conventional default for enums. Do not use this.
51
+ FIELD_BEHAVIOR_UNSPECIFIED = 0;
52
+
53
+ // Specifically denotes a field as optional.
54
+ // While all fields in protocol buffers are optional, this may be specified
55
+ // for emphasis if appropriate.
56
+ OPTIONAL = 1;
57
+
58
+ // Denotes a field as required.
59
+ // This indicates that the field **must** be provided as part of the request,
60
+ // and failure to do so will cause an error (usually `INVALID_ARGUMENT`).
61
+ REQUIRED = 2;
62
+
63
+ // Denotes a field as output only.
64
+ // This indicates that the field is provided in responses, but including the
65
+ // field in a request does nothing (the server *must* ignore it and
66
+ // *must not* throw an error as a result of the field's presence).
67
+ OUTPUT_ONLY = 3;
68
+
69
+ // Denotes a field as input only.
70
+ // This indicates that the field is provided in requests, and the
71
+ // corresponding field is not included in output.
72
+ INPUT_ONLY = 4;
73
+
74
+ // Denotes a field as immutable.
75
+ // This indicates that the field may be set once in a request to create a
76
+ // resource, but may not be changed thereafter.
77
+ IMMUTABLE = 5;
78
+
79
+ // Denotes that a (repeated) field is an unordered list.
80
+ // This indicates that the service may provide the elements of the list
81
+ // in any arbitrary order, rather than the order the user originally
82
+ // provided. Additionally, the list's order may or may not be stable.
83
+ UNORDERED_LIST = 6;
84
+
85
+ // Denotes that this field returns a non-empty default value if not set.
86
+ // This indicates that if the user provides the empty value in a request,
87
+ // a non-empty value will be returned. The user will not be aware of what
88
+ // non-empty value to expect.
89
+ NON_EMPTY_DEFAULT = 7;
90
+
91
+ // Denotes that the field in a resource (a message annotated with
92
+ // google.api.resource) is used in the resource name to uniquely identify the
93
+ // resource. For AIP-compliant APIs, this should only be applied to the
94
+ // `name` field on the resource.
95
+ //
96
+ // This behavior should not be applied to references to other resources within
97
+ // the message.
98
+ //
99
+ // The identifier field of resources often have different field behavior
100
+ // depending on the request it is embedded in (e.g. for Create methods name
101
+ // is optional and unused, while for Update methods it is required). Instead
102
+ // of method-specific annotations, only `IDENTIFIER` is required.
103
+ IDENTIFIER = 8;
104
+ }
.venv/lib/python3.11/site-packages/google/generativeai/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (2.39 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/__pycache__/client.cpython-311.pyc ADDED
Binary file (18.7 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/__pycache__/discuss.cpython-311.pyc ADDED
Binary file (25 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/__pycache__/protos.cpython-311.pyc ADDED
Binary file (2.35 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/__pycache__/utils.cpython-311.pyc ADDED
Binary file (922 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__init__.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2023 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """A collection of type definitions used throughout the library."""
16
+
17
+ from google.generativeai.types.citation_types import *
18
+ from google.generativeai.types.content_types import *
19
+ from google.generativeai.types.file_types import *
20
+ from google.generativeai.types.generation_types import *
21
+ from google.generativeai.types.helper_types import *
22
+ from google.generativeai.types.model_types import *
23
+ from google.generativeai.types.permission_types import *
24
+ from google.generativeai.types.safety_types import *
25
+
26
+
27
+ del model_types
28
+ del citation_types
29
+ del safety_types
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/citation_types.cpython-311.pyc ADDED
Binary file (1.49 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/file_types.cpython-311.pyc ADDED
Binary file (7.03 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/generation_types.cpython-311.pyc ADDED
Binary file (33.9 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/palm_safety_types.cpython-311.pyc ADDED
Binary file (12.9 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/permission_types.cpython-311.pyc ADDED
Binary file (19.9 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/__pycache__/text_types.cpython-311.pyc ADDED
Binary file (1.21 kB). View file
 
.venv/lib/python3.11/site-packages/google/generativeai/types/citation_types.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2023 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ from __future__ import annotations
16
+ from typing import List
17
+
18
+ from typing_extensions import TypedDict
19
+
20
+ from google.generativeai import protos
21
+ from google.generativeai import string_utils
22
+
23
+
24
+ __all__ = [
25
+ "CitationMetadataDict",
26
+ "CitationSourceDict",
27
+ ]
28
+
29
+
30
+ class CitationSourceDict(TypedDict):
31
+ start_index: int | None
32
+ end_index: int | None
33
+ uri: str | None
34
+ license: str | None
35
+
36
+ __doc__ = string_utils.strip_oneof(protos.CitationSource.__doc__)
37
+
38
+
39
+ class CitationMetadataDict(TypedDict):
40
+ citation_sources: List[CitationSourceDict | None]
41
+
42
+ __doc__ = string_utils.strip_oneof(protos.CitationMetadata.__doc__)
.venv/lib/python3.11/site-packages/google/generativeai/types/helper_types.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2023 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from __future__ import annotations
17
+
18
+ import google.api_core.timeout
19
+ import google.api_core.retry
20
+
21
+ import collections
22
+ import dataclasses
23
+
24
+ from typing import Union
25
+ from typing_extensions import TypedDict
26
+
27
+ __all__ = ["RequestOptions", "RequestOptionsType"]
28
+
29
+
30
+ class RequestOptionsDict(TypedDict, total=False):
31
+ retry: google.api_core.retry.Retry
32
+ timeout: Union[int, float, google.api_core.timeout.TimeToDeadlineTimeout]
33
+
34
+
35
+ @dataclasses.dataclass(init=False)
36
+ class RequestOptions(collections.abc.Mapping):
37
+ """Request options
38
+
39
+ >>> import google.generativeai as genai
40
+ >>> from google.generativeai.types import RequestOptions
41
+ >>> from google.api_core import retry
42
+ >>>
43
+ >>> model = genai.GenerativeModel()
44
+ >>> response = model.generate_content('Hello',
45
+ ... request_options=RequestOptions(
46
+ ... retry=retry.Retry(initial=10, multiplier=2, maximum=60, timeout=300)))
47
+ >>> response = model.generate_content('Hello',
48
+ ... request_options=RequestOptions(timeout=600)))
49
+
50
+ Args:
51
+ retry: Refer to [retry docs](https://googleapis.dev/python/google-api-core/latest/retry.html) for details.
52
+ timeout: In seconds (or provide a [TimeToDeadlineTimeout](https://googleapis.dev/python/google-api-core/latest/timeout.html) object).
53
+ """
54
+
55
+ retry: google.api_core.retry.Retry | None
56
+ timeout: int | float | google.api_core.timeout.TimeToDeadlineTimeout | None
57
+
58
+ def __init__(
59
+ self,
60
+ *,
61
+ retry: google.api_core.retry.Retry | None = None,
62
+ timeout: int | float | google.api_core.timeout.TimeToDeadlineTimeout | None = None,
63
+ ):
64
+ self.retry = retry
65
+ self.timeout = timeout
66
+
67
+ # Inherit from Mapping for **unpacking
68
+ def __getitem__(self, item):
69
+ if item == "retry":
70
+ return self.retry
71
+ elif item == "timeout":
72
+ return self.timeout
73
+ else:
74
+ raise KeyError(
75
+ f"Invalid key: 'RequestOptions' does not contain a key named '{item}'. "
76
+ "Please use a valid key."
77
+ )
78
+
79
+ def __iter__(self):
80
+ yield "retry"
81
+ yield "timeout"
82
+
83
+ def __len__(self):
84
+ return 2
85
+
86
+
87
+ RequestOptionsType = Union[RequestOptions, RequestOptionsDict]
.venv/lib/python3.11/site-packages/google/generativeai/types/retriever_types.py ADDED
@@ -0,0 +1,1698 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2023 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ from __future__ import annotations
16
+
17
+ import datetime
18
+ import re
19
+ import abc
20
+ import dataclasses
21
+ from typing import Any, AsyncIterable, Optional, Union, Iterable, Mapping
22
+ from typing_extensions import deprecated # type: ignore
23
+
24
+ import google.ai.generativelanguage as glm
25
+ from google.generativeai import protos
26
+
27
+ from google.protobuf import field_mask_pb2
28
+ from google.generativeai.client import get_default_retriever_client
29
+ from google.generativeai.client import get_default_retriever_async_client
30
+ from google.generativeai import string_utils
31
+ from google.generativeai.types import helper_types
32
+
33
+ from google.generativeai.types import permission_types
34
+ from google.generativeai.types.model_types import idecode_time
35
+ from google.generativeai.utils import flatten_update_paths
36
+
37
+ _VALID_NAME = r"[a-z0-9]([a-z0-9-]{0,38}[a-z0-9])$"
38
+ NAME_ERROR_MSG = """The `name` must consist of alphanumeric characters (or -) and be 40 or fewer characters; or be empty. The name you entered:
39
+ len(name)== {length}
40
+ name={name}
41
+ """
42
+
43
+
44
+ def valid_name(name):
45
+ return re.match(_VALID_NAME, name) and len(name) < 40
46
+
47
+
48
+ Operator = protos.Condition.Operator
49
+ State = protos.Chunk.State
50
+
51
+ OperatorOptions = Union[str, int, Operator]
52
+ StateOptions = Union[str, int, State]
53
+
54
+ ChunkOptions = Union[
55
+ protos.Chunk,
56
+ str,
57
+ tuple[str, str],
58
+ tuple[str, str, Any],
59
+ Mapping[str, Any],
60
+ ] # fmt: no
61
+
62
+ BatchCreateChunkOptions = Union[
63
+ protos.BatchCreateChunksRequest,
64
+ Mapping[str, str],
65
+ Mapping[str, tuple[str, str]],
66
+ Iterable[ChunkOptions],
67
+ ] # fmt: no
68
+
69
+ UpdateChunkOptions = Union[protos.UpdateChunkRequest, Mapping[str, Any], tuple[str, Any]]
70
+
71
+ BatchUpdateChunksOptions = Union[protos.BatchUpdateChunksRequest, Iterable[UpdateChunkOptions]]
72
+
73
+ BatchDeleteChunkOptions = Union[list[protos.DeleteChunkRequest], Iterable[str]]
74
+
75
+ _OPERATOR: dict[OperatorOptions, Operator] = {
76
+ Operator.OPERATOR_UNSPECIFIED: Operator.OPERATOR_UNSPECIFIED,
77
+ 0: Operator.OPERATOR_UNSPECIFIED,
78
+ "operator_unspecified": Operator.OPERATOR_UNSPECIFIED,
79
+ "unspecified": Operator.OPERATOR_UNSPECIFIED,
80
+ Operator.LESS: Operator.LESS,
81
+ 1: Operator.LESS,
82
+ "operator_less": Operator.LESS,
83
+ "less": Operator.LESS,
84
+ "<": Operator.LESS,
85
+ Operator.LESS_EQUAL: Operator.LESS_EQUAL,
86
+ 2: Operator.LESS_EQUAL,
87
+ "operator_less_equal": Operator.LESS_EQUAL,
88
+ "less_equal": Operator.LESS_EQUAL,
89
+ "<=": Operator.LESS_EQUAL,
90
+ Operator.EQUAL: Operator.EQUAL,
91
+ 3: Operator.EQUAL,
92
+ "operator_equal": Operator.EQUAL,
93
+ "equal": Operator.EQUAL,
94
+ "==": Operator.EQUAL,
95
+ Operator.GREATER_EQUAL: Operator.GREATER_EQUAL,
96
+ 4: Operator.GREATER_EQUAL,
97
+ "operator_greater_equal": Operator.GREATER_EQUAL,
98
+ "greater_equal": Operator.GREATER_EQUAL,
99
+ Operator.EQUAL: Operator.EQUAL,
100
+ 5: Operator.EQUAL,
101
+ "operator_equal": Operator.EQUAL,
102
+ "equal": Operator.EQUAL,
103
+ "==": Operator.EQUAL,
104
+ Operator.NOT_EQUAL: Operator.NOT_EQUAL,
105
+ 6: Operator.NOT_EQUAL,
106
+ "operator_not_equal": Operator.NOT_EQUAL,
107
+ "not_equal": Operator.NOT_EQUAL,
108
+ "!=": Operator.NOT_EQUAL,
109
+ Operator.INCLUDES: Operator.INCLUDES,
110
+ 7: Operator.INCLUDES,
111
+ "operator_includes": Operator.INCLUDES,
112
+ "includes": Operator.INCLUDES,
113
+ Operator.EXCLUDES: Operator.EXCLUDES,
114
+ 8: Operator.EXCLUDES,
115
+ "operator_excludes": Operator.EXCLUDES,
116
+ "excludes": Operator.EXCLUDES,
117
+ "not in": Operator.EXCLUDES,
118
+ }
119
+
120
+ _STATE: dict[StateOptions, State] = {
121
+ State.STATE_UNSPECIFIED: State.STATE_UNSPECIFIED,
122
+ 0: State.STATE_UNSPECIFIED,
123
+ "state_unspecifed": State.STATE_UNSPECIFIED,
124
+ "unspecified": State.STATE_UNSPECIFIED,
125
+ State.STATE_PENDING_PROCESSING: State.STATE_PENDING_PROCESSING,
126
+ 1: State.STATE_PENDING_PROCESSING,
127
+ "pending_processing": State.STATE_PENDING_PROCESSING,
128
+ "pending": State.STATE_PENDING_PROCESSING,
129
+ State.STATE_ACTIVE: State.STATE_ACTIVE,
130
+ 2: State.STATE_ACTIVE,
131
+ "state_active": State.STATE_ACTIVE,
132
+ "active": State.STATE_ACTIVE,
133
+ State.STATE_FAILED: State.STATE_FAILED,
134
+ 10: State.STATE_FAILED,
135
+ "state_failed": State.STATE_FAILED,
136
+ "failed": State.STATE_FAILED,
137
+ }
138
+
139
+
140
+ def to_operator(x: OperatorOptions) -> Operator:
141
+ if isinstance(x, str):
142
+ x = x.lower()
143
+ return _OPERATOR[x]
144
+
145
+
146
+ def to_state(x: StateOptions) -> State:
147
+ if isinstance(x, str):
148
+ x = x.lower()
149
+ return _STATE[x]
150
+
151
+
152
+ @string_utils.prettyprint
153
+ @dataclasses.dataclass
154
+ class MetadataFilter:
155
+ key: str
156
+ conditions: Iterable[Condition]
157
+
158
+ def _to_proto(self):
159
+ kwargs = {}
160
+ conditions = []
161
+ for c in self.conditions:
162
+ if isinstance(c.value, str):
163
+ kwargs["string_value"] = c.value
164
+ elif isinstance(c.value, (int, float)):
165
+ kwargs["numeric_value"] = float(c.value)
166
+ else:
167
+ raise ValueError(
168
+ f"Invalid value type: The value for the condition must be either a string or an integer/float. Received: '{c.value}' of type {type(c.value).__name__}."
169
+ )
170
+ kwargs["operation"] = c.operation
171
+
172
+ condition = protos.Condition(**kwargs)
173
+ conditions.append(condition)
174
+
175
+ return protos.MetadataFilter(key=self.key, conditions=conditions)
176
+
177
+
178
+ @string_utils.prettyprint
179
+ @dataclasses.dataclass
180
+ class Condition:
181
+ value: str | float
182
+ operation: Operator
183
+
184
+
185
+ @string_utils.prettyprint
186
+ @dataclasses.dataclass
187
+ class CustomMetadata:
188
+ key: str
189
+ value: str | Iterable[str] | float
190
+
191
+ def _to_proto(self):
192
+ kwargs = {}
193
+ if isinstance(self.value, str):
194
+ kwargs["string_value"] = self.value
195
+ elif isinstance(self.value, Iterable):
196
+ if isinstance(self.value, Mapping):
197
+ # If already converted to a protos.StringList, get the values
198
+ kwargs["string_list_value"] = self.value
199
+ else:
200
+ kwargs["string_list_value"] = protos.StringList(values=self.value)
201
+ elif isinstance(self.value, (int, float)):
202
+ kwargs["numeric_value"] = float(self.value)
203
+ else:
204
+ raise ValueError(
205
+ f"Invalid value type: The value for a custom_metadata specification must be either a list of string values, a string, or an integer/float. Received: '{self.value}' of type {type(self.value).__name__}."
206
+ )
207
+ return protos.CustomMetadata(key=self.key, **kwargs)
208
+
209
+ @classmethod
210
+ def _from_dict(cls, cm):
211
+ key = cm["key"]
212
+ value = (
213
+ cm.get("value", None)
214
+ or cm.get("string_value", None)
215
+ or cm.get("string_list_value", None)
216
+ or cm.get("numeric_value", None)
217
+ )
218
+ return cls(key=key, value=value)
219
+
220
+ def _to_dict(self):
221
+ proto = self._to_proto()
222
+ return type(proto).to_dict(proto)
223
+
224
+
225
+ CustomMetadataOptions = Union[CustomMetadata, protos.CustomMetadata, dict]
226
+
227
+
228
+ def make_custom_metadata(cm: CustomMetadataOptions) -> CustomMetadata:
229
+ if isinstance(cm, CustomMetadata):
230
+ return cm
231
+
232
+ if isinstance(cm, protos.CustomMetadata):
233
+ cm = type(cm).to_dict(cm)
234
+
235
+ if isinstance(cm, dict):
236
+ return CustomMetadata._from_dict(cm)
237
+ else:
238
+ raise ValueError( # nofmt
239
+ f"Invalid input: Could not create a 'CustomMetadata' from the provided input. Received type: '{type(cm).__name__}', value: '{cm}'."
240
+ )
241
+
242
+
243
+ @string_utils.prettyprint
244
+ @dataclasses.dataclass
245
+ class ChunkData:
246
+ string_value: str
247
+
248
+
249
+ @string_utils.prettyprint
250
+ @dataclasses.dataclass()
251
+ class Corpus:
252
+ """
253
+ A `Corpus` is a collection of `Documents`.
254
+ """
255
+
256
+ name: str
257
+ display_name: str
258
+ create_time: datetime.datetime
259
+ update_time: datetime.datetime
260
+
261
+ @property
262
+ def permissions(self) -> permission_types.Permissions:
263
+ return permission_types.Permissions(self)
264
+
265
+ def create_document(
266
+ self,
267
+ name: str | None = None,
268
+ display_name: str | None = None,
269
+ custom_metadata: Iterable[CustomMetadata] | None = None,
270
+ client: glm.RetrieverServiceClient | None = None,
271
+ request_options: helper_types.RequestOptionsType | None = None,
272
+ ) -> Document:
273
+ """
274
+ Request to create a `Document`.
275
+
276
+ Args:
277
+ name: The `Document` resource name. The ID (name excluding the "corpora/*/documents/" prefix) can contain up to 40 characters
278
+ that are lowercase alphanumeric or dashes (-). The ID cannot start or end with a dash.
279
+ display_name: The human-readable display name for the `Document`.
280
+ custom_metadata: User provided custom metadata stored as key-value pairs used for querying.
281
+ request_options: Options for the request.
282
+
283
+ Return:
284
+ Document object with specified name or display name.
285
+
286
+ Raises:
287
+ ValueError: When the name is not specified or formatted incorrectly.
288
+ """
289
+ if request_options is None:
290
+ request_options = {}
291
+
292
+ if client is None:
293
+ client = get_default_retriever_client()
294
+
295
+ # Handle the custom_metadata parameter
296
+ c_data = []
297
+ if custom_metadata:
298
+ for cm in custom_metadata:
299
+ c_data.append(cm._to_proto())
300
+
301
+ if name is None:
302
+ document = protos.Document(display_name=display_name, custom_metadata=c_data)
303
+ elif valid_name(name):
304
+ document = protos.Document(
305
+ name=f"{self.name}/documents/{name}",
306
+ display_name=display_name,
307
+ custom_metadata=c_data,
308
+ )
309
+ else:
310
+ raise ValueError(NAME_ERROR_MSG.format(length=len(name), name=name))
311
+
312
+ request = protos.CreateDocumentRequest(parent=self.name, document=document)
313
+ response = client.create_document(request, **request_options)
314
+ return decode_document(response)
315
+
316
+ async def create_document_async(
317
+ self,
318
+ name: str | None = None,
319
+ display_name: str | None = None,
320
+ custom_metadata: Iterable[CustomMetadata] | None = None,
321
+ client: glm.RetrieverServiceAsyncClient | None = None,
322
+ request_options: helper_types.RequestOptionsType | None = None,
323
+ ) -> Document:
324
+ """This is the async version of `Corpus.create_document`."""
325
+ if request_options is None:
326
+ request_options = {}
327
+
328
+ if client is None:
329
+ client = get_default_retriever_async_client()
330
+
331
+ # Handle the custom_metadata parameter
332
+ c_data = []
333
+ if custom_metadata:
334
+ for cm in custom_metadata:
335
+ c_data.append(cm._to_proto())
336
+
337
+ if name is None:
338
+ document = protos.Document(display_name=display_name, custom_metadata=c_data)
339
+ elif valid_name(name):
340
+ document = protos.Document(
341
+ name=f"{self.name}/documents/{name}",
342
+ display_name=display_name,
343
+ custom_metadata=c_data,
344
+ )
345
+ else:
346
+ raise ValueError(NAME_ERROR_MSG.format(length=len(name), name=name))
347
+
348
+ request = protos.CreateDocumentRequest(parent=self.name, document=document)
349
+ response = await client.create_document(request, **request_options)
350
+ return decode_document(response)
351
+
352
+ def get_document(
353
+ self,
354
+ name: str,
355
+ client: glm.RetrieverServiceClient | None = None,
356
+ request_options: helper_types.RequestOptionsType | None = None,
357
+ ) -> Document:
358
+ """
359
+ Get information about a specific `Document`.
360
+
361
+ Args:
362
+ name: The `Document` name.
363
+ request_options: Options for the request.
364
+
365
+ Return:
366
+ `Document` of interest.
367
+ """
368
+ if request_options is None:
369
+ request_options = {}
370
+
371
+ if client is None:
372
+ client = get_default_retriever_client()
373
+
374
+ if "/" not in name:
375
+ name = f"{self.name}/documents/{name}"
376
+
377
+ request = protos.GetDocumentRequest(name=name)
378
+ response = client.get_document(request, **request_options)
379
+ return decode_document(response)
380
+
381
+ async def get_document_async(
382
+ self,
383
+ name: str,
384
+ client: glm.RetrieverServiceAsyncClient | None = None,
385
+ request_options: helper_types.RequestOptionsType | None = None,
386
+ ) -> Document:
387
+ """This is the async version of `Corpus.get_document`."""
388
+ if request_options is None:
389
+ request_options = {}
390
+
391
+ if client is None:
392
+ client = get_default_retriever_async_client()
393
+
394
+ if "/" not in name:
395
+ name = f"{self.name}/documents/{name}"
396
+
397
+ request = protos.GetDocumentRequest(name=name)
398
+ response = await client.get_document(request, **request_options)
399
+ return decode_document(response)
400
+
401
+ def _apply_update(self, path, value):
402
+ parts = path.split(".")
403
+ for part in parts[:-1]:
404
+ self = getattr(self, part)
405
+ setattr(self, parts[-1], value)
406
+
407
+ def update(
408
+ self,
409
+ updates: dict[str, Any],
410
+ client: glm.RetrieverServiceClient | None = None,
411
+ request_options: helper_types.RequestOptionsType | None = None,
412
+ ):
413
+ """
414
+ Update a list of fields for a specified `Corpus`.
415
+
416
+ Args:
417
+ updates: List of fields to update in a `Corpus`.
418
+ request_options: Options for the request.
419
+
420
+ Return:
421
+ Updated version of the `Corpus` object.
422
+ """
423
+ if request_options is None:
424
+ request_options = {}
425
+
426
+ if client is None:
427
+ client = get_default_retriever_client()
428
+
429
+ updates = flatten_update_paths(updates)
430
+ # At this time, only `display_name` can be updated
431
+ for item in updates:
432
+ if item != "display_name":
433
+ raise ValueError(
434
+ "Invalid operation: Currently, only the 'display_name' attribute can be updated for a 'Corpus'."
435
+ )
436
+ field_mask = field_mask_pb2.FieldMask()
437
+
438
+ for path in updates.keys():
439
+ field_mask.paths.append(path)
440
+ for path, value in updates.items():
441
+ self._apply_update(path, value)
442
+
443
+ request = protos.UpdateCorpusRequest(corpus=self.to_dict(), update_mask=field_mask)
444
+ client.update_corpus(request, **request_options)
445
+ return self
446
+
447
+ async def update_async(
448
+ self,
449
+ updates: dict[str, Any],
450
+ client: glm.RetrieverServiceAsyncClient | None = None,
451
+ request_options: helper_types.RequestOptionsType | None = None,
452
+ ):
453
+ """This is the async version of `Corpus.update`."""
454
+ if request_options is None:
455
+ request_options = {}
456
+
457
+ if client is None:
458
+ client = get_default_retriever_async_client()
459
+
460
+ updates = flatten_update_paths(updates)
461
+ # At this time, only `display_name` can be updated
462
+ for item in updates:
463
+ if item != "display_name":
464
+ raise ValueError(
465
+ "Invalid operation: Currently, only the 'display_name' attribute can be updated for a 'Corpus'."
466
+ )
467
+ field_mask = field_mask_pb2.FieldMask()
468
+
469
+ for path in updates.keys():
470
+ field_mask.paths.append(path)
471
+ for path, value in updates.items():
472
+ self._apply_update(path, value)
473
+
474
+ request = protos.UpdateCorpusRequest(corpus=self.to_dict(), update_mask=field_mask)
475
+ await client.update_corpus(request, **request_options)
476
+ return self
477
+
478
+ def query(
479
+ self,
480
+ query: str,
481
+ metadata_filters: Iterable[MetadataFilter] | None = None,
482
+ results_count: int | None = None,
483
+ client: glm.RetrieverServiceClient | None = None,
484
+ request_options: helper_types.RequestOptionsType | None = None,
485
+ ) -> Iterable[RelevantChunk]:
486
+ """
487
+ Query a corpus for information.
488
+
489
+ Args:
490
+ query: Query string to perform semantic search.
491
+ metadata_filters: Filter for `Chunk` metadata.
492
+ results_count: The maximum number of `Chunk`s to return; must be less than 100.
493
+ request_options: Options for the request.
494
+
495
+ Returns:
496
+ List of relevant chunks.
497
+ """
498
+ if request_options is None:
499
+ request_options = {}
500
+
501
+ if client is None:
502
+ client = get_default_retriever_client()
503
+
504
+ if results_count:
505
+ if results_count > 100:
506
+ raise ValueError(
507
+ "Invalid operation: The number of results returned must be between 1 and 100."
508
+ )
509
+
510
+ m_f_ = []
511
+ if metadata_filters:
512
+ for mf in metadata_filters:
513
+ m_f_.append(mf._to_proto())
514
+
515
+ request = protos.QueryCorpusRequest(
516
+ name=self.name,
517
+ query=query,
518
+ metadata_filters=m_f_,
519
+ results_count=results_count,
520
+ )
521
+ response = client.query_corpus(request, **request_options)
522
+ response = type(response).to_dict(response)
523
+
524
+ # Create a RelevantChunk object for each chunk listed in response['relevant_chunks']
525
+ relevant_chunks = []
526
+ for c in response["relevant_chunks"]:
527
+ rc = RelevantChunk(
528
+ chunk_relevance_score=c["chunk_relevance_score"], chunk=Chunk(**c["chunk"])
529
+ )
530
+ relevant_chunks.append(rc)
531
+
532
+ return relevant_chunks
533
+
534
+ async def query_async(
535
+ self,
536
+ query: str,
537
+ metadata_filters: Iterable[MetadataFilter] | None = None,
538
+ results_count: int | None = None,
539
+ client: glm.RetrieverServiceAsyncClient | None = None,
540
+ request_options: helper_types.RequestOptionsType | None = None,
541
+ ) -> Iterable[RelevantChunk]:
542
+ """This is the async version of `Corpus.query`."""
543
+ if request_options is None:
544
+ request_options = {}
545
+
546
+ if client is None:
547
+ client = get_default_retriever_async_client()
548
+
549
+ if results_count:
550
+ if results_count > 100:
551
+ raise ValueError(
552
+ "Invalid operation: The number of results returned must be between 1 and 100."
553
+ )
554
+
555
+ m_f_ = []
556
+ if metadata_filters:
557
+ for mf in metadata_filters:
558
+ m_f_.append(mf._to_proto())
559
+
560
+ request = protos.QueryCorpusRequest(
561
+ name=self.name,
562
+ query=query,
563
+ metadata_filters=m_f_,
564
+ results_count=results_count,
565
+ )
566
+ response = await client.query_corpus(request, **request_options)
567
+ response = type(response).to_dict(response)
568
+
569
+ # Create a RelevantChunk object for each chunk listed in response['relevant_chunks']
570
+ relevant_chunks = []
571
+ for c in response["relevant_chunks"]:
572
+ rc = RelevantChunk(
573
+ chunk_relevance_score=c["chunk_relevance_score"], chunk=Chunk(**c["chunk"])
574
+ )
575
+ relevant_chunks.append(rc)
576
+
577
+ return relevant_chunks
578
+
579
+ def delete_document(
580
+ self,
581
+ name: str,
582
+ force: bool = False,
583
+ client: glm.RetrieverServiceClient | None = None,
584
+ request_options: helper_types.RequestOptionsType | None = None,
585
+ ):
586
+ """
587
+ Delete a document in the corpus.
588
+
589
+ Args:
590
+ name: The `Document` name.
591
+ force: If set to true, any `Chunk`s and objects related to this `Document` will also be deleted.
592
+ request_options: Options for the request.
593
+ """
594
+ if request_options is None:
595
+ request_options = {}
596
+
597
+ if client is None:
598
+ client = get_default_retriever_client()
599
+
600
+ if "/" not in name:
601
+ name = f"{self.name}/documents/{name}"
602
+
603
+ request = protos.DeleteDocumentRequest(name=name, force=bool(force))
604
+ client.delete_document(request, **request_options)
605
+
606
+ async def delete_document_async(
607
+ self,
608
+ name: str,
609
+ force: bool = False,
610
+ client: glm.RetrieverServiceAsyncClient | None = None,
611
+ request_options: helper_types.RequestOptionsType | None = None,
612
+ ):
613
+ """This is the async version of `Corpus.delete_document`."""
614
+ if request_options is None:
615
+ request_options = {}
616
+
617
+ if client is None:
618
+ client = get_default_retriever_async_client()
619
+
620
+ if "/" not in name:
621
+ name = f"{self.name}/documents/{name}"
622
+
623
+ request = protos.DeleteDocumentRequest(name=name, force=bool(force))
624
+ await client.delete_document(request, **request_options)
625
+
626
+ def list_documents(
627
+ self,
628
+ page_size: int | None = None,
629
+ client: glm.RetrieverServiceClient | None = None,
630
+ request_options: helper_types.RequestOptionsType | None = None,
631
+ ) -> Iterable[Document]:
632
+ """
633
+ List documents in corpus.
634
+
635
+ Args:
636
+ name: The name of the `Corpus` containing `Document`s.
637
+ page_size: The maximum number of `Document`s to return (per page). The service may return fewer `Document`s.
638
+ request_options: Options for the request.
639
+
640
+ Return:
641
+ Paginated list of `Document`s.
642
+ """
643
+ if request_options is None:
644
+ request_options = {}
645
+
646
+ if client is None:
647
+ client = get_default_retriever_client()
648
+
649
+ request = protos.ListDocumentsRequest(
650
+ parent=self.name,
651
+ page_size=page_size,
652
+ )
653
+ for doc in client.list_documents(request, **request_options):
654
+ yield decode_document(doc)
655
+
656
+ async def list_documents_async(
657
+ self,
658
+ page_size: int | None = None,
659
+ client: glm.RetrieverServiceAsyncClient | None = None,
660
+ request_options: helper_types.RequestOptionsType | None = None,
661
+ ) -> AsyncIterable[Document]:
662
+ """This is the async version of `Corpus.list_documents`."""
663
+ if request_options is None:
664
+ request_options = {}
665
+
666
+ if client is None:
667
+ client = get_default_retriever_async_client()
668
+
669
+ request = protos.ListDocumentsRequest(
670
+ parent=self.name,
671
+ page_size=page_size,
672
+ )
673
+ async for doc in await client.list_documents(request, **request_options):
674
+ yield decode_document(doc)
675
+
676
+ # PERMISSIONS STUBS: ..deprecated:: >0.5.2
677
+ @deprecated(
678
+ "`Corpus.create_permission` is deprecated and will be removed in a future release. \
679
+ Corpus permissions are now managed using the `permissions` property. Use `Corpus.permissions.create` instead."
680
+ )
681
+ def create_permission(
682
+ self,
683
+ role: permission_types.RoleOptions,
684
+ grantee_type: Optional[permission_types.GranteeTypeOptions] = None,
685
+ email_address: Optional[str] = None,
686
+ client: glm.PermissionServiceClient | None = None,
687
+ ) -> permission_types.Permission:
688
+ return self.permissions.create(
689
+ role=role, grantee_type=grantee_type, email_address=email_address, client=client
690
+ )
691
+
692
+ @deprecated(
693
+ "`Corpus.create_permission_async` is deprecated and will be removed in a future release. \
694
+ Corpus permissions are now managed using the `permissions` property. Use `Corpus.permissions.create_async` instead."
695
+ )
696
+ async def create_permission_async(
697
+ self,
698
+ role: permission_types.RoleOptions,
699
+ grantee_type: Optional[permission_types.GranteeTypeOptions] = None,
700
+ email_address: Optional[str] = None,
701
+ client: glm.PermissionServiceAsyncClient | None = None,
702
+ ) -> permission_types.Permission:
703
+ return await self.permissions.create_async(
704
+ role=role, grantee_type=grantee_type, email_address=email_address, client=client
705
+ )
706
+
707
+ @deprecated(
708
+ "`Corpus.list_permission` is deprecated and will be removed in a future release. \
709
+ Corpus permissions are now managed using the `permissions` property. Use `Corpus.permissions.list` instead."
710
+ )
711
+ def list_permissions(
712
+ self,
713
+ page_size: Optional[int] = None,
714
+ client: glm.PermissionServiceClient | None = None,
715
+ ) -> Iterable[permission_types.Permission]:
716
+ return self.permissions.list(page_size=page_size, client=client)
717
+
718
+ @deprecated(
719
+ "`Corpus.list_permission_async` is deprecated and will be removed in a future release. \
720
+ Corpus permissions are now managed using the `permissions` property. Use `Corpus.permissions.list_async` instead."
721
+ )
722
+ async def list_permissions_async(
723
+ self,
724
+ page_size: Optional[int] = None,
725
+ client: glm.PermissionServiceAsyncClient | None = None,
726
+ ) -> AsyncIterable[permission_types.Permission]:
727
+ return self.permissions.list_async(page_size=page_size, client=client)
728
+
729
+ # PERMISSIONS STUBS END
730
+
731
+ def to_dict(self) -> dict[str, Any]:
732
+ result = {"name": self.name, "display_name": self.display_name}
733
+ return result
734
+
735
+
736
+ def decode_document(document):
737
+ document = type(document).to_dict(document)
738
+ idecode_time(document, "create_time")
739
+ idecode_time(document, "update_time")
740
+ return Document(**document)
741
+
742
+
743
+ @string_utils.prettyprint
744
+ @dataclasses.dataclass()
745
+ class Document(abc.ABC):
746
+ """
747
+ A `Document` is a collection of `Chunk`s.
748
+ """
749
+
750
+ name: str
751
+ display_name: str
752
+ custom_metadata: list[CustomMetadata]
753
+ create_time: datetime.datetime
754
+ update_time: datetime.datetime
755
+
756
+ def create_chunk(
757
+ self,
758
+ data: str | ChunkData,
759
+ name: str | None = None,
760
+ custom_metadata: Iterable[CustomMetadata] | None = None,
761
+ client: glm.RetrieverServiceClient | None = None,
762
+ request_options: helper_types.RequestOptionsType | None = None,
763
+ ) -> Chunk:
764
+ """
765
+ Create a `Chunk` object which has textual data.
766
+
767
+ Args:
768
+ data: The content for the `Chunk`, such as the text string.
769
+ name: The `Chunk` resource name. The ID (name excluding the "corpora/*/documents/*/chunks/" prefix) can contain up to 40 characters that are lowercase alphanumeric or dashes (-).
770
+ custom_metadata: User provided custom metadata stored as key-value pairs.
771
+ state: States for the lifecycle of a `Chunk`.
772
+ request_options: Options for the request.
773
+
774
+ Return:
775
+ `Chunk` object with specified data.
776
+
777
+ Raises:
778
+ ValueError when chunk name not specified correctly.
779
+ """
780
+ if request_options is None:
781
+ request_options = {}
782
+
783
+ if client is None:
784
+ client = get_default_retriever_client()
785
+
786
+ # Handle the custom_metadata parameter
787
+ c_data = []
788
+ if custom_metadata:
789
+ for cm in custom_metadata:
790
+ c_data.append(cm._to_proto())
791
+
792
+ if name is not None:
793
+ if valid_name(name):
794
+ chunk_name = f"{self.name}/chunks/{name}"
795
+ else:
796
+ raise ValueError(NAME_ERROR_MSG.format(length=len(name), name=name))
797
+ else:
798
+ chunk_name = name
799
+
800
+ if isinstance(data, str):
801
+ chunk = protos.Chunk(
802
+ name=chunk_name, data={"string_value": data}, custom_metadata=c_data
803
+ )
804
+ else:
805
+ chunk = protos.Chunk(
806
+ name=chunk_name,
807
+ data={"string_value": data.string_value},
808
+ custom_metadata=c_data,
809
+ )
810
+
811
+ request = protos.CreateChunkRequest(parent=self.name, chunk=chunk)
812
+ response = client.create_chunk(request, **request_options)
813
+ return decode_chunk(response)
814
+
815
+ async def create_chunk_async(
816
+ self,
817
+ data: str | ChunkData,
818
+ name: str | None = None,
819
+ custom_metadata: Iterable[CustomMetadata] | None = None,
820
+ client: glm.RetrieverServiceAsyncClient | None = None,
821
+ request_options: helper_types.RequestOptionsType | None = None,
822
+ ) -> Chunk:
823
+ """This is the async version of `Document.create_chunk`."""
824
+ if request_options is None:
825
+ request_options = {}
826
+
827
+ if client is None:
828
+ client = get_default_retriever_async_client()
829
+
830
+ # Handle the custom_metadata parameter
831
+ c_data = []
832
+ if custom_metadata:
833
+ for cm in custom_metadata:
834
+ c_data.append(cm._to_proto())
835
+
836
+ if name is not None:
837
+ if valid_name(name):
838
+ chunk_name = f"{self.name}/chunks/{name}"
839
+ else:
840
+ raise ValueError(NAME_ERROR_MSG.format(length=len(name), name=name))
841
+ else:
842
+ chunk_name = name
843
+
844
+ if isinstance(data, str):
845
+ chunk = protos.Chunk(
846
+ name=chunk_name, data={"string_value": data}, custom_metadata=c_data
847
+ )
848
+ else:
849
+ chunk = protos.Chunk(
850
+ name=chunk_name,
851
+ data={"string_value": data.string_value},
852
+ custom_metadata=c_data,
853
+ )
854
+
855
+ request = protos.CreateChunkRequest(parent=self.name, chunk=chunk)
856
+ response = await client.create_chunk(request, **request_options)
857
+ return decode_chunk(response)
858
+
859
+ def _make_chunk(self, chunk: ChunkOptions) -> protos.Chunk:
860
+ # del self
861
+ if isinstance(chunk, protos.Chunk):
862
+ return protos.Chunk(chunk)
863
+ elif isinstance(chunk, str):
864
+ return protos.Chunk(data={"string_value": chunk})
865
+ elif isinstance(chunk, tuple):
866
+ if len(chunk) == 2:
867
+ name, data = chunk # pytype: disable=bad-unpacking
868
+ custom_metadata = None
869
+ elif len(chunk) == 3:
870
+ name, data, custom_metadata = chunk # pytype: disable=bad-unpacking
871
+ else:
872
+ raise ValueError(
873
+ f"Tuples should have length 2 or 3, got length: {len(chunk)}\n"
874
+ f"value: {chunk}"
875
+ )
876
+
877
+ return protos.Chunk(
878
+ name=name,
879
+ data={"string_value": data},
880
+ custom_metadata=custom_metadata,
881
+ )
882
+ elif isinstance(chunk, Mapping):
883
+ if isinstance(chunk["data"], str):
884
+ chunk = dict(chunk)
885
+ chunk["data"] = {"string_value": chunk["data"]}
886
+ return protos.Chunk(chunk)
887
+ else:
888
+ raise TypeError(
889
+ f"Invalid input: Could not convert instance of type '{type(chunk).__name__}' to a chunk. Received value: '{chunk}'."
890
+ )
891
+
892
+ def _make_batch_create_chunk_request(
893
+ self, chunks: BatchCreateChunkOptions
894
+ ) -> protos.BatchCreateChunksRequest:
895
+ if isinstance(chunks, protos.BatchCreateChunksRequest):
896
+ return chunks
897
+
898
+ if isinstance(chunks, Mapping):
899
+ chunks = chunks.items()
900
+ chunks = (
901
+ # Flatten tuples
902
+ (key,) + value if isinstance(value, tuple) else (key, value)
903
+ for key, value in chunks
904
+ )
905
+
906
+ requests = []
907
+ for i, chunk in enumerate(chunks):
908
+ chunk = self._make_chunk(chunk)
909
+ if chunk.name == "":
910
+ chunk.name = str(i)
911
+
912
+ chunk.name = f"{self.name}/chunks/{chunk.name}"
913
+
914
+ requests.append(protos.CreateChunkRequest(parent=self.name, chunk=chunk))
915
+
916
+ return protos.BatchCreateChunksRequest(parent=self.name, requests=requests)
917
+
918
+ def batch_create_chunks(
919
+ self,
920
+ chunks: BatchCreateChunkOptions,
921
+ client: glm.RetrieverServiceClient | None = None,
922
+ request_options: helper_types.RequestOptionsType | None = None,
923
+ ):
924
+ """
925
+ Create chunks within the given document.
926
+
927
+ Args:
928
+ chunks: `Chunks` to create.
929
+ request_options: Options for the request.
930
+
931
+ Return:
932
+ Information about the created chunks.
933
+ """
934
+ if request_options is None:
935
+ request_options = {}
936
+
937
+ if client is None:
938
+ client = get_default_retriever_client()
939
+
940
+ request = self._make_batch_create_chunk_request(chunks)
941
+ response = client.batch_create_chunks(request, **request_options)
942
+ return [decode_chunk(chunk) for chunk in response.chunks]
943
+
944
+ async def batch_create_chunks_async(
945
+ self,
946
+ chunks: BatchCreateChunkOptions,
947
+ client: glm.RetrieverServiceAsyncClient | None = None,
948
+ request_options: helper_types.RequestOptionsType | None = None,
949
+ ):
950
+ """This is the async version of `Document.batch_create_chunk`."""
951
+ if request_options is None:
952
+ request_options = {}
953
+
954
+ if client is None:
955
+ client = get_default_retriever_async_client()
956
+
957
+ request = self._make_batch_create_chunk_request(chunks)
958
+ response = await client.batch_create_chunks(request, **request_options)
959
+ return [decode_chunk(chunk) for chunk in response.chunks]
960
+
961
+ def get_chunk(
962
+ self,
963
+ name: str,
964
+ client: glm.RetrieverServiceClient | None = None,
965
+ request_options: helper_types.RequestOptionsType | None = None,
966
+ ):
967
+ """
968
+ Get information about a specific chunk.
969
+
970
+ Args:
971
+ name: Name of `Chunk`.
972
+ request_options: Options for the request.
973
+
974
+ Returns:
975
+ `Chunk` that was requested.
976
+ """
977
+ if request_options is None:
978
+ request_options = {}
979
+
980
+ if client is None:
981
+ client = get_default_retriever_client()
982
+
983
+ if "/" not in name:
984
+ name = f"{self.name}/chunks/{name}"
985
+
986
+ request = protos.GetChunkRequest(name=name)
987
+ response = client.get_chunk(request, **request_options)
988
+ return decode_chunk(response)
989
+
990
+ async def get_chunk_async(
991
+ self,
992
+ name: str,
993
+ client: glm.RetrieverServiceAsyncClient | None = None,
994
+ request_options: helper_types.RequestOptionsType | None = None,
995
+ ):
996
+ """This is the async version of `Document.get_chunk`."""
997
+ if request_options is None:
998
+ request_options = {}
999
+
1000
+ if client is None:
1001
+ client = get_default_retriever_async_client()
1002
+
1003
+ if "/" not in name:
1004
+ name = f"{self.name}/chunks/{name}"
1005
+
1006
+ request = protos.GetChunkRequest(name=name)
1007
+ response = await client.get_chunk(request, **request_options)
1008
+ return decode_chunk(response)
1009
+
1010
+ def list_chunks(
1011
+ self,
1012
+ page_size: int | None = None,
1013
+ client: glm.RetrieverServiceClient | None = None,
1014
+ request_options: helper_types.RequestOptionsType | None = None,
1015
+ ) -> Iterable[Chunk]:
1016
+ """
1017
+ List chunks of a document.
1018
+
1019
+ Args:
1020
+ page_size: Maximum number of `Chunk`s to request.
1021
+ request_options: Options for the request.
1022
+
1023
+ Return:
1024
+ List of chunks in the document.
1025
+ """
1026
+ if request_options is None:
1027
+ request_options = {}
1028
+
1029
+ if client is None:
1030
+ client = get_default_retriever_client()
1031
+
1032
+ request = protos.ListChunksRequest(parent=self.name, page_size=page_size)
1033
+ for chunk in client.list_chunks(request, **request_options):
1034
+ yield decode_chunk(chunk)
1035
+
1036
+ async def list_chunks_async(
1037
+ self,
1038
+ page_size: int | None = None,
1039
+ client: glm.RetrieverServiceClient | None = None,
1040
+ request_options: helper_types.RequestOptionsType | None = None,
1041
+ ) -> AsyncIterable[Chunk]:
1042
+ """This is the async version of `Document.list_chunks`."""
1043
+ if request_options is None:
1044
+ request_options = {}
1045
+
1046
+ if client is None:
1047
+ client = get_default_retriever_async_client()
1048
+
1049
+ request = protos.ListChunksRequest(parent=self.name, page_size=page_size)
1050
+ async for chunk in await client.list_chunks(request, **request_options):
1051
+ yield decode_chunk(chunk)
1052
+
1053
+ def query(
1054
+ self,
1055
+ query: str,
1056
+ metadata_filters: Iterable[MetadataFilter] | None = None,
1057
+ results_count: int | None = None,
1058
+ client: glm.RetrieverServiceClient | None = None,
1059
+ request_options: helper_types.RequestOptionsType | None = None,
1060
+ ) -> list[RelevantChunk]:
1061
+ """
1062
+ Query a `Document` in the `Corpus` for information.
1063
+
1064
+ Args:
1065
+ query: Query string to perform semantic search.
1066
+ metadata_filters: Filter for `Chunk` metadata.
1067
+ results_count: The maximum number of `Chunk`s to return.
1068
+
1069
+ Returns:
1070
+ List of relevant chunks.
1071
+ """
1072
+ if request_options is None:
1073
+ request_options = {}
1074
+
1075
+ if client is None:
1076
+ client = get_default_retriever_client()
1077
+
1078
+ if results_count:
1079
+ if results_count < 0 or results_count >= 100:
1080
+ raise ValueError(
1081
+ "Invalid operation: The number of results returned must be between 1 and 100."
1082
+ )
1083
+
1084
+ m_f_ = []
1085
+ if metadata_filters:
1086
+ for mf in metadata_filters:
1087
+ m_f_.append(mf._to_proto())
1088
+
1089
+ request = protos.QueryDocumentRequest(
1090
+ name=self.name,
1091
+ query=query,
1092
+ metadata_filters=m_f_,
1093
+ results_count=results_count,
1094
+ )
1095
+ response = client.query_document(request, **request_options)
1096
+ response = type(response).to_dict(response)
1097
+
1098
+ # Create a RelevantChunk object for each chunk listed in response['relevant_chunks']
1099
+ relevant_chunks = []
1100
+ for c in response["relevant_chunks"]:
1101
+ rc = RelevantChunk(
1102
+ chunk_relevance_score=c["chunk_relevance_score"], chunk=Chunk(**c["chunk"])
1103
+ )
1104
+ relevant_chunks.append(rc)
1105
+
1106
+ return relevant_chunks
1107
+
1108
+ async def query_async(
1109
+ self,
1110
+ query: str,
1111
+ metadata_filters: Iterable[MetadataFilter] | None = None,
1112
+ results_count: int | None = None,
1113
+ client: glm.RetrieverServiceAsyncClient | None = None,
1114
+ request_options: helper_types.RequestOptionsType | None = None,
1115
+ ) -> list[RelevantChunk]:
1116
+ """This is the async version of `Document.query`."""
1117
+ if request_options is None:
1118
+ request_options = {}
1119
+
1120
+ if client is None:
1121
+ client = get_default_retriever_async_client()
1122
+
1123
+ if results_count:
1124
+ if results_count < 0 or results_count >= 100:
1125
+ raise ValueError(
1126
+ "Invalid operation: The number of results returned must be between 1 and 100."
1127
+ )
1128
+
1129
+ m_f_ = []
1130
+ if metadata_filters:
1131
+ for mf in metadata_filters:
1132
+ m_f_.append(mf._to_proto())
1133
+
1134
+ request = protos.QueryDocumentRequest(
1135
+ name=self.name,
1136
+ query=query,
1137
+ metadata_filters=m_f_,
1138
+ results_count=results_count,
1139
+ )
1140
+ response = await client.query_document(request, **request_options)
1141
+ response = type(response).to_dict(response)
1142
+
1143
+ # Create a RelevantChunk object for each chunk listed in response['relevant_chunks']
1144
+ relevant_chunks = []
1145
+ for c in response["relevant_chunks"]:
1146
+ rc = RelevantChunk(
1147
+ chunk_relevance_score=c["chunk_relevance_score"], chunk=Chunk(**c["chunk"])
1148
+ )
1149
+ relevant_chunks.append(rc)
1150
+
1151
+ return relevant_chunks
1152
+
1153
+ def _apply_update(self, path, value):
1154
+ parts = path.split(".")
1155
+ for part in parts[:-1]:
1156
+ self = getattr(self, part)
1157
+ setattr(self, parts[-1], value)
1158
+
1159
+ def update(
1160
+ self,
1161
+ updates: dict[str, Any],
1162
+ client: glm.RetrieverServiceClient | None = None,
1163
+ request_options: helper_types.RequestOptionsType | None = None,
1164
+ ):
1165
+ """
1166
+ Update a list of fields for a specified document.
1167
+
1168
+ Args:
1169
+ updates: The list of fields to update.
1170
+ request_options: Options for the request.
1171
+
1172
+ Return:
1173
+ `Chunk` object with specified updates.
1174
+ """
1175
+ if request_options is None:
1176
+ request_options = {}
1177
+
1178
+ if client is None:
1179
+ client = get_default_retriever_client()
1180
+
1181
+ updates = flatten_update_paths(updates)
1182
+ # At this time, only `display_name` can be updated
1183
+ for item in updates:
1184
+ if item != "display_name":
1185
+ raise ValueError(
1186
+ "Invalid operation: Currently, only the 'display_name' attribute can be updated for a 'Document'."
1187
+ )
1188
+ field_mask = field_mask_pb2.FieldMask()
1189
+ for path in updates.keys():
1190
+ field_mask.paths.append(path)
1191
+ for path, value in updates.items():
1192
+ self._apply_update(path, value)
1193
+
1194
+ request = protos.UpdateDocumentRequest(document=self.to_dict(), update_mask=field_mask)
1195
+ client.update_document(request, **request_options)
1196
+ return self
1197
+
1198
+ async def update_async(
1199
+ self,
1200
+ updates: dict[str, Any],
1201
+ client: glm.RetrieverServiceAsyncClient | None = None,
1202
+ request_options: helper_types.RequestOptionsType | None = None,
1203
+ ):
1204
+ """This is the async version of `Document.update`."""
1205
+ if request_options is None:
1206
+ request_options = {}
1207
+
1208
+ if client is None:
1209
+ client = get_default_retriever_async_client()
1210
+
1211
+ updates = flatten_update_paths(updates)
1212
+ # At this time, only `display_name` can be updated
1213
+ for item in updates:
1214
+ if item != "display_name":
1215
+ raise ValueError(
1216
+ "Invalid operation: Currently, only the 'display_name' attribute can be updated for a 'Document'."
1217
+ )
1218
+ field_mask = field_mask_pb2.FieldMask()
1219
+ for path in updates.keys():
1220
+ field_mask.paths.append(path)
1221
+ for path, value in updates.items():
1222
+ self._apply_update(path, value)
1223
+
1224
+ request = protos.UpdateDocumentRequest(document=self.to_dict(), update_mask=field_mask)
1225
+ await client.update_document(request, **request_options)
1226
+ return self
1227
+
1228
+ def batch_update_chunks(
1229
+ self,
1230
+ chunks: BatchUpdateChunksOptions,
1231
+ client: glm.RetrieverServiceClient | None = None,
1232
+ request_options: helper_types.RequestOptionsType | None = None,
1233
+ ):
1234
+ """
1235
+ Update multiple chunks within the same document.
1236
+
1237
+ Args:
1238
+ chunks: Data structure specifying which `Chunk`s to update and what the required updates are.
1239
+ request_options: Options for the request.
1240
+
1241
+ Return:
1242
+ Updated `Chunk`s.
1243
+ """
1244
+ if request_options is None:
1245
+ request_options = {}
1246
+
1247
+ if client is None:
1248
+ client = get_default_retriever_client()
1249
+
1250
+ if isinstance(chunks, protos.BatchUpdateChunksRequest):
1251
+ response = client.batch_update_chunks(chunks)
1252
+ response = type(response).to_dict(response)
1253
+ return response
1254
+
1255
+ _requests = []
1256
+ if isinstance(chunks, Mapping):
1257
+ # Key is name of chunk, value is a dictionary of updates
1258
+ for key, value in chunks.items():
1259
+ chunk_to_update = self.get_chunk(name=key)
1260
+
1261
+ # Handle the custom_metadata parameter
1262
+ c_data = []
1263
+ if chunk_to_update.custom_metadata:
1264
+ for cm in chunk_to_update.custom_metadata:
1265
+ c_data.append(cm._to_proto())
1266
+
1267
+ # When handling updates, use to the _to_proto result of the custom_metadata
1268
+ chunk_to_update.custom_metadata = c_data
1269
+
1270
+ updates = flatten_update_paths(value)
1271
+ # At this time, only `data` can be updated
1272
+ for item in updates:
1273
+ if item != "data.string_value":
1274
+ raise ValueError(
1275
+ f"Invalid operation: Currently, only the 'data' attribute can be updated for a 'Chunk'. Attempted to update '{item}'."
1276
+ )
1277
+ field_mask = field_mask_pb2.FieldMask()
1278
+ for path in updates.keys():
1279
+ field_mask.paths.append(path)
1280
+ for path, value in updates.items():
1281
+ chunk_to_update._apply_update(path, value)
1282
+ _requests.append(
1283
+ protos.UpdateChunkRequest(
1284
+ chunk=chunk_to_update.to_dict(), update_mask=field_mask
1285
+ )
1286
+ )
1287
+ request = protos.BatchUpdateChunksRequest(parent=self.name, requests=_requests)
1288
+ response = client.batch_update_chunks(request, **request_options)
1289
+ response = type(response).to_dict(response)
1290
+ return response
1291
+ if isinstance(chunks, Iterable) and not isinstance(chunks, Mapping):
1292
+ for chunk in chunks:
1293
+ if isinstance(chunk, protos.UpdateChunkRequest):
1294
+ _requests.append(chunk)
1295
+ elif isinstance(chunk, tuple):
1296
+ # First element is name of chunk, second element contains updates
1297
+ chunk_to_update = self.get_chunk(name=chunk[0])
1298
+
1299
+ # Handle the custom_metadata parameter
1300
+ c_data = []
1301
+ if chunk_to_update.custom_metadata:
1302
+ for cm in chunk_to_update.custom_metadata:
1303
+ c_data.append(cm._to_proto())
1304
+
1305
+ # When handling updates, use to the _to_proto result of the custom_metadata
1306
+ chunk_to_update.custom_metadata = c_data
1307
+
1308
+ updates = flatten_update_paths(chunk[1])
1309
+ field_mask = field_mask_pb2.FieldMask()
1310
+ for path in updates.keys():
1311
+ field_mask.paths.append(path)
1312
+ for path, value in updates.items():
1313
+ chunk_to_update._apply_update(path, value)
1314
+ _requests.append(
1315
+ {"chunk": chunk_to_update.to_dict(), "update_mask": field_mask}
1316
+ )
1317
+ else:
1318
+ raise TypeError(
1319
+ "Invalid input: The 'chunks' parameter must be a list of 'protos.UpdateChunkRequests',"
1320
+ " dictionaries, or tuples of dictionaries."
1321
+ )
1322
+ request = protos.BatchUpdateChunksRequest(parent=self.name, requests=_requests)
1323
+ response = client.batch_update_chunks(request, **request_options)
1324
+ response = type(response).to_dict(response)
1325
+ return response
1326
+
1327
+ async def batch_update_chunks_async(
1328
+ self,
1329
+ chunks: BatchUpdateChunksOptions,
1330
+ client: glm.RetrieverServiceAsyncClient | None = None,
1331
+ request_options: helper_types.RequestOptionsType | None = None,
1332
+ ):
1333
+ """This is the async version of `Document.batch_update_chunks`."""
1334
+ if request_options is None:
1335
+ request_options = {}
1336
+
1337
+ if client is None:
1338
+ client = get_default_retriever_async_client()
1339
+
1340
+ if isinstance(chunks, protos.BatchUpdateChunksRequest):
1341
+ response = client.batch_update_chunks(chunks)
1342
+ response = type(response).to_dict(response)
1343
+ return response
1344
+
1345
+ _requests = []
1346
+ if isinstance(chunks, Mapping):
1347
+ # Key is name of chunk, value is a dictionary of updates
1348
+ for key, value in chunks.items():
1349
+ chunk_to_update = self.get_chunk(name=key)
1350
+
1351
+ # Handle the custom_metadata parameter
1352
+ c_data = []
1353
+ if chunk_to_update.custom_metadata:
1354
+ for cm in chunk_to_update.custom_metadata:
1355
+ c_data.append(cm._to_proto())
1356
+
1357
+ # When handling updates, use to the _to_proto result of the custom_metadata
1358
+ chunk_to_update.custom_metadata = c_data
1359
+
1360
+ updates = flatten_update_paths(value)
1361
+ # At this time, only `data` can be updated
1362
+ for item in updates:
1363
+ if item != "data.string_value":
1364
+ raise ValueError(
1365
+ f"Invalid operation: Currently, only the 'data' attribute can be updated for a 'Chunk'. Attempted to update '{item}'."
1366
+ )
1367
+ field_mask = field_mask_pb2.FieldMask()
1368
+ for path in updates.keys():
1369
+ field_mask.paths.append(path)
1370
+ for path, value in updates.items():
1371
+ chunk_to_update._apply_update(path, value)
1372
+ _requests.append(
1373
+ protos.UpdateChunkRequest(
1374
+ chunk=chunk_to_update.to_dict(), update_mask=field_mask
1375
+ )
1376
+ )
1377
+ request = protos.BatchUpdateChunksRequest(parent=self.name, requests=_requests)
1378
+ response = await client.batch_update_chunks(request, **request_options)
1379
+ response = type(response).to_dict(response)
1380
+ return response
1381
+ if isinstance(chunks, Iterable) and not isinstance(chunks, Mapping):
1382
+ for chunk in chunks:
1383
+ if isinstance(chunk, protos.UpdateChunkRequest):
1384
+ _requests.append(chunk)
1385
+ elif isinstance(chunk, tuple):
1386
+ # First element is name of chunk, second element contains updates
1387
+ chunk_to_update = self.get_chunk(name=chunk[0])
1388
+
1389
+ # Handle the custom_metadata parameter
1390
+ c_data = []
1391
+ if chunk_to_update.custom_metadata:
1392
+ for cm in chunk_to_update.custom_metadata:
1393
+ c_data.append(cm._to_proto())
1394
+
1395
+ # When handling updates, use to the _to_proto result of the custom_metadata
1396
+ chunk_to_update.custom_metadata = c_data
1397
+
1398
+ updates = flatten_update_paths(chunk[1])
1399
+ field_mask = field_mask_pb2.FieldMask()
1400
+ for path in updates.keys():
1401
+ field_mask.paths.append(path)
1402
+ for path, value in updates.items():
1403
+ chunk_to_update._apply_update(path, value)
1404
+ _requests.append(
1405
+ {"chunk": chunk_to_update.to_dict(), "update_mask": field_mask}
1406
+ )
1407
+ else:
1408
+ raise TypeError(
1409
+ "Invalid input: The 'chunks' parameter must be a list of 'protos.UpdateChunkRequests', "
1410
+ "dictionaries, or tuples of dictionaries."
1411
+ )
1412
+ request = protos.BatchUpdateChunksRequest(parent=self.name, requests=_requests)
1413
+ response = await client.batch_update_chunks(request, **request_options)
1414
+ response = type(response).to_dict(response)
1415
+ return response
1416
+
1417
+ def delete_chunk(
1418
+ self,
1419
+ name: str,
1420
+ client: glm.RetrieverServiceClient | None = None,
1421
+ request_options: helper_types.RequestOptionsType | None = None, # fmt: {}
1422
+ ):
1423
+ """
1424
+ Delete a `Chunk`.
1425
+
1426
+ Args:
1427
+ name: The `Chunk` name.
1428
+ request_options: Options for the request.
1429
+ """
1430
+ if request_options is None:
1431
+ request_options = {}
1432
+
1433
+ if client is None:
1434
+ client = get_default_retriever_client()
1435
+
1436
+ if "/" not in name:
1437
+ name = f"{self.name}/chunks/{name}"
1438
+
1439
+ request = protos.DeleteChunkRequest(name=name)
1440
+ client.delete_chunk(request, **request_options)
1441
+
1442
+ async def delete_chunk_async(
1443
+ self,
1444
+ name: str,
1445
+ client: glm.RetrieverServiceAsyncClient | None = None,
1446
+ request_options: helper_types.RequestOptionsType | None = None, # fmt: {}
1447
+ ):
1448
+ """This is the async version of `Document.delete_chunk`."""
1449
+ if request_options is None:
1450
+ request_options = {}
1451
+
1452
+ if client is None:
1453
+ client = get_default_retriever_async_client()
1454
+
1455
+ if "/" not in name:
1456
+ name = f"{self.name}/chunks/{name}"
1457
+
1458
+ request = protos.DeleteChunkRequest(name=name)
1459
+ await client.delete_chunk(request, **request_options)
1460
+
1461
+ def batch_delete_chunks(
1462
+ self,
1463
+ chunks: BatchDeleteChunkOptions,
1464
+ client: glm.RetrieverServiceClient | None = None,
1465
+ request_options: helper_types.RequestOptionsType | None = None,
1466
+ ):
1467
+ """
1468
+ Delete multiple `Chunk`s from a document.
1469
+
1470
+ Args:
1471
+ chunks: Names of `Chunks` to delete.
1472
+ request_options: Options for the request.
1473
+ """
1474
+ if request_options is None:
1475
+ request_options = {}
1476
+
1477
+ if client is None:
1478
+ client = get_default_retriever_client()
1479
+
1480
+ if all(isinstance(x, protos.DeleteChunkRequest) for x in chunks):
1481
+ request = protos.BatchDeleteChunksRequest(parent=self.name, requests=chunks)
1482
+ client.batch_delete_chunks(request, **request_options)
1483
+ elif isinstance(chunks, Iterable):
1484
+ _request_list = []
1485
+ for chunk_name in chunks:
1486
+ _request_list.append(protos.DeleteChunkRequest(name=chunk_name))
1487
+ request = protos.BatchDeleteChunksRequest(parent=self.name, requests=_request_list)
1488
+ client.batch_delete_chunks(request, **request_options)
1489
+ else:
1490
+ raise ValueError(
1491
+ "Invalid operation: To delete chunks, you must pass in either the names of the chunks as an iterable, "
1492
+ "or multiple 'protos.DeleteChunkRequest's."
1493
+ )
1494
+
1495
+ async def batch_delete_chunks_async(
1496
+ self,
1497
+ chunks: BatchDeleteChunkOptions,
1498
+ client: glm.RetrieverServiceAsyncClient | None = None,
1499
+ request_options: helper_types.RequestOptionsType | None = None,
1500
+ ):
1501
+ """This is the async version of `Document.batch_delete_chunks`."""
1502
+ if request_options is None:
1503
+ request_options = {}
1504
+
1505
+ if client is None:
1506
+ client = get_default_retriever_async_client()
1507
+
1508
+ if all(isinstance(x, protos.DeleteChunkRequest) for x in chunks):
1509
+ request = protos.BatchDeleteChunksRequest(parent=self.name, requests=chunks)
1510
+ await client.batch_delete_chunks(request, **request_options)
1511
+ elif isinstance(chunks, Iterable):
1512
+ _request_list = []
1513
+ for chunk_name in chunks:
1514
+ _request_list.append(protos.DeleteChunkRequest(name=chunk_name))
1515
+ request = protos.BatchDeleteChunksRequest(parent=self.name, requests=_request_list)
1516
+ await client.batch_delete_chunks(request, **request_options)
1517
+ else:
1518
+ raise ValueError(
1519
+ "Invalid operation: To delete chunks, you must pass in either the names of the chunks as an iterable, "
1520
+ "or multiple 'protos.DeleteChunkRequest's."
1521
+ )
1522
+
1523
+ def to_dict(self) -> dict[str, Any]:
1524
+ result = {
1525
+ "name": self.name,
1526
+ "display_name": self.display_name,
1527
+ "custom_metadata": self.custom_metadata,
1528
+ }
1529
+ return result
1530
+
1531
+
1532
+ def decode_chunk(chunk: protos.Chunk) -> Chunk:
1533
+ chunk = type(chunk).to_dict(chunk)
1534
+ idecode_time(chunk, "create_time")
1535
+ idecode_time(chunk, "update_time")
1536
+ return Chunk(**chunk)
1537
+
1538
+
1539
+ @string_utils.prettyprint
1540
+ @dataclasses.dataclass
1541
+ class RelevantChunk:
1542
+ chunk_relevance_score: float
1543
+ chunk: Chunk
1544
+
1545
+
1546
+ @string_utils.prettyprint
1547
+ @dataclasses.dataclass(init=False)
1548
+ class Chunk(abc.ABC):
1549
+ """
1550
+ A `Chunk` is part of the `Document`, or the actual text.
1551
+ """
1552
+
1553
+ name: str
1554
+ data: ChunkData
1555
+ custom_metadata: list[CustomMetadata] | None
1556
+ state: State
1557
+ create_time: datetime.datetime | None
1558
+ update_time: datetime.datetime | None
1559
+
1560
+ def __init__(
1561
+ self,
1562
+ name: str,
1563
+ data: ChunkData | str,
1564
+ custom_metadata: Iterable[CustomMetadata] | None,
1565
+ state: State,
1566
+ create_time: datetime.datetime | str | None = None,
1567
+ update_time: datetime.datetime | str | None = None,
1568
+ ):
1569
+ self.name = name
1570
+ if isinstance(data, str):
1571
+ self.data = ChunkData(string_value=data)
1572
+ elif isinstance(data, dict):
1573
+ self.data = ChunkData(string_value=data["string_value"])
1574
+
1575
+ if custom_metadata is None:
1576
+ self.custom_metadata = []
1577
+ else:
1578
+ self.custom_metadata = [make_custom_metadata(cm) for cm in custom_metadata]
1579
+
1580
+ self.state = to_state(state)
1581
+
1582
+ if create_time is None:
1583
+ self.create_time = None
1584
+ elif isinstance(create_time, datetime.datetime):
1585
+ self.create_time = create_time
1586
+ else:
1587
+ self.create_time = datetime.datetime.strptime(create_time, "%Y-%m-%dT%H:%M:%S.%fZ")
1588
+
1589
+ if update_time is None:
1590
+ self.update_time = None
1591
+ elif isinstance(update_time, datetime.datetime):
1592
+ self.update_time = update_time
1593
+ else:
1594
+ self.update_time = datetime.datetime.strptime(update_time, "%Y-%m-%dT%H:%M:%S.%fZ")
1595
+
1596
+ def _apply_update(self, path, value):
1597
+ parts = path.split(".")
1598
+ for part in parts[:-1]:
1599
+ self = getattr(self, part)
1600
+ setattr(self, parts[-1], value)
1601
+
1602
+ def update(
1603
+ self,
1604
+ updates: dict[str, Any],
1605
+ client: glm.RetrieverServiceClient | None = None,
1606
+ request_options: helper_types.RequestOptionsType | None = None,
1607
+ ):
1608
+ """
1609
+ Update a list of fields for a specified `Chunk`.
1610
+
1611
+ Args:
1612
+ updates: List of fields to update for a `Chunk`.
1613
+ request_options: Options for the request.
1614
+
1615
+ Return:
1616
+ Updated `Chunk` object.
1617
+ """
1618
+ if request_options is None:
1619
+ request_options = {}
1620
+
1621
+ if client is None:
1622
+ client = get_default_retriever_client()
1623
+
1624
+ # Handle the custom_metadata parameter
1625
+ c_data = []
1626
+ if self.custom_metadata:
1627
+ for cm in self.custom_metadata:
1628
+ c_data.append(cm._to_proto())
1629
+
1630
+ # When handling updates, use to the _to_proto result of the custom_metadata
1631
+ self.custom_metadata = c_data
1632
+
1633
+ updates = flatten_update_paths(updates)
1634
+ # At this time, only `data` can be updated
1635
+ for item in updates:
1636
+ if item != "data.string_value":
1637
+ raise ValueError(
1638
+ f"Invalid operation: Currently, only the 'data' attribute can be updated for a 'Chunk'. Attempted to update '{item}'."
1639
+ )
1640
+ field_mask = field_mask_pb2.FieldMask()
1641
+
1642
+ for path in updates.keys():
1643
+ field_mask.paths.append(path)
1644
+ for path, value in updates.items():
1645
+ self._apply_update(path, value)
1646
+ request = protos.UpdateChunkRequest(chunk=self.to_dict(), update_mask=field_mask)
1647
+
1648
+ client.update_chunk(request, **request_options)
1649
+ return self
1650
+
1651
+ async def update_async(
1652
+ self,
1653
+ updates: dict[str, Any],
1654
+ client: glm.RetrieverServiceAsyncClient | None = None,
1655
+ request_options: helper_types.RequestOptionsType | None = None,
1656
+ ):
1657
+ """This is the async version of `Chunk.update`."""
1658
+ if request_options is None:
1659
+ request_options = {}
1660
+
1661
+ if client is None:
1662
+ client = get_default_retriever_async_client()
1663
+
1664
+ # Handle the custom_metadata parameter
1665
+ c_data = []
1666
+ if self.custom_metadata:
1667
+ for cm in self.custom_metadata:
1668
+ c_data.append(cm._to_proto())
1669
+
1670
+ # When handling updates, use to the _to_proto result of the custom_metadata
1671
+ self.custom_metadata = c_data
1672
+
1673
+ updates = flatten_update_paths(updates)
1674
+ # At this time, only `data` can be updated
1675
+ for item in updates:
1676
+ if item != "data.string_value":
1677
+ raise ValueError(
1678
+ f"Invalid operation: Currently, only the 'data' attribute can be updated for a 'Chunk'. Attempted to update '{item}'."
1679
+ )
1680
+ field_mask = field_mask_pb2.FieldMask()
1681
+
1682
+ for path in updates.keys():
1683
+ field_mask.paths.append(path)
1684
+ for path, value in updates.items():
1685
+ self._apply_update(path, value)
1686
+ request = protos.UpdateChunkRequest(chunk=self.to_dict(), update_mask=field_mask)
1687
+
1688
+ await client.update_chunk(request, **request_options)
1689
+ return self
1690
+
1691
+ def to_dict(self) -> dict[str, Any]:
1692
+ result = {
1693
+ "name": self.name,
1694
+ "data": dataclasses.asdict(self.data),
1695
+ "custom_metadata": [cm._to_dict() for cm in self.custom_metadata],
1696
+ "state": self.state,
1697
+ }
1698
+ return result
.venv/lib/python3.11/site-packages/google/logging/type/http_request_pb2.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright 2024 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
18
+ # source: google/logging/type/http_request.proto
19
+ """Generated protocol buffer code."""
20
+ from google.protobuf import descriptor as _descriptor
21
+ from google.protobuf import descriptor_pool as _descriptor_pool
22
+ from google.protobuf import symbol_database as _symbol_database
23
+ from google.protobuf.internal import builder as _builder
24
+
25
+ # @@protoc_insertion_point(imports)
26
+
27
+ _sym_db = _symbol_database.Default()
28
+
29
+
30
+ from google.protobuf import duration_pb2 as google_dot_protobuf_dot_duration__pb2
31
+
32
+
33
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
34
+ b'\n&google/logging/type/http_request.proto\x12\x13google.logging.type\x1a\x1egoogle/protobuf/duration.proto"\xef\x02\n\x0bHttpRequest\x12\x16\n\x0erequest_method\x18\x01 \x01(\t\x12\x13\n\x0brequest_url\x18\x02 \x01(\t\x12\x14\n\x0crequest_size\x18\x03 \x01(\x03\x12\x0e\n\x06status\x18\x04 \x01(\x05\x12\x15\n\rresponse_size\x18\x05 \x01(\x03\x12\x12\n\nuser_agent\x18\x06 \x01(\t\x12\x11\n\tremote_ip\x18\x07 \x01(\t\x12\x11\n\tserver_ip\x18\r \x01(\t\x12\x0f\n\x07referer\x18\x08 \x01(\t\x12*\n\x07latency\x18\x0e \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x14\n\x0c\x63\x61\x63he_lookup\x18\x0b \x01(\x08\x12\x11\n\tcache_hit\x18\t \x01(\x08\x12*\n"cache_validated_with_origin_server\x18\n \x01(\x08\x12\x18\n\x10\x63\x61\x63he_fill_bytes\x18\x0c \x01(\x03\x12\x10\n\x08protocol\x18\x0f \x01(\tB\xbe\x01\n\x17\x63om.google.logging.typeB\x10HttpRequestProtoP\x01Z8google.golang.org/genproto/googleapis/logging/type;ltype\xaa\x02\x19Google.Cloud.Logging.Type\xca\x02\x19Google\\Cloud\\Logging\\Type\xea\x02\x1cGoogle::Cloud::Logging::Typeb\x06proto3'
35
+ )
36
+
37
+ _globals = globals()
38
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
39
+ _builder.BuildTopDescriptorsAndMessages(
40
+ DESCRIPTOR, "google.logging.type.http_request_pb2", _globals
41
+ )
42
+ if _descriptor._USE_C_DESCRIPTORS == False:
43
+ DESCRIPTOR._options = None
44
+ DESCRIPTOR._serialized_options = b"\n\027com.google.logging.typeB\020HttpRequestProtoP\001Z8google.golang.org/genproto/googleapis/logging/type;ltype\252\002\031Google.Cloud.Logging.Type\312\002\031Google\\Cloud\\Logging\\Type\352\002\034Google::Cloud::Logging::Type"
45
+ _globals["_HTTPREQUEST"]._serialized_start = 96
46
+ _globals["_HTTPREQUEST"]._serialized_end = 463
47
+ # @@protoc_insertion_point(module_scope)
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (211 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/any.cpython-311.pyc ADDED
Binary file (1.67 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/any_pb2.cpython-311.pyc ADDED
Binary file (1.95 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/api_pb2.cpython-311.pyc ADDED
Binary file (3.02 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/descriptor_database.cpython-311.pyc ADDED
Binary file (7 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/descriptor_pool.cpython-311.pyc ADDED
Binary file (58.2 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/duration.cpython-311.pyc ADDED
Binary file (4.31 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/empty_pb2.cpython-311.pyc ADDED
Binary file (1.93 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/json_format.cpython-311.pyc ADDED
Binary file (46.3 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto.cpython-311.pyc ADDED
Binary file (4.41 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto_builder.cpython-311.pyc ADDED
Binary file (4.74 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/proto_json.cpython-311.pyc ADDED
Binary file (3.25 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/reflection.cpython-311.pyc ADDED
Binary file (2.78 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/runtime_version.cpython-311.pyc ADDED
Binary file (4.68 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/service.cpython-311.pyc ADDED
Binary file (9.8 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/service_reflection.cpython-311.pyc ADDED
Binary file (13.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/source_context_pb2.cpython-311.pyc ADDED
Binary file (2.04 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/struct_pb2.cpython-311.pyc ADDED
Binary file (2.97 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/timestamp.cpython-311.pyc ADDED
Binary file (4.96 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/timestamp_pb2.cpython-311.pyc ADDED
Binary file (2.02 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/__pycache__/wrappers_pb2.cpython-311.pyc ADDED
Binary file (3.09 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/compiler/__init__.py ADDED
File without changes
.venv/lib/python3.11/site-packages/google/protobuf/compiler/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (197 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/compiler/__pycache__/plugin_pb2.cpython-311.pyc ADDED
Binary file (3.5 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/compiler/plugin_pb2.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/compiler/plugin.proto
5
+ # Protobuf Python Version: 5.29.3
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 3,
17
+ '',
18
+ 'google/protobuf/compiler/plugin.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n%google/protobuf/compiler/plugin.proto\x12\x18google.protobuf.compiler\x1a google/protobuf/descriptor.proto\"c\n\x07Version\x12\x14\n\x05major\x18\x01 \x01(\x05R\x05major\x12\x14\n\x05minor\x18\x02 \x01(\x05R\x05minor\x12\x14\n\x05patch\x18\x03 \x01(\x05R\x05patch\x12\x16\n\x06suffix\x18\x04 \x01(\tR\x06suffix\"\xcf\x02\n\x14\x43odeGeneratorRequest\x12(\n\x10\x66ile_to_generate\x18\x01 \x03(\tR\x0e\x66ileToGenerate\x12\x1c\n\tparameter\x18\x02 \x01(\tR\tparameter\x12\x43\n\nproto_file\x18\x0f \x03(\x0b\x32$.google.protobuf.FileDescriptorProtoR\tprotoFile\x12\\\n\x17source_file_descriptors\x18\x11 \x03(\x0b\x32$.google.protobuf.FileDescriptorProtoR\x15sourceFileDescriptors\x12L\n\x10\x63ompiler_version\x18\x03 \x01(\x0b\x32!.google.protobuf.compiler.VersionR\x0f\x63ompilerVersion\"\x85\x04\n\x15\x43odeGeneratorResponse\x12\x14\n\x05\x65rror\x18\x01 \x01(\tR\x05\x65rror\x12-\n\x12supported_features\x18\x02 \x01(\x04R\x11supportedFeatures\x12\'\n\x0fminimum_edition\x18\x03 \x01(\x05R\x0eminimumEdition\x12\'\n\x0fmaximum_edition\x18\x04 \x01(\x05R\x0emaximumEdition\x12H\n\x04\x66ile\x18\x0f \x03(\x0b\x32\x34.google.protobuf.compiler.CodeGeneratorResponse.FileR\x04\x66ile\x1a\xb1\x01\n\x04\x46ile\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\'\n\x0finsertion_point\x18\x02 \x01(\tR\x0einsertionPoint\x12\x18\n\x07\x63ontent\x18\x0f \x01(\tR\x07\x63ontent\x12R\n\x13generated_code_info\x18\x10 \x01(\x0b\x32\".google.protobuf.GeneratedCodeInfoR\x11generatedCodeInfo\"W\n\x07\x46\x65\x61ture\x12\x10\n\x0c\x46\x45\x41TURE_NONE\x10\x00\x12\x1b\n\x17\x46\x45\x41TURE_PROTO3_OPTIONAL\x10\x01\x12\x1d\n\x19\x46\x45\x41TURE_SUPPORTS_EDITIONS\x10\x02\x42r\n\x1c\x63om.google.protobuf.compilerB\x0cPluginProtosZ)google.golang.org/protobuf/types/pluginpb\xaa\x02\x18Google.Protobuf.Compiler')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.compiler.plugin_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'\n\034com.google.protobuf.compilerB\014PluginProtosZ)google.golang.org/protobuf/types/pluginpb\252\002\030Google.Protobuf.Compiler'
36
+ _globals['_VERSION']._serialized_start=101
37
+ _globals['_VERSION']._serialized_end=200
38
+ _globals['_CODEGENERATORREQUEST']._serialized_start=203
39
+ _globals['_CODEGENERATORREQUEST']._serialized_end=538
40
+ _globals['_CODEGENERATORRESPONSE']._serialized_start=541
41
+ _globals['_CODEGENERATORRESPONSE']._serialized_end=1058
42
+ _globals['_CODEGENERATORRESPONSE_FILE']._serialized_start=792
43
+ _globals['_CODEGENERATORRESPONSE_FILE']._serialized_end=969
44
+ _globals['_CODEGENERATORRESPONSE_FEATURE']._serialized_start=971
45
+ _globals['_CODEGENERATORRESPONSE_FEATURE']._serialized_end=1058
46
+ # @@protoc_insertion_point(module_scope)
.venv/lib/python3.11/site-packages/google/protobuf/internal/__init__.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
.venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (197 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/_parameterized.cpython-311.pyc ADDED
Binary file (18.7 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/api_implementation.cpython-311.pyc ADDED
Binary file (3.68 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/builder.cpython-311.pyc ADDED
Binary file (5.55 kB). View file
 
.venv/lib/python3.11/site-packages/google/protobuf/internal/__pycache__/containers.cpython-311.pyc ADDED
Binary file (34.8 kB). View file