frogml-core 0.0.112__py3-none-any.whl → 0.0.114__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. frogml_core/__init__.py +1 -1
  2. frogml_core/inner/di_configuration/__init__.py +0 -6
  3. {frogml_core-0.0.112.dist-info → frogml_core-0.0.114.dist-info}/METADATA +1 -1
  4. {frogml_core-0.0.112.dist-info → frogml_core-0.0.114.dist-info}/RECORD +8 -115
  5. frogml_services_mock/mocks/frogml_mocks.py +0 -11
  6. frogml_services_mock/services_mock.py +0 -48
  7. frogml_storage/__init__.py +1 -1
  8. frogml_core/clients/prompt_manager/__init__.py +0 -0
  9. frogml_core/clients/prompt_manager/model_descriptor_mapper.py +0 -196
  10. frogml_core/clients/prompt_manager/prompt_manager_client.py +0 -190
  11. frogml_core/clients/prompt_manager/prompt_proto_mapper.py +0 -264
  12. frogml_core/clients/vector_store/__init__.py +0 -2
  13. frogml_core/clients/vector_store/management_client.py +0 -127
  14. frogml_core/clients/vector_store/serving_client.py +0 -157
  15. frogml_core/clients/workspace_manager/__init__.py +0 -1
  16. frogml_core/clients/workspace_manager/client.py +0 -224
  17. frogml_core/llmops/__init__.py +0 -0
  18. frogml_core/llmops/generation/__init__.py +0 -0
  19. frogml_core/llmops/generation/_steaming.py +0 -78
  20. frogml_core/llmops/generation/base.py +0 -5
  21. frogml_core/llmops/generation/chat/__init__.py +0 -0
  22. frogml_core/llmops/generation/chat/openai/LICENSE.txt +0 -201
  23. frogml_core/llmops/generation/chat/openai/types/__init__.py +0 -0
  24. frogml_core/llmops/generation/chat/openai/types/chat/__init__.py +0 -0
  25. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion.py +0 -88
  26. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_assistant_message_param.py +0 -65
  27. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_chunk.py +0 -153
  28. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_content_part_text_param.py +0 -28
  29. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_function_call_option_param.py +0 -25
  30. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_function_message_param.py +0 -33
  31. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message.py +0 -56
  32. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_param.py +0 -34
  33. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_tool_call.py +0 -46
  34. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_tool_call_param.py +0 -44
  35. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_named_tool_choice_param.py +0 -32
  36. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_role.py +0 -20
  37. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_system_message_param.py +0 -35
  38. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_token_logprob.py +0 -71
  39. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_choice_option_param.py +0 -28
  40. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_message_param.py +0 -31
  41. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_param.py +0 -29
  42. frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_user_message_param.py +0 -35
  43. frogml_core/llmops/generation/chat/openai/types/chat/completion_create_params.py +0 -279
  44. frogml_core/llmops/generation/chat/openai/types/completion_choice.py +0 -47
  45. frogml_core/llmops/generation/chat/openai/types/completion_create_params.py +0 -209
  46. frogml_core/llmops/generation/chat/openai/types/completion_usage.py +0 -30
  47. frogml_core/llmops/generation/chat/openai/types/model.py +0 -35
  48. frogml_core/llmops/generation/chat/openai/types/shared/__init__.py +0 -3
  49. frogml_core/llmops/generation/chat/openai/types/shared/error_object.py +0 -27
  50. frogml_core/llmops/generation/chat/openai/types/shared/function_definition.py +0 -49
  51. frogml_core/llmops/generation/chat/openai/types/shared/function_parameters.py +0 -20
  52. frogml_core/llmops/generation/chat/openai/types/shared_params/__init__.py +0 -2
  53. frogml_core/llmops/generation/chat/openai/types/shared_params/function_definition.py +0 -49
  54. frogml_core/llmops/generation/chat/openai/types/shared_params/function_parameters.py +0 -22
  55. frogml_core/llmops/generation/streaming.py +0 -26
  56. frogml_core/llmops/model/__init__.py +0 -0
  57. frogml_core/llmops/model/descriptor.py +0 -40
  58. frogml_core/llmops/prompt/__init__.py +0 -0
  59. frogml_core/llmops/prompt/base.py +0 -136
  60. frogml_core/llmops/prompt/chat/__init__.py +0 -0
  61. frogml_core/llmops/prompt/chat/message.py +0 -24
  62. frogml_core/llmops/prompt/chat/template.py +0 -113
  63. frogml_core/llmops/prompt/chat/value.py +0 -10
  64. frogml_core/llmops/prompt/manager.py +0 -138
  65. frogml_core/llmops/prompt/template.py +0 -24
  66. frogml_core/llmops/prompt/value.py +0 -14
  67. frogml_core/llmops/provider/__init__.py +0 -0
  68. frogml_core/llmops/provider/chat.py +0 -44
  69. frogml_core/llmops/provider/openai/__init__.py +0 -0
  70. frogml_core/llmops/provider/openai/client.py +0 -126
  71. frogml_core/llmops/provider/openai/provider.py +0 -93
  72. frogml_core/vector_store/__init__.py +0 -4
  73. frogml_core/vector_store/client.py +0 -151
  74. frogml_core/vector_store/collection.py +0 -429
  75. frogml_core/vector_store/filters.py +0 -359
  76. frogml_core/vector_store/inference_client.py +0 -105
  77. frogml_core/vector_store/rest_helpers.py +0 -81
  78. frogml_core/vector_store/utils/__init__.py +0 -0
  79. frogml_core/vector_store/utils/filter_utils.py +0 -23
  80. frogml_core/vector_store/utils/upsert_utils.py +0 -218
  81. frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2.py +0 -77
  82. frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2.pyi +0 -417
  83. frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2_grpc.py +0 -441
  84. frogml_proto/qwak/prompt/v1/prompt/prompt_pb2.py +0 -69
  85. frogml_proto/qwak/prompt/v1/prompt/prompt_pb2.pyi +0 -415
  86. frogml_proto/qwak/prompt/v1/prompt/prompt_pb2_grpc.py +0 -4
  87. frogml_proto/qwak/vectors/v1/collection/collection_pb2.py +0 -46
  88. frogml_proto/qwak/vectors/v1/collection/collection_pb2.pyi +0 -287
  89. frogml_proto/qwak/vectors/v1/collection/collection_pb2_grpc.py +0 -4
  90. frogml_proto/qwak/vectors/v1/collection/collection_service_pb2.py +0 -60
  91. frogml_proto/qwak/vectors/v1/collection/collection_service_pb2.pyi +0 -258
  92. frogml_proto/qwak/vectors/v1/collection/collection_service_pb2_grpc.py +0 -304
  93. frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2.py +0 -28
  94. frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2.pyi +0 -41
  95. frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2_grpc.py +0 -4
  96. frogml_proto/qwak/vectors/v1/filters_pb2.py +0 -52
  97. frogml_proto/qwak/vectors/v1/filters_pb2.pyi +0 -297
  98. frogml_proto/qwak/vectors/v1/filters_pb2_grpc.py +0 -4
  99. frogml_proto/qwak/vectors/v1/vector_pb2.py +0 -38
  100. frogml_proto/qwak/vectors/v1/vector_pb2.pyi +0 -142
  101. frogml_proto/qwak/vectors/v1/vector_pb2_grpc.py +0 -4
  102. frogml_proto/qwak/vectors/v1/vector_service_pb2.py +0 -53
  103. frogml_proto/qwak/vectors/v1/vector_service_pb2.pyi +0 -243
  104. frogml_proto/qwak/vectors/v1/vector_service_pb2_grpc.py +0 -201
  105. frogml_proto/qwak/workspace/workspace_pb2.py +0 -50
  106. frogml_proto/qwak/workspace/workspace_pb2.pyi +0 -331
  107. frogml_proto/qwak/workspace/workspace_pb2_grpc.py +0 -4
  108. frogml_proto/qwak/workspace/workspace_service_pb2.py +0 -84
  109. frogml_proto/qwak/workspace/workspace_service_pb2.pyi +0 -393
  110. frogml_proto/qwak/workspace/workspace_service_pb2_grpc.py +0 -507
  111. frogml_services_mock/mocks/prompt_manager_service.py +0 -281
  112. frogml_services_mock/mocks/vector_serving_api.py +0 -159
  113. frogml_services_mock/mocks/vectors_management_api.py +0 -97
  114. frogml_services_mock/mocks/workspace_manager_service_mock.py +0 -202
  115. {frogml_core-0.0.112.dist-info → frogml_core-0.0.114.dist-info}/WHEEL +0 -0
