oracle-ads 2.11.18__py3-none-any.whl → 2.12.0__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 (40) hide show
  1. ads/aqua/common/utils.py +20 -3
  2. ads/aqua/config/__init__.py +4 -0
  3. ads/aqua/config/config.py +28 -0
  4. ads/aqua/config/evaluation/__init__.py +4 -0
  5. ads/aqua/config/evaluation/evaluation_service_config.py +282 -0
  6. ads/aqua/config/evaluation/evaluation_service_model_config.py +8 -0
  7. ads/aqua/config/utils/__init__.py +4 -0
  8. ads/aqua/config/utils/serializer.py +339 -0
  9. ads/aqua/constants.py +1 -1
  10. ads/aqua/evaluation/entities.py +1 -0
  11. ads/aqua/evaluation/evaluation.py +56 -88
  12. ads/aqua/extension/common_handler.py +2 -3
  13. ads/aqua/extension/common_ws_msg_handler.py +2 -2
  14. ads/aqua/extension/evaluation_handler.py +4 -3
  15. ads/aqua/extension/model_handler.py +26 -1
  16. ads/aqua/extension/utils.py +12 -1
  17. ads/aqua/modeldeployment/deployment.py +31 -51
  18. ads/aqua/ui.py +27 -25
  19. ads/llm/__init__.py +10 -4
  20. ads/llm/chat_template.py +31 -0
  21. ads/llm/guardrails/base.py +3 -2
  22. ads/llm/guardrails/huggingface.py +1 -1
  23. ads/llm/langchain/plugins/chat_models/__init__.py +5 -0
  24. ads/llm/langchain/plugins/chat_models/oci_data_science.py +924 -0
  25. ads/llm/langchain/plugins/llms/__init__.py +5 -0
  26. ads/llm/langchain/plugins/llms/oci_data_science_model_deployment_endpoint.py +939 -0
  27. ads/llm/requirements.txt +2 -2
  28. ads/llm/serialize.py +3 -6
  29. ads/llm/templates/tool_chat_template_hermes.jinja +130 -0
  30. ads/llm/templates/tool_chat_template_mistral_parallel.jinja +94 -0
  31. {oracle_ads-2.11.18.dist-info → oracle_ads-2.12.0.dist-info}/METADATA +7 -4
  32. {oracle_ads-2.11.18.dist-info → oracle_ads-2.12.0.dist-info}/RECORD +35 -27
  33. ads/llm/langchain/plugins/base.py +0 -118
  34. ads/llm/langchain/plugins/contant.py +0 -44
  35. ads/llm/langchain/plugins/embeddings.py +0 -64
  36. ads/llm/langchain/plugins/llm_gen_ai.py +0 -301
  37. ads/llm/langchain/plugins/llm_md.py +0 -316
  38. {oracle_ads-2.11.18.dist-info → oracle_ads-2.12.0.dist-info}/LICENSE.txt +0 -0
  39. {oracle_ads-2.11.18.dist-info → oracle_ads-2.12.0.dist-info}/WHEEL +0 -0
  40. {oracle_ads-2.11.18.dist-info → oracle_ads-2.12.0.dist-info}/entry_points.txt +0 -0
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
2
  # Copyright (c) 2024 Oracle and/or its affiliates.
4
3
  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
4
  from dataclasses import fields
5
+ from datetime import datetime, timedelta
6
6
  from typing import Dict, Optional
7
7
 
8
+ from cachetools import TTLCache, cached
8
9
  from tornado.web import HTTPError
9
10
 
11
+ from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID
12
+ from ads.aqua.common.utils import fetch_service_compartment
10
13
  from ads.aqua.extension.errors import Errors
11
14
 
12
15
 
@@ -21,3 +24,11 @@ def validate_function_parameters(data_class, input_data: Dict):
21
24
  raise HTTPError(
22
25
  400, Errors.MISSING_REQUIRED_PARAMETER.format(required_parameter)
23
26
  )
27
+
28
+
29
+ @cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=1), timer=datetime.now))
30
+ def ui_compatability_check():
31
+ """This method caches the service compartment OCID details that is set by either the environment variable or if
32
+ fetched from the configuration. The cached result is returned when multiple calls are made in quick succession
33
+ from the UI to avoid multiple config file loads."""
34
+ return ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment()
@@ -146,7 +146,7 @@ class AquaDeploymentApp(AquaApp):
146
146
  env_var : dict, optional
147
147
  Environment variable for the deployment, by default None.
148
148
  container_family: str
149
- The image family of model deployment container runtime. Required for unverified Aqua models.
149
+ The image family of model deployment container runtime.
150
150
  memory_in_gbs: float
151
151
  The memory in gbs for the shape selected.
152
152
  ocpus: float
@@ -230,41 +230,14 @@ class AquaDeploymentApp(AquaApp):
230
230
 
231
231
  env_var.update({"FT_MODEL": f"{fine_tune_output_path}"})
232
232
 
