truefoundry 0.5.0rc6__py3-none-any.whl → 0.5.1rc1__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.
- truefoundry/common/utils.py +73 -1
- truefoundry/deploy/__init__.py +5 -0
- truefoundry/deploy/cli/cli.py +2 -0
- truefoundry/deploy/cli/commands/__init__.py +1 -0
- truefoundry/deploy/cli/commands/deploy_init_command.py +22 -0
- truefoundry/deploy/lib/dao/application.py +2 -1
- truefoundry/deploy/v2/lib/patched_models.py +8 -0
- truefoundry/ml/__init__.py +15 -12
- truefoundry/ml/artifact/truefoundry_artifact_repo.py +8 -3
- truefoundry/ml/autogen/client/__init__.py +11 -0
- truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +161 -0
- truefoundry/ml/autogen/client/models/__init__.py +11 -0
- truefoundry/ml/autogen/client/models/artifact_version_manifest.py +2 -2
- truefoundry/ml/autogen/client/models/export_deployment_files_request_dto.py +82 -0
- truefoundry/ml/autogen/client/models/infer_method_name.py +34 -0
- truefoundry/ml/autogen/client/models/model_server.py +34 -0
- truefoundry/ml/autogen/client/models/model_version_environment.py +97 -0
- truefoundry/ml/autogen/client/models/model_version_manifest.py +14 -3
- truefoundry/ml/autogen/client/models/serialization_format.py +35 -0
- truefoundry/ml/autogen/client/models/sklearn_framework.py +31 -2
- truefoundry/ml/autogen/client/models/transformers_framework.py +2 -2
- truefoundry/ml/autogen/client/models/xg_boost_framework.py +20 -2
- truefoundry/ml/autogen/client_README.md +6 -0
- truefoundry/ml/autogen/entities/artifacts.py +65 -6
- truefoundry/ml/cli/commands/model_init.py +97 -0
- truefoundry/ml/cli/utils.py +34 -0
- truefoundry/ml/log_types/artifacts/model.py +48 -24
- truefoundry/ml/log_types/artifacts/utils.py +37 -1
- truefoundry/ml/mlfoundry_api.py +77 -79
- truefoundry/ml/mlfoundry_run.py +3 -31
- truefoundry/ml/model_framework.py +257 -3
- truefoundry/ml/validation_utils.py +2 -0
- {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1rc1.dist-info}/METADATA +2 -6
- {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1rc1.dist-info}/RECORD +36 -45
- truefoundry/deploy/function_service/__init__.py +0 -3
- truefoundry/deploy/function_service/__main__.py +0 -27
- truefoundry/deploy/function_service/app.py +0 -92
- truefoundry/deploy/function_service/build.py +0 -45
- truefoundry/deploy/function_service/remote/__init__.py +0 -6
- truefoundry/deploy/function_service/remote/context.py +0 -3
- truefoundry/deploy/function_service/remote/method.py +0 -67
- truefoundry/deploy/function_service/remote/remote.py +0 -144
- truefoundry/deploy/function_service/route.py +0 -137
- truefoundry/deploy/function_service/service.py +0 -113
- truefoundry/deploy/function_service/utils.py +0 -53
- truefoundry/langchain/__init__.py +0 -12
- truefoundry/langchain/deprecated.py +0 -302
- truefoundry/langchain/truefoundry_chat.py +0 -130
- truefoundry/langchain/truefoundry_embeddings.py +0 -171
- truefoundry/langchain/truefoundry_llm.py +0 -106
- truefoundry/langchain/utils.py +0 -44
- {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1rc1.dist-info}/WHEEL +0 -0
- {truefoundry-0.5.0rc6.dist-info → truefoundry-0.5.1rc1.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"]
|
truefoundry/langchain/utils.py
DELETED
|
@@ -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
|
|
File without changes
|
|
File without changes
|