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,157 +0,0 @@
1
- from typing import List, Optional
2
-
3
- import grpc
4
- from typeguard import typechecked
5
-
6
- from frogml_proto.qwak.vectors.v1.filters_pb2 import Filter as ProtoFilter
7
- from frogml_proto.qwak.vectors.v1.vector_pb2 import (
8
- DoubleVector,
9
- SearchResult,
10
- StoredVector,
11
- VectorIdentifier,
12
- )
13
- from frogml_proto.qwak.vectors.v1.vector_service_pb2 import (
14
- DeleteVectorsRequest,
15
- FetchVectorRequest,
16
- SearchSimilarVectorsRequest,
17
- UpsertVectorsRequest,
18
- )
19
- from frogml_proto.qwak.vectors.v1.vector_service_pb2_grpc import VectorServiceStub
20
- from frogml_core.clients._inner.edge_communications import get_endpoint_url
21
- from frogml_core.exceptions import FrogmlException, FrogmlNotFoundException
22
- from frogml_core.inner.tool.grpc.grpc_tools import create_grpc_channel
23
-
24
-
25
- class VectorServingClient:
26
- def __init__(
27
- self,
28
- edge_services_url: Optional[str] = None,
29
- environment_id: Optional[str] = None,
30
- ):
31
- edge_services_url = get_endpoint_url(edge_services_url, environment_id)
32
- self._edge_services_url = edge_services_url
33
-
34
- grpc_channel = create_grpc_channel(
35
- url=edge_services_url,
36
- enable_ssl=False if edge_services_url.startswith("localhost") else True,
37
- status_for_retry=(
38
- grpc.StatusCode.UNAVAILABLE,
39
- grpc.StatusCode.DEADLINE_EXCEEDED,
40
- grpc.StatusCode.INTERNAL,
41
- ),
42
- backoff_options={"init_backoff_ms": 250},
43
- )
44
-
45
- self._vector_serving_service = VectorServiceStub(grpc_channel)
46
-
47
- @typechecked
48
- def search(
49
- self,
50
- collection_name: str,
51
- vector: List[float],
52
- properties: List[str],
53
- top_results: int = 1,
54
- include_id: bool = True,
55
- include_vector: bool = False,
56
- include_distance: bool = False,
57
- filters: Optional[ProtoFilter] = None,
58
- tenant_id: Optional[str] = None,
59
- ) -> List[SearchResult]:
60
- """
61
- Search for similar vectors
62
- """
63
- request: SearchSimilarVectorsRequest
64
- if tenant_id is not None:
65
- request = SearchSimilarVectorsRequest(
66
- collection_name=collection_name,
67
- reference_vector=DoubleVector(element=vector),
68
- properties=properties,
69
- max_results=top_results,
70
- filter=filters,
71
- include_id=include_id,
72
- include_vector=include_vector,
73
- include_distance=include_distance,
74
- tenant_id=tenant_id,
75
- )
76
- else:
77
- request = SearchSimilarVectorsRequest(
78
- collection_name=collection_name,
79
- reference_vector=DoubleVector(element=vector),
80
- properties=properties,
81
- max_results=top_results,
82
- filter=filters,
83
- include_id=include_id,
84
- include_vector=include_vector,
85
- include_distance=include_distance,
86
- )
87
-
88
- try:
89
- return list(
90
- self._vector_serving_service.SearchSimilarVectors(
91
- request
92
- ).search_results
93
- )
94
-
95
- except grpc.RpcError as e:
96
- raise FrogmlException(
97
- f"Failed to query collection '{collection_name}' for vector '{str(vector)}': {repr(e)}"
98
- )
99
-
100
- @typechecked
101
- def upsert_vectors(self, collection_name: str, vectors: List[StoredVector]) -> None:
102
- """
103
- Upsert vectors to a collection
104
- """
105
- try:
106
- self._vector_serving_service.UpsertVectors(
107
- UpsertVectorsRequest(
108
- collection_name=collection_name,
109
- vector=vectors,
110
- )
111
- )
112
-
113
- except grpc.RpcError as e:
114
- raise FrogmlException(f"Failed to upsert, got: {repr(e)}")
115
-
116
- @typechecked
117
- def delete_vectors(
118
- self, collection_name: str, vector_identifiers: List[VectorIdentifier]
119
- ) -> int:
120
- """
121
- Delete vectors from a collection
122
- """
123
- try:
124
- return self._vector_serving_service.DeleteVectors(
125
- DeleteVectorsRequest(
126
- collection_name=collection_name,
127
- vector_identifiers=vector_identifiers,
128
- )
129
- ).num_vectors_deleted
130
-
131
- except grpc.RpcError as e:
132
- raise FrogmlException(
133
- f"Failed to delete vectors by id '{str(vector_identifiers)}': {repr(e)}"
134
- )
135
-
136
- @typechecked
137
- def fetch_vector(
138
- self, collection_name: str, vector_identifier: VectorIdentifier
139
- ) -> StoredVector:
140
- """
141
- Fetch a vector from a collection
142
- """
143
- try:
144
- return self._vector_serving_service.FetchVector(
145
- FetchVectorRequest(
146
- collection_name=collection_name, vector_identifier=vector_identifier
147
- )
148
- ).vector
149
-
150
- except grpc.RpcError as e:
151
- if e.args[0].code.name == "NOT_FOUND":
152
- raise FrogmlNotFoundException(
153
- f"Could not find vector {repr(vector_identifier)} in collection {collection_name}"
154
- )
155
- raise FrogmlException(
156
- f"Failed to get vector by ID '{vector_identifier}': {repr(e)}"
157
- )
@@ -1 +0,0 @@
1
- from .client import WorkspaceManagerClient
@@ -1,224 +0,0 @@
1
- import grpc
2
- from dependency_injector.wiring import Provide
3
-
4
- from frogml_proto.qwak.user_application.common.v0.resources_pb2 import (
5
- ClientPodComputeResources,
6
- PodComputeResourceTemplateSpec,
7
- )
8
- from frogml_proto.qwak.workspace.workspace_pb2 import (
9
- DefaultWorkspaceDetails,
10
- WorkspaceSpec,
11
- )
12
- from frogml_proto.qwak.workspace.workspace_service_pb2 import (
13
- CreateWorkspaceRequest,
14
- CreateWorkspaceResponse,
15
- DeleteWorkspaceRequest,
16
- DeployWorkspaceRequest,
17
- DeployWorkspaceResponse,
18
- GetDefaultWorkspaceValuesRequest,
19
- GetWorkspaceByIdRequest,
20
- GetWorkspaceByIdResponse,
21
- ListWorkspaceImagesRequest,
22
- ListWorkspaceImagesResponse,
23
- ListWorkspacesRequest,
24
- ListWorkspacesResponse,
25
- MarkBuildAsCopiedRequest,
26
- UndeployWorkspaceRequest,
27
- UpdateWorkspaceRequest,
28
- )
29
- from frogml_proto.qwak.workspace.workspace_service_pb2_grpc import (
30
- WorkspaceManagementServiceStub,
31
- )
32
- from frogml_core.exceptions import FrogmlException
33
- from frogml_core.inner.di_configuration import FrogmlContainer
34
-
35
-
36
- class WorkspaceManagerClient:
37
- """
38
- Used for interacting with Workspace Manager endpoints
39
- """
40
-
41
- def __init__(self, grpc_channel=Provide[FrogmlContainer.core_grpc_channel]):
42
- self._workspace_manager = WorkspaceManagementServiceStub(grpc_channel)
43
-
44
- def create_workspace(
45
- self, workspace_name: str, image_id: str, template_id: str
46
- ) -> CreateWorkspaceResponse:
47
- """
48
- Args:
49
- workspace_name: The name of the workspace
50
- image_id: The image id of the workspace deployment
51
- template_id: The id of the template to use for the workspace deployment
52
-
53
- Returns:
54
- The response of the created workspace
55
- """
56
- try:
57
- create_workspace_request = CreateWorkspaceRequest(
58
- workspace_spec=WorkspaceSpec(
59
- workspace_name=workspace_name,
60
- image_id=image_id,
61
- client_pod_compute_resources=ClientPodComputeResources(
62
- template_spec=PodComputeResourceTemplateSpec(
63
- template_id=template_id
64
- )
65
- ),
66
- )
67
- )
68
- return self._workspace_manager.CreateWorkspace(create_workspace_request)
69
- except grpc.RpcError as e:
70
- raise FrogmlException(
71
- f"Failed to create workspace, code: {e.code().name} error is {e.details()}"
72
- )
73
-
74
- def update_workspace(
75
- self,
76
- workspace_id: str,
77
- workspace_name: str = "",
78
- image_id: str = "",
79
- template_id: str = "",
80
- ) -> CreateWorkspaceResponse:
81
- """
82
- Args:
83
- workspace_id: The id of the workspace
84
- workspace_name: The name of the workspace
85
- image_id: The image id of the workspace deployment
86
- template_id: The id of the template to use for the workspace deployment
87
- Returns:
88
- The response of the updated workspace
89
- """
90
- try:
91
- update_workspace_request = UpdateWorkspaceRequest(
92
- workspace_id=workspace_id,
93
- workspace_spec=WorkspaceSpec(
94
- workspace_name=workspace_name,
95
- image_id=image_id,
96
- client_pod_compute_resources=ClientPodComputeResources(
97
- template_spec=PodComputeResourceTemplateSpec(
98
- template_id=template_id
99
- )
100
- ),
101
- ),
102
- )
103
- return self._workspace_manager.UpdateWorkspace(update_workspace_request)
104
- except grpc.RpcError as e:
105
- raise FrogmlException(
106
- f"Failed to update workspace, code: {e.code().name} error is {e.details()}"
107
- )
108
-
109
- def deploy_workspace(self, workspace_id: str) -> DeployWorkspaceResponse:
110
- """
111
- Args:
112
- workspace_id: The id of the workspace
113
- Returns:
114
- The response of the deployed workspace
115
- """
116
- try:
117
- deploy_workspace_request = DeployWorkspaceRequest(workspace_id=workspace_id)
118
- return self._workspace_manager.DeployWorkspace(deploy_workspace_request)
119
- except grpc.RpcError as e:
120
- raise FrogmlException(
121
- f"Failed to deploy workspace, code: {e.code().name} error is {e.details()}"
122
- )
123
-
124
- def get_workspaces(self) -> ListWorkspacesResponse:
125
- """
126
- Returns:
127
- The response of the list workspaces
128
- """
129
- try:
130
- return self._workspace_manager.ListWorkspaces(ListWorkspacesRequest())
131
- except grpc.RpcError as e:
132
- raise FrogmlException(
133
- f"Failed to list workspaces, code: {e.code().name} error is {e.details()}"
134
- )
135
-
136
- def get_workspace_by_id(self, workspace_id: str) -> GetWorkspaceByIdResponse:
137
- """
138
- Args:
139
- workspace_id: The id of the workspace
140
- Returns:
141
- The response of the workspace
142
- """
143
- try:
144
- return self._workspace_manager.GetWorkspaceById(
145
- GetWorkspaceByIdRequest(workspace_id=workspace_id)
146
- )
147
- except grpc.RpcError as e:
148
- raise FrogmlException(
149
- f"Failed to get workspace by id, code: {e.code().name} error is {e.details()}"
150
- )
151
-
152
- def delete_workspace(self, workspace_id: str) -> DeployWorkspaceResponse:
153
- """
154
- Args:
155
- workspace_id: The id of the workspace
156
- Returns:
157
- The response of the deleted workspace
158
- """
159
- try:
160
- delete_workspace_request = DeleteWorkspaceRequest(workspace_id=workspace_id)
161
- return self._workspace_manager.DeleteWorkspace(delete_workspace_request)
162
- except grpc.RpcError as e:
163
- raise FrogmlException(
164
- f"Failed to delete workspace, code: {e.code().name} error is {e.details()}"
165
- )
166
-
167
- def undeploy_workspace(self, workspace_id: str) -> DeployWorkspaceResponse:
168
- """
169
- Args:
170
- workspace_id: The id of the workspace
171
- Returns:
172
- The response of the undeployed workspace
173
- """
174
- try:
175
- undeploy_workspace_request = UndeployWorkspaceRequest(
176
- workspace_id=workspace_id
177
- )
178
- return self._workspace_manager.UndeployWorkspace(undeploy_workspace_request)
179
- except grpc.RpcError as e:
180
- raise FrogmlException(
181
- f"Failed to undeploy workspace, code: {e.code().name} error is {e.details()}"
182
- )
183
-
184
- def get_workspace_images(self) -> ListWorkspaceImagesResponse:
185
- """
186
- Returns:
187
- The response of the list workspace image
188
- """
189
- try:
190
- return self._workspace_manager.ListWorkspaceImages(
191
- ListWorkspaceImagesRequest()
192
- )
193
- except grpc.RpcError as e:
194
- raise FrogmlException(
195
- f"Failed to list workspace image types, code: {e.code().name} error is {e.details()}"
196
- )
197
-
198
- def get_default_workspace_details(self) -> DefaultWorkspaceDetails:
199
- """
200
- Returns:
201
- The default values to complete in case of missing values
202
- """
203
- try:
204
- return self._workspace_manager.GetDefaultWorkspaceValues(
205
- GetDefaultWorkspaceValuesRequest()
206
- ).default_workspace_details
207
- except grpc.RpcError as e:
208
- raise FrogmlException(
209
- f"Failed to get default workspace values, code: {e.code().name} error is {e.details()}"
210
- )
211
-
212
- def _mark_build_as_copied(self, workspace_id: str, build_id: str) -> None:
213
- """
214
- Mark build as copied
215
- """
216
- try:
217
- self._workspace_manager.MarkBuildAsCopied(
218
- MarkBuildAsCopiedRequest(
219
- workspace_id=workspace_id,
220
- build_id=build_id,
221
- )
222
- )
223
- except grpc.RpcError as e:
224
- raise FrogmlException(f"Failed to mark build as copied, got: {e.details()}")
File without changes
File without changes
@@ -1,78 +0,0 @@
1
- import json
2
- from typing import Iterator, Type, TypeVar
3
-
4
- import requests
5
- from dacite import Config, from_dict
6
-
7
- from frogml_core.exceptions.frogml_decode_exception import FrogmlDecodeException
8
- from frogml_core.exceptions.frogml_external_exception import FrogmlExternalException
9
- from frogml_core.llmops.generation.streaming import Stream
10
-
11
- _SSEvent = TypeVar("_SSEvent")
12
-
13
-
14
- class BaseSSEDecoder(Stream[_SSEvent]):
15
- _response: requests.Response
16
- _iterator: Iterator[_SSEvent]
17
-
18
- def __init__(self, response: requests.Response, parse_to: Type[_SSEvent]):
19
- if response.encoding is None:
20
- response.encoding = "utf-8"
21
-
22
- self._parse_to = parse_to
23
-
24
- self._response = response
25
- self._iterator = self.__decode(response=response)
26
-
27
- def _is_chunk_empty(self, chunk: str) -> bool:
28
- return not chunk or chunk == "" or chunk.startswith(":") or chunk == ":"
29
-
30
- def _raise_on_chunk_error(self, chunk: str):
31
- is_error: bool = False
32
- try:
33
- maybe_error = json.loads(chunk)
34
- if "error" in maybe_error:
35
- is_error = True
36
- except Exception: # nosec
37
- pass
38
-
39
- if chunk.strip().startswith("error"):
40
- is_error = True
41
-
42
- if is_error:
43
- raise FrogmlExternalException(message=chunk)
44
-
45
- def __decode(self, response: requests.Response) -> Iterator[_SSEvent]:
46
- chunk: str
47
- for chunk in response.iter_lines(chunk_size=None, decode_unicode=True):
48
- if self._is_chunk_empty(chunk=chunk):
49
- continue
50
-
51
- self._raise_on_chunk_error(chunk=chunk)
52
-
53
- try:
54
- if chunk.strip().startswith("[DONE]"):
55
- break
56
-
57
- _, _, content = chunk.partition(":")
58
-
59
- if content.strip().startswith("[DONE]"):
60
- break
61
-
62
- yield self._parse_event(event=content)
63
- except Exception as e:
64
- raise FrogmlDecodeException(f"Failed to decode event: {chunk}") from e
65
-
66
- def __iter__(self) -> Iterator[_SSEvent]:
67
- for chunk in self._iterator:
68
- yield chunk
69
-
70
- def __next__(self) -> _SSEvent:
71
- return self._iterator.__next__()
72
-
73
- def _parse_event(self, event: str) -> _SSEvent:
74
- return from_dict(
75
- data_class=self._parse_to,
76
- data=json.loads(event),
77
- config=Config(check_types=False),
78
- )
@@ -1,5 +0,0 @@
1
- from abc import ABC
2
-
3
-
4
- class ModelResponse(ABC):
5
- pass
File without changes
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2024 OpenAI
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.