233
- is_custom_container = False
234
- try:
235
- container_type_key = aqua_model.custom_metadata_list.get(
236
- AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME
237
- ).value
238
- except ValueError as err:
239
- message = (
240
- f"{AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME} key is not available in the custom metadata field "
241
- f"for model {aqua_model.id}."
242
- )
243
- logger.debug(message)
244
- if not container_family:
245
- raise AquaValueError(
246
- f"{message}. For unverified Aqua models, container_family parameter should be "
247
- f"set and value can be one of {', '.join(InferenceContainerTypeFamily.values())}."
248
- ) from err
249
- container_type_key = container_family
250
- try:
251
- # Check if the container override flag is set. If set, then the user has chosen custom image
252
- if aqua_model.custom_metadata_list.get(
253
- AQUA_DEPLOYMENT_CONTAINER_OVERRIDE_FLAG_METADATA_NAME
254
- ).value:
255
- is_custom_container = True
256
- except Exception:
257
- pass
233
+ container_type_key = self._get_container_type_key(
234
+ model=aqua_model,
235
+ container_family=container_family
236
+ )
258
237
 
259
238
  # fetch image name from config
260
- # If the image is of type custom, then `container_type_key` is the inference image
261
- container_image = (
262
- get_container_image(
263
- container_type=container_type_key,
264
- )
265
- if not is_custom_container
266
- else container_type_key
267
- )
239
+ container_image = get_container_image(container_type=container_type_key)
240
+
268
241
  logging.info(
269
242
  f"Aqua Image used for deploying {aqua_model.id} : {container_image}"
270
243
  )
@@ -433,6 +406,26 @@ class AquaDeploymentApp(AquaApp):
433
406
  deployment.dsc_model_deployment, self.region
434
407
  )
435
408
 
409
+ @staticmethod
410
+ def _get_container_type_key(model: DataScienceModel, container_family: str) -> str:
411
+ container_type_key = UNKNOWN
412
+ if container_family:
413
+ container_type_key = container_family
414
+ else:
415
+ try:
416
+ container_type_key = model.custom_metadata_list.get(
417
+ AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME
418
+ ).value
419
+ except ValueError as err:
420
+ raise AquaValueError(
421
+ f"{AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME} key is not available in the custom metadata field "
422
+ f"for model {model.id}. For unverified Aqua models, {AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME} should be"
423
+ f"set and value can be one of {', '.join(InferenceContainerTypeFamily.values())}."
424
+ ) from err
425
+
426
+ return container_type_key
427
+
428
+
436
429
  @telemetry(entry_point="plugin=deployment&action=list", name="aqua")
437
430
  def list(self, **kwargs) -> List["AquaDeployment"]:
