truefoundry 0.5.0rc6__py3-none-any.whl → 0.5.1__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.

Potentially problematic release.


This version of truefoundry might be problematic. Click here for more details.

Files changed (68) hide show
  1. truefoundry/common/auth_service_client.py +2 -2
  2. truefoundry/common/constants.py +9 -0
  3. truefoundry/common/utils.py +81 -1
  4. truefoundry/deploy/__init__.py +5 -0
  5. truefoundry/deploy/builder/builders/tfy_notebook_buildpack/__init__.py +4 -2
  6. truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py +7 -5
  7. truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py +87 -28
  8. truefoundry/deploy/builder/constants.py +8 -0
  9. truefoundry/deploy/builder/utils.py +9 -4
  10. truefoundry/deploy/cli/cli.py +2 -0
  11. truefoundry/deploy/cli/commands/__init__.py +1 -0
  12. truefoundry/deploy/cli/commands/deploy_init_command.py +22 -0
  13. truefoundry/deploy/lib/dao/application.py +2 -1
  14. truefoundry/deploy/v2/lib/patched_models.py +8 -0
  15. truefoundry/ml/__init__.py +25 -15
  16. truefoundry/ml/artifact/truefoundry_artifact_repo.py +8 -3
  17. truefoundry/ml/autogen/client/__init__.py +24 -0
  18. truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +325 -0
  19. truefoundry/ml/autogen/client/models/__init__.py +24 -0
  20. truefoundry/ml/autogen/client/models/artifact_version_manifest.py +2 -2
  21. truefoundry/ml/autogen/client/models/export_deployment_files_request_dto.py +82 -0
  22. truefoundry/ml/autogen/client/models/infer_method_name.py +34 -0
  23. truefoundry/ml/autogen/client/models/model_server.py +34 -0
  24. truefoundry/ml/autogen/client/models/model_version_environment.py +97 -0
  25. truefoundry/ml/autogen/client/models/model_version_manifest.py +13 -8
  26. truefoundry/ml/autogen/client/models/sklearn_framework.py +25 -2
  27. truefoundry/ml/autogen/client/models/sklearn_model_schema.py +82 -0
  28. truefoundry/ml/autogen/client/models/sklearn_serialization_format.py +35 -0
  29. truefoundry/ml/autogen/client/models/transformers_framework.py +2 -2
  30. truefoundry/ml/autogen/client/models/validate_external_storage_root_request_dto.py +71 -0
  31. truefoundry/ml/autogen/client/models/validate_external_storage_root_response_dto.py +69 -0
  32. truefoundry/ml/autogen/client/models/xg_boost_framework.py +28 -3
  33. truefoundry/ml/autogen/client/models/xg_boost_model_schema.py +88 -0
  34. truefoundry/ml/autogen/client/models/xg_boost_serialization_format.py +36 -0
  35. truefoundry/ml/autogen/client_README.md +12 -0
  36. truefoundry/ml/autogen/entities/artifacts.py +119 -26
  37. truefoundry/ml/autogen/models/signature.py +6 -3
  38. truefoundry/ml/autogen/models/utils.py +12 -7
  39. truefoundry/ml/cli/commands/model_init.py +97 -0
  40. truefoundry/ml/cli/utils.py +34 -0
  41. truefoundry/ml/log_types/artifacts/model.py +53 -38
  42. truefoundry/ml/log_types/artifacts/utils.py +38 -2
  43. truefoundry/ml/mlfoundry_api.py +77 -81
  44. truefoundry/ml/mlfoundry_run.py +3 -33
  45. truefoundry/ml/model_framework.py +372 -3
  46. truefoundry/ml/validation_utils.py +2 -0
  47. {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1.dist-info}/METADATA +2 -6
  48. {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1.dist-info}/RECORD +50 -55
  49. truefoundry/deploy/function_service/__init__.py +0 -3
  50. truefoundry/deploy/function_service/__main__.py +0 -27
  51. truefoundry/deploy/function_service/app.py +0 -92
  52. truefoundry/deploy/function_service/build.py +0 -45
  53. truefoundry/deploy/function_service/remote/__init__.py +0 -6
  54. truefoundry/deploy/function_service/remote/context.py +0 -3
  55. truefoundry/deploy/function_service/remote/method.py +0 -67
  56. truefoundry/deploy/function_service/remote/remote.py +0 -144
  57. truefoundry/deploy/function_service/route.py +0 -137
  58. truefoundry/deploy/function_service/service.py +0 -113
  59. truefoundry/deploy/function_service/utils.py +0 -53
  60. truefoundry/langchain/__init__.py +0 -12
  61. truefoundry/langchain/deprecated.py +0 -302
  62. truefoundry/langchain/truefoundry_chat.py +0 -130
  63. truefoundry/langchain/truefoundry_embeddings.py +0 -171
  64. truefoundry/langchain/truefoundry_llm.py +0 -106
  65. truefoundry/langchain/utils.py +0 -44
  66. truefoundry/ml/log_types/artifacts/model_extras.py +0 -48
  67. {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1.dist-info}/WHEEL +0 -0
  68. {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1.dist-info}/entry_points.txt +0 -0
