frogml-core 0.0.113__py3-none-any.whl → 0.0.115__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.
- frogml_core/__init__.py +1 -1
- frogml_core/clients/administration/authentication/client.py +2 -2
- frogml_core/clients/batch_job_management/client.py +4 -4
- frogml_core/clients/build_orchestrator/build_model_request_getter.py +6 -6
- frogml_core/clients/build_orchestrator/client.py +12 -12
- frogml_core/clients/build_orchestrator/internal_client.py +10 -10
- frogml_core/frogml_client/build_api_helpers/build_api_steps.py +3 -3
- frogml_core/inner/build_logic/constants/upload_tag.py +7 -7
- frogml_core/inner/build_logic/interface/context_interface.py +1 -1
- frogml_core/inner/build_logic/phases/phase_010_fetch_model/fetch_strategy_manager/strategy/strategy.py +4 -4
- frogml_core/inner/build_logic/phases/phase_010_fetch_model/set_version_step.py +3 -3
- frogml_core/inner/build_logic/phases/phase_020_remote_register_frogml_build/start_remote_build_step.py +3 -3
- frogml_core/inner/build_logic/phases/phase_020_remote_register_frogml_build/upload_step.py +11 -9
- frogml_core/inner/build_logic/tools/ignore_files.py +3 -3
- frogml_core/inner/di_configuration/__init__.py +0 -6
- frogml_core/model/adapters/__init__.py +1 -1
- frogml_core/model/analytics_logging.py +1 -1
- frogml_core/model/tools/adapters/input.py +6 -6
- frogml_core/model/tools/adapters/output.py +8 -8
- frogml_core/model/tools/run_model_locally.py +2 -2
- frogml_core/model/utils/feature_utils.py +1 -1
- {frogml_core-0.0.113.dist-info → frogml_core-0.0.115.dist-info}/METADATA +1 -1
- {frogml_core-0.0.113.dist-info → frogml_core-0.0.115.dist-info}/RECORD +30 -137
- frogml_services_mock/mocks/analytics_api.py +6 -6
- frogml_services_mock/mocks/ecosystem_service_api.py +2 -2
- frogml_services_mock/mocks/frogml_mocks.py +0 -11
- frogml_services_mock/services_mock.py +4 -52
- frogml_storage/__init__.py +1 -1
- frogml_core/clients/prompt_manager/__init__.py +0 -0
- frogml_core/clients/prompt_manager/model_descriptor_mapper.py +0 -196
- frogml_core/clients/prompt_manager/prompt_manager_client.py +0 -190
- frogml_core/clients/prompt_manager/prompt_proto_mapper.py +0 -264
- frogml_core/clients/vector_store/__init__.py +0 -2
- frogml_core/clients/vector_store/management_client.py +0 -127
- frogml_core/clients/vector_store/serving_client.py +0 -157
- frogml_core/clients/workspace_manager/__init__.py +0 -1
- frogml_core/clients/workspace_manager/client.py +0 -224
- frogml_core/llmops/__init__.py +0 -0
- frogml_core/llmops/generation/__init__.py +0 -0
- frogml_core/llmops/generation/_steaming.py +0 -78
- frogml_core/llmops/generation/base.py +0 -5
- frogml_core/llmops/generation/chat/__init__.py +0 -0
- frogml_core/llmops/generation/chat/openai/LICENSE.txt +0 -201
- frogml_core/llmops/generation/chat/openai/types/__init__.py +0 -0
- frogml_core/llmops/generation/chat/openai/types/chat/__init__.py +0 -0
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion.py +0 -88
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_assistant_message_param.py +0 -65
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_chunk.py +0 -153
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_content_part_text_param.py +0 -28
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_function_call_option_param.py +0 -25
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_function_message_param.py +0 -33
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message.py +0 -56
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_param.py +0 -34
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_tool_call.py +0 -46
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_message_tool_call_param.py +0 -44
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_named_tool_choice_param.py +0 -32
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_role.py +0 -20
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_system_message_param.py +0 -35
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_token_logprob.py +0 -71
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_choice_option_param.py +0 -28
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_message_param.py +0 -31
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_tool_param.py +0 -29
- frogml_core/llmops/generation/chat/openai/types/chat/chat_completion_user_message_param.py +0 -35
- frogml_core/llmops/generation/chat/openai/types/chat/completion_create_params.py +0 -279
- frogml_core/llmops/generation/chat/openai/types/completion_choice.py +0 -47
- frogml_core/llmops/generation/chat/openai/types/completion_create_params.py +0 -209
- frogml_core/llmops/generation/chat/openai/types/completion_usage.py +0 -30
- frogml_core/llmops/generation/chat/openai/types/model.py +0 -35
- frogml_core/llmops/generation/chat/openai/types/shared/__init__.py +0 -3
- frogml_core/llmops/generation/chat/openai/types/shared/error_object.py +0 -27
- frogml_core/llmops/generation/chat/openai/types/shared/function_definition.py +0 -49
- frogml_core/llmops/generation/chat/openai/types/shared/function_parameters.py +0 -20
- frogml_core/llmops/generation/chat/openai/types/shared_params/__init__.py +0 -2
- frogml_core/llmops/generation/chat/openai/types/shared_params/function_definition.py +0 -49
- frogml_core/llmops/generation/chat/openai/types/shared_params/function_parameters.py +0 -22
- frogml_core/llmops/generation/streaming.py +0 -26
- frogml_core/llmops/model/__init__.py +0 -0
- frogml_core/llmops/model/descriptor.py +0 -40
- frogml_core/llmops/prompt/__init__.py +0 -0
- frogml_core/llmops/prompt/base.py +0 -136
- frogml_core/llmops/prompt/chat/__init__.py +0 -0
- frogml_core/llmops/prompt/chat/message.py +0 -24
- frogml_core/llmops/prompt/chat/template.py +0 -113
- frogml_core/llmops/prompt/chat/value.py +0 -10
- frogml_core/llmops/prompt/manager.py +0 -138
- frogml_core/llmops/prompt/template.py +0 -24
- frogml_core/llmops/prompt/value.py +0 -14
- frogml_core/llmops/provider/__init__.py +0 -0
- frogml_core/llmops/provider/chat.py +0 -44
- frogml_core/llmops/provider/openai/__init__.py +0 -0
- frogml_core/llmops/provider/openai/client.py +0 -126
- frogml_core/llmops/provider/openai/provider.py +0 -93
- frogml_core/vector_store/__init__.py +0 -4
- frogml_core/vector_store/client.py +0 -151
- frogml_core/vector_store/collection.py +0 -429
- frogml_core/vector_store/filters.py +0 -359
- frogml_core/vector_store/inference_client.py +0 -105
- frogml_core/vector_store/rest_helpers.py +0 -81
- frogml_core/vector_store/utils/__init__.py +0 -0
- frogml_core/vector_store/utils/filter_utils.py +0 -23
- frogml_core/vector_store/utils/upsert_utils.py +0 -218
- frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2.py +0 -77
- frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2.pyi +0 -417
- frogml_proto/qwak/prompt/v1/prompt/prompt_manager_service_pb2_grpc.py +0 -441
- frogml_proto/qwak/prompt/v1/prompt/prompt_pb2.py +0 -69
- frogml_proto/qwak/prompt/v1/prompt/prompt_pb2.pyi +0 -415
- frogml_proto/qwak/prompt/v1/prompt/prompt_pb2_grpc.py +0 -4
- frogml_proto/qwak/vectors/v1/collection/collection_pb2.py +0 -46
- frogml_proto/qwak/vectors/v1/collection/collection_pb2.pyi +0 -287
- frogml_proto/qwak/vectors/v1/collection/collection_pb2_grpc.py +0 -4
- frogml_proto/qwak/vectors/v1/collection/collection_service_pb2.py +0 -60
- frogml_proto/qwak/vectors/v1/collection/collection_service_pb2.pyi +0 -258
- frogml_proto/qwak/vectors/v1/collection/collection_service_pb2_grpc.py +0 -304
- frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2.py +0 -28
- frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2.pyi +0 -41
- frogml_proto/qwak/vectors/v1/collection/event/collection_event_pb2_grpc.py +0 -4
- frogml_proto/qwak/vectors/v1/filters_pb2.py +0 -52
- frogml_proto/qwak/vectors/v1/filters_pb2.pyi +0 -297
- frogml_proto/qwak/vectors/v1/filters_pb2_grpc.py +0 -4
- frogml_proto/qwak/vectors/v1/vector_pb2.py +0 -38
- frogml_proto/qwak/vectors/v1/vector_pb2.pyi +0 -142
- frogml_proto/qwak/vectors/v1/vector_pb2_grpc.py +0 -4
- frogml_proto/qwak/vectors/v1/vector_service_pb2.py +0 -53
- frogml_proto/qwak/vectors/v1/vector_service_pb2.pyi +0 -243
- frogml_proto/qwak/vectors/v1/vector_service_pb2_grpc.py +0 -201
- frogml_proto/qwak/workspace/workspace_pb2.py +0 -50
- frogml_proto/qwak/workspace/workspace_pb2.pyi +0 -331
- frogml_proto/qwak/workspace/workspace_pb2_grpc.py +0 -4
- frogml_proto/qwak/workspace/workspace_service_pb2.py +0 -84
- frogml_proto/qwak/workspace/workspace_service_pb2.pyi +0 -393
- frogml_proto/qwak/workspace/workspace_service_pb2_grpc.py +0 -507
- frogml_services_mock/mocks/prompt_manager_service.py +0 -281
- frogml_services_mock/mocks/vector_serving_api.py +0 -159
- frogml_services_mock/mocks/vectors_management_api.py +0 -97
- frogml_services_mock/mocks/workspace_manager_service_mock.py +0 -202
- /frogml_core/model/adapters/output_adapters/{qwak_with_default_fallback.py → frogml_with_default_fallback.py} +0 -0
- {frogml_core-0.0.113.dist-info → frogml_core-0.0.115.dist-info}/WHEEL +0 -0
@@ -1,127 +0,0 @@
|
|
1
|
-
from typing import List, Optional
|
2
|
-
|
3
|
-
import grpc
|
4
|
-
from dependency_injector.wiring import Provide, inject
|
5
|
-
|
6
|
-
from frogml_proto.qwak.vectors.v1.collection.collection_pb2 import (
|
7
|
-
VectorCollection,
|
8
|
-
VectorCollectionMetric,
|
9
|
-
VectorCollectionSpec,
|
10
|
-
VectorCollectionVectorizer,
|
11
|
-
)
|
12
|
-
from frogml_proto.qwak.vectors.v1.collection.collection_service_pb2 import (
|
13
|
-
CreateCollectionRequest,
|
14
|
-
DeleteCollectionByIdRequest,
|
15
|
-
DeleteCollectionByNameRequest,
|
16
|
-
GetCollectionByIdRequest,
|
17
|
-
GetCollectionByNameRequest,
|
18
|
-
ListCollectionsRequest,
|
19
|
-
)
|
20
|
-
from frogml_proto.qwak.vectors.v1.collection.collection_service_pb2_grpc import (
|
21
|
-
VectorCollectionServiceStub,
|
22
|
-
)
|
23
|
-
from frogml_core.exceptions import FrogmlException
|
24
|
-
from frogml_core.inner.di_configuration import FrogmlContainer
|
25
|
-
|
26
|
-
|
27
|
-
class VectorManagementClient:
|
28
|
-
@inject
|
29
|
-
def __init__(self, grpc_channel=Provide[FrogmlContainer.core_grpc_channel]):
|
30
|
-
self._vector_management_service: VectorCollectionServiceStub = (
|
31
|
-
VectorCollectionServiceStub(grpc_channel)
|
32
|
-
)
|
33
|
-
|
34
|
-
def create_collection(
|
35
|
-
self,
|
36
|
-
name: str,
|
37
|
-
dimension: int,
|
38
|
-
description: str = None,
|
39
|
-
metric: VectorCollectionMetric = VectorCollectionMetric.COLLECTION_METRIC_L2_SQUARED,
|
40
|
-
vectorizer: Optional[str] = None,
|
41
|
-
multi_tenant: bool = False,
|
42
|
-
) -> VectorCollection:
|
43
|
-
"""
|
44
|
-
Create a collection
|
45
|
-
"""
|
46
|
-
try:
|
47
|
-
return self._vector_management_service.CreateCollection(
|
48
|
-
CreateCollectionRequest(
|
49
|
-
collection_spec=VectorCollectionSpec(
|
50
|
-
name=name,
|
51
|
-
description=description,
|
52
|
-
vectorizer=VectorCollectionVectorizer(
|
53
|
-
qwak_model_name=vectorizer
|
54
|
-
),
|
55
|
-
metric=metric,
|
56
|
-
dimension=dimension,
|
57
|
-
multi_tenancy_enabled=multi_tenant,
|
58
|
-
)
|
59
|
-
)
|
60
|
-
).vector_collection
|
61
|
-
|
62
|
-
except grpc.RpcError as e:
|
63
|
-
raise FrogmlException(f"Failed to create collection: {e.details()}")
|
64
|
-
|
65
|
-
def list_collections(self) -> List[VectorCollection]:
|
66
|
-
"""
|
67
|
-
List all vector collections
|
68
|
-
"""
|
69
|
-
try:
|
70
|
-
return self._vector_management_service.ListCollections(
|
71
|
-
ListCollectionsRequest()
|
72
|
-
).vector_collections
|
73
|
-
|
74
|
-
except grpc.RpcError as e:
|
75
|
-
raise FrogmlException(f"Failed to list collections: {e.details()}")
|
76
|
-
|
77
|
-
def get_collection_by_name(self, name: str) -> VectorCollection:
|
78
|
-
"""
|
79
|
-
Get vector collection by name
|
80
|
-
"""
|
81
|
-
try:
|
82
|
-
return self._vector_management_service.GetCollectionByName(
|
83
|
-
GetCollectionByNameRequest(name=name)
|
84
|
-
).vector_collection
|
85
|
-
except grpc.RpcError as e:
|
86
|
-
raise FrogmlException(
|
87
|
-
f"Failed to get collection by name '{name}': {e.details()}"
|
88
|
-
)
|
89
|
-
|
90
|
-
def get_collection_by_id(self, id: str) -> VectorCollection:
|
91
|
-
"""
|
92
|
-
Get vector collection by id
|
93
|
-
"""
|
94
|
-
try:
|
95
|
-
return self._vector_management_service.GetCollectionById(
|
96
|
-
GetCollectionByIdRequest(id=id)
|
97
|
-
).vector_collection
|
98
|
-
except grpc.RpcError as e:
|
99
|
-
raise FrogmlException(
|
100
|
-
f"Failed to get collection by id '{id}': {e.details()}"
|
101
|
-
)
|
102
|
-
|
103
|
-
def delete_collection_by_id(self, id: str) -> None:
|
104
|
-
"""
|
105
|
-
Delete vector collection by id
|
106
|
-
"""
|
107
|
-
try:
|
108
|
-
self._vector_management_service.DeleteCollectionById(
|
109
|
-
DeleteCollectionByIdRequest(id=id)
|
110
|
-
)
|
111
|
-
except grpc.RpcError as e:
|
112
|
-
raise FrogmlException(
|
113
|
-
f"Failed to delete collection by id '{id}': {e.details()}"
|
114
|
-
)
|
115
|
-
|
116
|
-
def delete_collection_by_name(self, name: str) -> None:
|
117
|
-
"""
|
118
|
-
Delete vector collection by id
|
119
|
-
"""
|
120
|
-
try:
|
121
|
-
self._vector_management_service.DeleteCollectionByName(
|
122
|
-
DeleteCollectionByNameRequest(name=name)
|
123
|
-
)
|
124
|
-
except grpc.RpcError as e:
|
125
|
-
raise FrogmlException(
|
126
|
-
f"Failed to delete collection by name '{name}': {e.details()}"
|
127
|
-
)
|
@@ -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()}")
|
frogml_core/llmops/__init__.py
DELETED
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
|
-
)
|
File without changes
|