438
431
  """List Aqua model deployments in a given compartment and under certain project.
@@ -672,23 +665,10 @@ class AquaDeploymentApp(AquaApp):
672
665
  restricted_params = []
673
666
  if params:
674
667
  model = DataScienceModel.from_id(model_id)
675
- try:
676
- container_type_key = model.custom_metadata_list.get(
677
- AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME
678
- ).value
679
- except ValueError as err:
680
- message = (
681
- f"{AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME} key is not available in the custom metadata field "
682
- f"for model {model_id}."
683
- )
684
- logger.debug(message)
685
-
686
- if not container_family:
687
- raise AquaValueError(
688
- f"{message}. For unverified Aqua models, container_family parameter should be "
689
- f"set and value can be one of {', '.join(InferenceContainerTypeFamily.values())}."
690
- ) from err
691
- container_type_key = container_family
668
+ container_type_key = self._get_container_type_key(
669
+ model=model,
670
+ container_family=container_family
671
+ )
692
672
 
693
673
  container_config = get_container_config()
694
674
  container_spec = container_config.get(ContainerSpec.CONTAINER_SPEC, {}).get(
ads/aqua/ui.py CHANGED
@@ -84,9 +84,6 @@ class AquaContainerConfigSpec(DataClassSerializable):
84
84
  health_check_port: str = None
85
85
  env_vars: List[dict] = None
86
86
  restricted_params: List[str] = None
87
- evaluation_configuration: AquaContainerEvaluationConfig = field(
88
- default_factory=AquaContainerEvaluationConfig
89
- )
90
87
 
91
88
 
92
89
  @dataclass(repr=False)
@@ -184,32 +181,37 @@ class AquaContainerConfig(DataClassSerializable):
184
181
  family=container_type,
185
182
  platforms=platforms,
186
183
  model_formats=model_formats,
187
- spec=AquaContainerConfigSpec(
188
- cli_param=container_spec.get(ContainerSpec.CLI_PARM, ""),
189
- server_port=container_spec.get(
190
- ContainerSpec.SERVER_PORT, ""
191
- ),
192
- health_check_port=container_spec.get(
193
- ContainerSpec.HEALTH_CHECK_PORT, ""
194
- ),
195
- env_vars=container_spec.get(ContainerSpec.ENV_VARS, []),
196
- restricted_params=container_spec.get(
197
- ContainerSpec.RESTRICTED_PARAMS, []
198
- ),
199
- evaluation_configuration=AquaContainerEvaluationConfig.from_config(
200
- container_spec.get(
201
- ContainerSpec.EVALUATION_CONFIGURATION, {}
202
- )
203
- ),
204
- )
205
- if container_spec
206
- else None,
184
+ spec=(
185
+ AquaContainerConfigSpec(
186
+ cli_param=container_spec.get(
187
+ ContainerSpec.CLI_PARM, ""
188
+ ),
189
+ server_port=container_spec.get(
190
+ ContainerSpec.SERVER_PORT, ""
191
+ ),
192
+ health_check_port=container_spec.get(
193
+ ContainerSpec.HEALTH_CHECK_PORT, ""
194
+ ),
195
+ env_vars=container_spec.get(ContainerSpec.ENV_VARS, []),
196
+ restricted_params=container_spec.get(
197
+ ContainerSpec.RESTRICTED_PARAMS, []
198
+ ),
199
+ )
200
+ if container_spec
201
+ else None
202
+ ),
207
203
  )
208
204
  if container.get("type") == "inference":
209
205
  inference_items[container_type] = container_item
210
- elif container_type == "odsc-llm-fine-tuning":
206
+ elif (
207
+ container.get("type") == "fine-tune"
208
+ or container_type == "odsc-llm-fine-tuning"
209
+ ):
211
210
  finetune_items[container_type] = container_item
212
- elif container_type == "odsc-llm-evaluate":
211
+ elif (
212
+ container.get("type") == "evaluate"
213
+ or container_type == "odsc-llm-evaluate"
214
+ ):
213
215
  evaluate_items[container_type] = container_item
214
216
 
215
217
  return AquaContainerConfig(
ads/llm/__init__.py CHANGED
@@ -6,10 +6,16 @@
6
6
 
7
7
  try:
8
8
  import langchain
9
- from ads.llm.langchain.plugins.llm_gen_ai import GenerativeAI
10
- from ads.llm.langchain.plugins.llm_md import ModelDeploymentTGI
11
- from ads.llm.langchain.plugins.llm_md import ModelDeploymentVLLM
12
- from ads.llm.langchain.plugins.embeddings import GenerativeAIEmbeddings
9
+ from ads.llm.langchain.plugins.llms.oci_data_science_model_deployment_endpoint import (
10
+ OCIModelDeploymentVLLM,
11
+ OCIModelDeploymentTGI,
12
+ )
13
+ from ads.llm.langchain.plugins.chat_models.oci_data_science import (
14
+ ChatOCIModelDeployment,
15
+ ChatOCIModelDeploymentVLLM,
16
+ ChatOCIModelDeploymentTGI,
17
+ )
18
+ from ads.llm.chat_template import ChatTemplates
13
19
  except ImportError as ex:
14
20
  if ex.name == "langchain":
15
21
  raise ImportError(
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*--
3
+
4
+ # Copyright (c) 2023 Oracle and/or its affiliates.
5
+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
+
7
+
8
+ import os
9
+
10
+
11
+ class ChatTemplates:
12
+ """Contains chat templates."""
13
+
14
+ @staticmethod
15
+ def _read_template(filename):
16
+ with open(
17
+ os.path.join(os.path.dirname(__file__), "templates", filename),
18
+ mode="r",
19
+ encoding="utf-8",
20
+ ) as f:
21
+ return f.read()
22
+
23
+ @staticmethod
24
+ def mistral():
25
+ """Chat template for auto tool calling with Mistral model deploy with vLLM."""
26
+ return ChatTemplates._read_template("tool_chat_template_mistral_parallel.jinja")
27
+
28
+ @staticmethod
29
+ def hermes():
30
+ """Chat template for auto tool calling with Hermes model deploy with vLLM."""
31
+ return ChatTemplates._read_template("tool_chat_template_hermes.jinja")
@@ -14,7 +14,7 @@ import sys
14
14
  from typing import Any, List, Dict, Tuple
15
15
  from langchain.schema.prompt import PromptValue
16
16
  from langchain.tools.base import BaseTool, ToolException
17
- from langchain.pydantic_v1 import BaseModel, root_validator
17
+ from pydantic import BaseModel, model_validator
18
18
 
19
19
 
20
20
  class RunInfo(BaseModel):
@@ -190,7 +190,8 @@ class Guardrail(BaseTool):
190
190
  This is used by the ``apply_filter()`` method.
191
191
  """
192
192
 
193
- @root_validator
193
+ @model_validator(mode="before")
194
+ @classmethod
194
195
  def default_name(cls, values):
195
196
  """Sets the default name of the guardrail."""
196
197
  if not values.get("name"):
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
  import evaluate
9
- from langchain.pydantic_v1 import root_validator
9
+ from pydantic.v1 import root_validator
10
10
  from .base import Guardrail
11
11
 
12
12
 
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*--
3
+
4
+ # Copyright (c) 2023 Oracle and/or its affiliates.
5
+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/