@@ -1,106 +0,0 @@
1
- from typing import Any, Dict, List, Optional
2
-
3
- from langchain.llms.base import LLM
4
- from langchain.pydantic_v1 import Extra, Field, root_validator
5
-
6
- from truefoundry.common.request_utils import requests_retry_session
7
- from truefoundry.langchain.utils import (
8
- validate_tfy_environment,
9
- )
10
- from truefoundry.logger import logger
11
-
12
-
13
- class TrueFoundryLLM(LLM):
14
- """`TrueFoundry LLM Gateway` completion models API.
15
-
16
- To use, you must have the environment variable ``TFY_API_KEY`` set with your API key and ``TFY_HOST`` set with your host or pass it as a named parameter to the constructor.
17
- """
18
-
19
- model: str = Field(description="The model to use for completion.")
20
- """The model to use for completion."""
21
- tfy_llm_gateway_url: Optional[str] = Field(default=None)
22
- """TrueFoundry LLM Gateway endpoint URL. Automatically inferred from env var `TFY_LLM_GATEWAY_URL` if not provided."""
23
- tfy_api_key: Optional[str] = Field(default=None)
24
- """TrueFoundry API Key. Automatically inferred from env var `TFY_API_KEY` if not provided."""
25
- model_parameters: Optional[dict] = Field(default_factory=dict)
26
- """Model parameters"""
27
- request_timeout: int = Field(default=30)
28
- """The timeout for the request in seconds."""
29
- max_retries: int = Field(default=5)
30
- """The number of retries for HTTP requests."""
31
- retry_backoff_factor: float = Field(default=0.3)
32
- """The backoff factor for exponential backoff during retries."""
33
-
34
- class Config:
35
- """Configuration for this pydantic object."""
36
-
37
- extra = Extra.forbid
38
- allow_population_by_field_name = True
39
-
40
- @root_validator()
41
- def validate_environment(cls, values: Dict) -> Dict:
42
- values = validate_tfy_environment(values)
43
- if not values["tfy_api_key"]:
44
- raise ValueError(
45
- "Did not find `tfy_api_key`, please add an environment variable"
46
- " `TFY_API_KEY` which contains it, or pass"
47
- " `tfy_api_key` as a named parameter."
48
- )
49
- if not values["tfy_llm_gateway_url"]:
50
- raise ValueError(
51
- "Did not find `tfy_llm_gateway_url`, please add an environment variable"
52
- " `TFY_LLM_GATEWAY_URL` which contains it, or pass"
53
- " `tfy_llm_gateway_url` as a named parameter."
54
- )
55
- return values
56
-
57
- @property
58
- def _llm_type(self) -> str:
59
- """Return type of llm model."""
60
- return "truefoundry-llm"
61
-
62
- def _call(
63
- self,
64
- prompt: str,
65
- stop: Optional[List[str]] = None,
66
- **kwargs: Any,
67
- ) -> str:
68
- """Call out to the deployed model
69
-
70
- Args:
71
- prompt: The prompt to pass into the model.
72
- stop: Optional list of stop words to use when generating.
73
-
74
- Returns:
75
- The string generated by the model.
76
-
77
- Example:
78
- .. code-block:: python
79
-
80
- response = model("I have a joke for you...")
81
- """
82
-
83
- payload = {**self.model_parameters} if self.model_parameters else {}
84
- if stop:
85
- payload["stop_sequences"] = stop
86
-
87
- payload["prompt"] = prompt
88
- payload["model"] = self.model
89
-
90
- session = requests_retry_session(
91
- retries=self.max_retries, backoff_factor=self.retry_backoff_factor
92
- )
93
-
94
- url = f"{self.tfy_llm_gateway_url}/openai/completions"
95
- logger.debug(f"Completion using - model: {self.model} at endpoint: {url}")
96
- response = session.post(
97
- url=url,
98
- json=payload,
99
- headers={
100
- "Authorization": f"Bearer {self.tfy_api_key}",
101
- },
102
- timeout=self.request_timeout,
103
- )
104
- response.raise_for_status()
105
- output = response.json()
106
- return output["choices"][0]["text"]
@@ -1,44 +0,0 @@
1
- import os
2
- from typing import Dict, List, Optional
3
- from urllib.parse import urljoin
4
-
5
- from langchain.pydantic_v1 import BaseModel
6
-
7
- from truefoundry.deploy.lib.auth.servicefoundry_session import ServiceFoundrySession
8
-
9
-
10
- class ModelParameters(BaseModel):
11
- temperature: Optional[float]
12
- maximum_length: Optional[int]
13
- top_p: Optional[float]
14
- top_k: Optional[int]
15
- repetition_penalty: Optional[float]
16
- frequency_penalty: Optional[float]
17
- presence_penalty: Optional[float]
18
- stop_sequences: Optional[List[str]]
19
-
20
-
21
- def validate_tfy_environment(values: Dict):
22
- gateway_url = values["tfy_llm_gateway_url"] or os.getenv("TFY_LLM_GATEWAY_URL")
23
- api_key = values["tfy_api_key"] or os.getenv("TFY_API_KEY")
24
-
25
- if gateway_url and api_key:
26
- values["tfy_llm_gateway_url"] = gateway_url
27
- values["tfy_api_key"] = api_key
28
- return values
29
-
30
- sfy_session = ServiceFoundrySession()
31
- if not sfy_session:
32
- raise Exception(
33
- "Unauthenticated: Please login using truefoundry login --host <https://example-domain.com>"
34
- )
35
-
36
- if not gateway_url:
37
- gateway_url = urljoin(sfy_session.base_url, "/api/llm")
38
-
39
- if not api_key:
40
- api_key = sfy_session.access_token
41
-
42
- values["tfy_llm_gateway_url"] = gateway_url
43
- values["tfy_api_key"] = api_key
44
- return values
@@ -1,48 +0,0 @@
1
- import enum
2
- from typing import List, Type, TypeVar
3
-
4
- from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
5
- ModelSchemaDto,
6
- )
7
- from truefoundry.ml.exceptions import MlFoundryException
8
- from truefoundry.pydantic_v1 import BaseModel
9
-
10
- T = TypeVar("T")
11
-
12
-
13
- class BaseEnum(enum.Enum):
14
- @classmethod
15
- def values(cls: Type[T]) -> List[T]:
16
- return [member.value for member in cls]
17
-
18
- @classmethod
19
- def _missing_(cls: Type[T], value: object):
20
- raise MlFoundryException(
21
- f"Unknown value for type {cls.__name__}: {value}", status_code=400
22
- )
23
-
24
-
25
- @enum.unique
26
- class CustomMetricValueType(str, BaseEnum):
27
- FLOAT = "float"
28
-
29
-
30
- @enum.unique
31
- class CustomMetricType(str, BaseEnum):
32
- METRIC = "metric"
33
- PROJECTION = "projection"
34
-
35
-
36
- class CustomMetric(BaseModel):
37
- class Config:
38
- validate_assignment = True
39
- use_enum_values = True
40
- extra = "allow"
41
-
42
- name: str
43
- value_type: CustomMetricValueType
44
- type: CustomMetricType
45
-
46
-
47
- class ModelSchema(ModelSchemaDto):
48
- pass