@@ -1,359 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from dataclasses import dataclass
3
- from typing import Any
4
-
5
- from google.protobuf.json_format import MessageToDict, ParseDict
6
-
7
- from frogml_proto.qwak.vectors.v1.filters_pb2 import And as ProtoAnd
8
- from frogml_proto.qwak.vectors.v1.filters_pb2 import (
9
- AtomicLiteral as ProtoAtomicLiteral,
10
- )
11
- from frogml_proto.qwak.vectors.v1.filters_pb2 import Equal as ProtoEqual
12
- from frogml_proto.qwak.vectors.v1.filters_pb2 import Filter as ProtoFilter
13
- from frogml_proto.qwak.vectors.v1.filters_pb2 import GreaterThan as ProtoGreaterThan
14
- from frogml_proto.qwak.vectors.v1.filters_pb2 import (
15
- GreaterThanEqual as ProtoGreaterThanEqual,
16
- )
17
- from frogml_proto.qwak.vectors.v1.filters_pb2 import IsNotNull as ProtoIsNotNull
18
- from frogml_proto.qwak.vectors.v1.filters_pb2 import IsNull as ProtoIsNull
19
- from frogml_proto.qwak.vectors.v1.filters_pb2 import LessThan as ProtoLessThan
20
- from frogml_proto.qwak.vectors.v1.filters_pb2 import (
21
- LessThanEqual as ProtoLessThanEqual,
22
- )
23
- from frogml_proto.qwak.vectors.v1.filters_pb2 import Like as ProtoLike
24
- from frogml_proto.qwak.vectors.v1.filters_pb2 import NotEqual as ProtoNotEqual
25
- from frogml_proto.qwak.vectors.v1.filters_pb2 import Or as ProtoOr
26
- from frogml_core.vector_store.utils.filter_utils import transform
27
-
28
-
29
- class Filter(ABC):
30
- """Abstract base class for filter objects."""
31
-
32
- def And(self, other):
33
- """Logical AND operation with another filter.
34
-
35
- Usage Example:
36
- ```
37
- filter1 = Equal("age", 30)
38
- filter2 = GreaterThan("score", 90)
39
- combined_filter = filter1.And(filter2)
40
- ```
41
- """
42
- return And(self, other)
43
-
44
- def Or(self, other):
45
- """Logical OR operation with another filter.
46
-
47
- Usage Example:
48
- ```
49
- filter1 = Equal("age", 30)
50
- filter2 = GreaterThan("score", 90)
51
- combined_filter = filter1.Or(filter2)
52
- ```
53
- """
54
- return Or(self, other)
55
-
56
- @abstractmethod
57
- def _to_proto(self):
58
- """Convert the filter to a protobuf representation."""
59
- pass
60
-
61
-
62
- @dataclass
63
- class And(Filter):
64
- """Logical And operation with another filter.
65
-
66
- Usage Example:
67
- ```
68
- filter1 = Equal("age", 30)
69
- filter2 = GreaterThan("score", 90)
70
- combined_filter = And(left=filter1, right=filter2)
71
- ```
72
- """
73
-
74
- left: Filter
75
- right: Filter
76
-
77
- def _to_proto(self):
78
- proto_filter = ProtoFilter()
79
- proto_filter_dict = MessageToDict(proto_filter)
80
- proto_and_dict = MessageToDict(
81
- ProtoAnd(left=self.left._to_proto(), right=self.right._to_proto())
82
- )
83
- proto_filter_dict["and"] = proto_and_dict
84
- return ParseDict(proto_filter_dict, proto_filter, ignore_unknown_fields=True)
85
-
86
-
87
- @dataclass
88
- class Or(Filter):
89
- """Logical OR operation with another filter.
90
-
91
- Usage Example:
92
- ```
93
- filter1 = Equal("age", 30)
94
- filter2 = GreaterThan("score", 90)
95
- combined_filter = Or(left=filter1, right=filter2)
96
- ```
97
- """
98
-
99
- left: Filter
100
- right: Filter
101
-
102
- def _to_proto(self):
103
- proto_filter = ProtoFilter()
104
- proto_filter_dict = MessageToDict(proto_filter)
105
- proto_or_dict = MessageToDict(
106
- ProtoOr(left=self.left._to_proto(), right=self.right._to_proto())
107
- )
108
- proto_filter_dict["or"] = proto_or_dict
109
- return ParseDict(proto_filter_dict, proto_filter, ignore_unknown_fields=True)
110
-
111
-
112
- @dataclass
113
- class _UnaryFilter(Filter):
114
- property: str
115
- value: Any
116
-
117
- def _to_proto(self):
118
- # Each UnaryFilter implements its own _to_proto
119
- pass
120
-
121
-
122
- class Equal(_UnaryFilter):
123
- """Equal operation.
124
-
125
- Usage Example:
126
- ```
127
- filter = Equal(property="age", value=30)
128
- ```
129
- """
130
-
131
- def _to_proto(self):
132
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
133
- return ProtoFilter(eq=ProtoEqual(property=self.property, value=atomic_literal))
134
-
135
-
136
- class NotEqual(_UnaryFilter):
137
- """NotEqual operation.
138
-
139
- Usage Example:
140
- ```
141
- filter = NotEqual(property="age", value=30)
142
- ```
143
- """
144
-
145
- def _to_proto(self):
146
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
147
- return ProtoFilter(
148
- ne=ProtoNotEqual(property=self.property, value=atomic_literal)
149
- )
150
-
151
-
152
- class LessThanEqual(_UnaryFilter):
153
- """LessThanEqual operation.
154
-
155
- Usage Example:
156
- ```
157
- filter = LessThanEqual(property="age", value=30)
158
- ```
159
- """
160
-
161
- def _to_proto(self):
162
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
163
- return ProtoFilter(
164
- lte=ProtoLessThanEqual(property=self.property, value=atomic_literal)
165
- )
166
-
167
-
168
- class LessThan(_UnaryFilter):
169
- """LessThan operation.
170
-
171
- Usage Example:
172
- ```
173
- filter = LessThan(property="age", value=30)
174
- ```
175
- """
176
-
177
- def _to_proto(self):
178
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
179
- return ProtoFilter(
180
- lt=ProtoLessThan(property=self.property, value=atomic_literal)
181
- )
182
-
183
-
184
- class GreaterThanEqual(_UnaryFilter):
185
- """GreaterThanEqual operation.
186
-
187
- Usage Example:
188
- ```
189
- filter = GreaterThanEqual(property="age", value=30)
190
- ```
191
- """
192
-
193
- def _to_proto(self):
194
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
195
- return ProtoFilter(
196
- gte=ProtoGreaterThanEqual(property=self.property, value=atomic_literal)
197
- )
198
-
199
-
200
- class GreaterThan(_UnaryFilter):
201
- """GreaterThan operation.
202
-
203
- Usage Example:
204
- ```
205
- filter = GreaterThan(property="age", value=30)
206
- ```
207
- """
208
-
209
- def _to_proto(self):
210
- atomic_literal: ProtoAtomicLiteral = transform(value=self.value)
211
- return ProtoFilter(
212
- gt=ProtoGreaterThan(property=self.property, value=atomic_literal)
213
- )
214
-
215
-
216
- @dataclass
217
- class Like(Filter):
218
- """Like operation.
219
-
220
- Usage Example:
221
- ```
222
- filter = Like(property="name", pattern="Tal")
223
- ```
224
- """
225
-
226
- property: str
227
- pattern: str
228
-
229
- def _to_proto(self):
230
- return ProtoFilter(like=ProtoLike(property=self.property, pattern=self.pattern))
231
-
232
-
233
- @dataclass
234
- class IsNull(Filter):
235
- """IsNull operation.
236
-
237
- Usage Example:
238
- ```
239
- filter = IsNull(property="zipcode)
240
- ```
241
- """
242
-
243
- property: str
244
-
245
- def _to_proto(self):
246
- return ProtoFilter(is_null=ProtoIsNull(property=self.property))
247
-
248
-
249
- @dataclass
250
- class IsNotNull(Filter):
251
- """IsNotNull operation.
252
-
253
- Usage Example:
254
- ```
255
- filter = IsNotNull(property="zipcode)
256
- ```
257
- """
258
-
259
- property: str
260
-
261
- def _to_proto(self):
262
- return ProtoFilter(is_not_null=ProtoIsNotNull(property=self.property))
263
-
264
-
265
- @dataclass
266
- class Property:
267
- """Represents a property for building filter conditions."""
268
-
269
- name: str
270
-
271
- def gt(self, value: Any):
272
- """Create a GreaterThan filter for this property.
273
-
274
- Usage Example:
275
- ```
276
- filter = Property("age").gt(30)
277
- ```
278
- """
279
- return GreaterThan(self.name, value)
280
-
281
- def gte(self, value: Any):
282
- """Create a GreaterThanEqual filter for this property.
283
-
284
- Usage Example:
285
- ```
286
- filter = Property("score").gte(90)
287
- ```
288
- """
289
- return GreaterThanEqual(self.name, value)
290
-
291
- def lt(self, value: Any):
292
- """Create a LessThan filter for this property.
293
-
294
- Usage Example:
295
- ```
296
- filter = Property("age").lt(30)
297
- ```
298
- """
299
- return LessThan(self.name, value)
300
-
301
- def lte(self, value: Any):
302
- """Create a LessThanEqual filter for this property.
303
-
304
- Usage Example:
305
- ```
306
- filter = Property("score").lte(90)
307
- ```
308
- """
309
- return LessThanEqual(self.name, value)
310
-
311
- def eq(self, value: Any):
312
- """Create an Equal filter for this property.
313
-
314
- Usage Example:
315
- ```
316
- filter = Property("score").eq(90)
317
- ```
318
- """
319
- return Equal(self.name, value)
320
-
321
- def ne(self, value: Any):
322
- """Create an NotEqual filter for this property.
323
-
324
- Usage Example:
325
- ```
326
- filter = Property("age").ne(30)
327
- ```
328
- """
329
- return NotEqual(self.name, value)
330
-
331
- def is_null(self):
332
- """Create an IsNull filter for this property.
333
-
334
- Usage Example:
335
- ```
336
- filter = Property("zipcode").is_null()
337
- ```
338
- """
339
- return IsNull(self.name)
340
-
341
- def is_not_null(self):
342
- """Create an IsNotNull filter for this property.
343
-
344
- Usage Example:
345
- ```
346
- filter = Property("zipcode").is_not_null()
347
- ```
348
- """
349
- return IsNotNull(self.name)
350
-
351
- def like(self, pattern: str):
352
- """Create a Like filter for this property.
353
-
354
- Usage Example:
355
- ```
356
- filter = Property("name").like("Tal")
357
- ```
358
- """
359
- return Like(self.name, pattern)
@@ -1,105 +0,0 @@
1
- import json
2
-
3
- from frogml_core.clients.administration.eco_system.client import EcosystemClient
4
- from frogml_core.exceptions import FrogmlException, FrogmlHTTPException
5
- from frogml_core.vector_store.rest_helpers import RestSession
6
-
7
-
8
- class VectorStoreInferenceClient:
9
- def __init__(
10
- self,
11
- model_id: str,
12
- ):
13
- """
14
- :param model_id: The model id to invoke against.
15
- """
16
-
17
- self.r_session = RestSession()
18
- self.ecosystem_client = EcosystemClient()
19
-
20
- authenticated_user_context = (
21
- self.ecosystem_client.get_authenticated_user_context()
22
- )
23
- account_details = authenticated_user_context.user.account_details
24
- default_environment_id = account_details.default_environment_id
25
- model_url_prefix = account_details.environment_by_id[
26
- default_environment_id
27
- ].configuration.model_api_url
28
-
29
- self.model_id = model_id
30
- self.content_type = "application/json; format=pandas-split"
31
- self.model_api = _get_model_url(
32
- model_id=model_id, model_url_prefix=model_url_prefix
33
- )
34
-
35
- def predict(
36
- self,
37
- feature_vectors,
38
- ):
39
- """
40
- Perform a prediction request against a Qwak based model
41
-
42
- :param feature_vectors: A list of feature vectors to predict against. Each feature vector is modeled as a python
43
- dictionary
44
- :return: Prediction response from the model
45
- """
46
-
47
- if feature_vectors.__class__.__name__ == "DataFrame":
48
- feature_vectors = feature_vectors.to_json(orient="split")
49
-
50
- if isinstance(feature_vectors, dict) or isinstance(feature_vectors, list):
51
- feature_vectors = json.dumps(feature_vectors)
52
-
53
- try:
54
- response = self.r_session.post(
55
- self.model_api, data=feature_vectors, headers={}
56
- )
57
-
58
- if response.status_code >= 400:
59
- exception_class_name = response.headers.get("X-Exception-Class")
60
- msg = f"{response.status_code}: {response.text}"
61
- raise FrogmlHTTPException(
62
- response.status_code, msg, exception_class_name
63
- )
64
-
65
- elif response.status_code != 200:
66
- raise FrogmlHTTPException(response.status_code, response.content)
67
-
68
- dict_response = json.loads(response.content)
69
- return dict_response
70
- except FrogmlHTTPException as e:
71
- raise e
72
- except Exception as e:
73
- raise RuntimeError(f"Failed to make a prediction request. Error is: {e}")
74
-
75
- def get_embedding(self, natural_input: str):
76
- feature_vector = [
77
- {
78
- "input": natural_input,
79
- }
80
- ]
81
- try:
82
- result_list = self.predict(feature_vector)
83
- except Exception as e:
84
- raise FrogmlException(
85
- f"Vectorizer {self.model_id} failed to transform input {feature_vector} to vectors. Error is: {str(e)}"
86
- )
87
- try:
88
- vector = result_list[0]["embeddings"]
89
- except Exception:
90
- raise FrogmlException(
91
- f"Vectorizer {self.model_id} must return a dataframe containing an 'embeddings' column"
92
- )
93
- if not vector:
94
- raise FrogmlException(
95
- f"Vectorizer {self.model_id} did not return embeddings for the given natural input. Unable to continue with the query."
96
- )
97
- return vector
98
-
99
-
100
- def _get_model_url(model_id: str, model_url_prefix: str) -> str:
101
- scheme = "http" if model_url_prefix.startswith("localhost") else "https"
102
- effective_model_id = model_id.replace("-", "_")
103
- return (
104
- f"{scheme}://{model_url_prefix}/v1/{effective_model_id}/predict" # noqa: E231
105
- )
@@ -1,81 +0,0 @@
1
- import base64
2
- import json
3
- import socket
4
- from datetime import datetime
5
-
6
- import requests
7
-
8
- from frogml_core.clients.administration import AuthenticationClient
9
- from frogml_core.inner.di_configuration.account import UserAccountConfiguration
10
-
11
-
12
- def _get_authorization():
13
- user_account_configuration = UserAccountConfiguration()
14
- token = (
15
- AuthenticationClient()
16
- .authenticate(user_account_configuration.get_user_token())
17
- .access_token
18
- )
19
- token_split = token.split(".")
20
- decoded_token = json.loads(_base64url_decode(token_split[1]).decode("utf-8"))
21
- token_expiration = datetime.fromtimestamp(decoded_token["exp"])
22
-
23
- return f"Bearer {token}", token_expiration
24
-
25
-
26
- def _base64url_decode(input):
27
- rem = len(input) % 4
28
- if rem > 0:
29
- input += "=" * (4 - rem)
30
-
31
- return base64.urlsafe_b64decode(input)
32
-
33
-
34
- class SocketAdapter(requests.adapters.HTTPAdapter):
35
- def __init__(self, *args, socket_params=None, **kwargs):
36
- self.socket_params = socket_params
37
- super().__init__(*args, **kwargs)
38
-
39
- def init_poolmanager(self, *args, **kwargs):
40
- if self.socket_params:
41
- kwargs["socket_options"] = self.socket_params
42
- super().init_poolmanager(*args, **kwargs)
43
-
44
-
45
- # Configure only TCP attributes that are available in the OS
46
- def validate_socket_config(socket_options):
47
- config = []
48
- for line in socket_options:
49
- if hasattr(socket, line[0]) and hasattr(socket, line[1]):
50
- config.append((getattr(socket, line[0]), getattr(socket, line[1]), line[2]))
51
- return config
52
-
53
-
54
- class RestSession(requests.Session):
55
- def __init__(self):
56
- super().__init__()
57
- self.headers.update({"Content-Type": "application/json"})
58
- socket_options = [
59
- ("SOL_SOCKET", "SO_KEEPALIVE", 1),
60
- ("SOL_TCP", "TCP_KEEPIDLE", 120),
61
- ("SOL_TCP", "TCP_KEEPINTVL", 75),
62
- ("SOL_TCP", "TCP_KEEPCNT", 9),
63
- ]
64
- socket_options = validate_socket_config(socket_options)
65
- adapter = SocketAdapter(socket_params=socket_options)
66
- self.mount("https://", adapter)
67
-
68
- def prepare_request(self, request):
69
- if "Authorization" not in self.headers:
70
- self.prepare_request_token()
71
- else:
72
- if self.jwt_expiration <= datetime.utcnow():
73
- self.prepare_request_token()
74
-
75
- return super().prepare_request(request)
76
-
77
- def prepare_request_token(self):
78
- (
79
- self.headers["Authorization"],
80
- self.jwt_expiration,
81
- ) = _get_authorization()
File without changes
@@ -1,23 +0,0 @@
1
- from datetime import datetime
2
- from typing import Any
3
-
4
- from frogml_proto.qwak.vectors.v1.filters_pb2 import (
5
- AtomicLiteral as ProtoAtomicLiteral,
6
- )
7
- from frogml_core.utils.datetime_utils import datetime_to_pts
8
-
9
-
10
- def transform(value: Any) -> ProtoAtomicLiteral:
11
- if isinstance(value, bool):
12
- return ProtoAtomicLiteral(bool_literal=value)
13
- elif isinstance(value, str):
14
- return ProtoAtomicLiteral(string_literal=value)
15
- elif isinstance(value, int):
16
- return ProtoAtomicLiteral(int_literal=value)
17
- elif isinstance(value, float):
18
- return ProtoAtomicLiteral(double_literal=value)
19
- elif isinstance(value, datetime):
20
- # Assuming that timestamp is a datetime
21
- return ProtoAtomicLiteral(timestamp_literal=datetime_to_pts(value))
22
- else:
23
- raise ValueError(f"Unsupported data type: {type(value)}")