truefoundry 0.5.0rc7__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 (67) 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 -16
  16. truefoundry/ml/autogen/client/__init__.py +21 -3
  17. truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +325 -0
  18. truefoundry/ml/autogen/client/models/__init__.py +21 -3
  19. truefoundry/ml/autogen/client/models/artifact_version_manifest.py +2 -2
  20. truefoundry/ml/autogen/client/models/export_deployment_files_request_dto.py +82 -0
  21. truefoundry/ml/autogen/client/models/infer_method_name.py +34 -0
  22. truefoundry/ml/autogen/client/models/model_server.py +34 -0
  23. truefoundry/ml/autogen/client/models/model_version_environment.py +1 -1
  24. truefoundry/ml/autogen/client/models/model_version_manifest.py +2 -8
  25. truefoundry/ml/autogen/client/models/sklearn_framework.py +15 -5
  26. truefoundry/ml/autogen/client/models/sklearn_model_schema.py +82 -0
  27. truefoundry/ml/autogen/client/models/{serialization_format.py → sklearn_serialization_format.py} +5 -5
  28. truefoundry/ml/autogen/client/models/transformers_framework.py +2 -2
  29. truefoundry/ml/autogen/client/models/validate_external_storage_root_request_dto.py +71 -0
  30. truefoundry/ml/autogen/client/models/validate_external_storage_root_response_dto.py +69 -0
  31. truefoundry/ml/autogen/client/models/xg_boost_framework.py +17 -5
  32. truefoundry/ml/autogen/client/models/xg_boost_model_schema.py +88 -0
  33. truefoundry/ml/autogen/client/models/xg_boost_serialization_format.py +36 -0
  34. truefoundry/ml/autogen/client_README.md +11 -1
  35. truefoundry/ml/autogen/entities/artifacts.py +95 -39
  36. truefoundry/ml/autogen/models/signature.py +6 -3
  37. truefoundry/ml/autogen/models/utils.py +12 -7
  38. truefoundry/ml/cli/commands/model_init.py +97 -0
  39. truefoundry/ml/cli/utils.py +34 -0
  40. truefoundry/ml/log_types/artifacts/model.py +50 -38
  41. truefoundry/ml/log_types/artifacts/utils.py +38 -2
  42. truefoundry/ml/mlfoundry_api.py +74 -80
  43. truefoundry/ml/mlfoundry_run.py +0 -32
  44. truefoundry/ml/model_framework.py +372 -3
  45. truefoundry/ml/validation_utils.py +2 -0
  46. {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/METADATA +1 -5
  47. {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/RECORD +49 -56
  48. truefoundry/deploy/function_service/__init__.py +0 -3
  49. truefoundry/deploy/function_service/__main__.py +0 -27
  50. truefoundry/deploy/function_service/app.py +0 -92
  51. truefoundry/deploy/function_service/build.py +0 -45
  52. truefoundry/deploy/function_service/remote/__init__.py +0 -6
  53. truefoundry/deploy/function_service/remote/context.py +0 -3
  54. truefoundry/deploy/function_service/remote/method.py +0 -67
  55. truefoundry/deploy/function_service/remote/remote.py +0 -144
  56. truefoundry/deploy/function_service/route.py +0 -137
  57. truefoundry/deploy/function_service/service.py +0 -113
  58. truefoundry/deploy/function_service/utils.py +0 -53
  59. truefoundry/langchain/__init__.py +0 -12
  60. truefoundry/langchain/deprecated.py +0 -302
  61. truefoundry/langchain/truefoundry_chat.py +0 -130
  62. truefoundry/langchain/truefoundry_embeddings.py +0 -171
  63. truefoundry/langchain/truefoundry_llm.py +0 -106
  64. truefoundry/langchain/utils.py +0 -44
  65. truefoundry/ml/log_types/artifacts/model_extras.py +0 -48
  66. {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/WHEEL +0 -0
  67. {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/entry_points.txt +0 -0
@@ -1,144 +0,0 @@
1
- import abc
2
- import inspect
3
- from typing import Dict, Optional
4
-
5
- from truefoundry.deploy.function_service.remote.method import method_factory
6
- from truefoundry.deploy.function_service.utils import get_qual_name
7
-
8
-
9
- class Remote(abc.ABC):
10
- @property
11
- @abc.abstractmethod
12
- def instance(self): ...
13
-
14
- @abc.abstractmethod
15
- def get_qual_name(self, method) -> str: ...
16
-
17
-
18
- class RemoteFunction(Remote):
19
- def __init__(self, func, **kwargs):
20
- self._func = func
21
- self._instance = inspect.getmodule(self._func)
22
- self.method = method_factory(remote_object=self, method=self._func)
23
-
24
- def __call__(self, *args, **kwargs):
25
- if len(args) > 0:
26
- raise Exception(
27
- "Positional arguments are not supported now.\n"
28
- "Please use keyword arguments"
29
- )
30
- return self.method.__call__(**kwargs)
31
-
32
- def run(self, **kwargs):
33
- return self.method.run(**kwargs)
34
-
35
- async def run_async(self, **kwargs):
36
- return await self.method.run_async(**kwargs)
37
-
38
- @property
39
- def instance(self):
40
- return self._instance
41
-
42
- def get_qual_name(self, method) -> str:
43
- return get_qual_name(method)
44
-
45
-
46
- class RemoteClass(Remote):
47
- def __init__(
48
- self,
49
- class_,
50
- *,
51
- init_kwargs: Optional[Dict] = None,
52
- name: Optional[str] = None,
53
- **kwargs,
54
- ):
55
- self._class = class_
56
- self._name = name or class_.__name__
57
- self._init_kwargs = init_kwargs or {}
58
-
59
- self._instance = None
60
-
61
- ###############
62
- # Maybe this is not the right way to model it.
63
- # Another approach can be, identify whether the environment is local
64
- # or our service. If local, then we can just return the instance of
65
- # the user defined class. Else, we return a class which reflects the
66
- # methods in the class, but internally doing network call.
67
- # But I am sticking with this now because not all the concepts of a python
68
- # class right now, will work in both remote and local. Examples, you cannot
69
- # access arbitrary attributes, properties etc. I want to keep the behaviour
70
- # identical for now.
71
- absent = object()
72
- methods = inspect.getmembers(class_, predicate=inspect.isfunction)
73
- for method_name, method in methods:
74
- if method_name.startswith("_"):
75
- continue
76
- existing_attribute = getattr(self, method_name, absent)
77
- if existing_attribute is not absent:
78
- raise Exception(
79
- f"Cannot reflect {method_name!r} of class {class_.__name__!r}.\n"
80
- f"{method_name!r} is reserved. Use a different method name"
81
- )
82
-
83
- setattr(
84
- self,
85
- method_name,
86
- method_factory(remote_object=self, method=method),
87
- )
88
- ###############
89
-
90
- def get_qual_name(self, method) -> str:
91
- return f"{self.name}:{get_qual_name(method)}"
92
-
93
- @property
94
- def instance(self):
95
- if self._instance:
96
- return self._instance
97
- instance = self._class(**self._init_kwargs)
98
- self._instance = instance
99
- return self._instance
100
-
101
- @property
102
- def class_(self):
103
- return self._class
104
-
105
- @property
106
- def name(self) -> str:
107
- return self._name
108
-
109
- @property
110
- def init_kwargs(self) -> Dict:
111
- return self._init_kwargs
112
-
113
-
114
- def remote(func_or_class, **kwargs):
115
- if inspect.isfunction(func_or_class):
116
- return RemoteFunction(func_or_class, **kwargs)
117
- if inspect.isclass(func_or_class):
118
- return RemoteClass(func_or_class, **kwargs)
119
-
120
- raise Exception()
121
-
122
-
123
- if __name__ == "__main__":
124
-
125
- def foo(a, b):
126
- print(a, b)
127
-
128
- remote(foo)(a=1, b=2)
129
-
130
- class Foo:
131
- def __init__(self, a, b):
132
- self.a = a
133
- self.b = b
134
-
135
- def foo(self):
136
- print(self.a, self.b)
137
-
138
- foo_instance = remote(Foo, name="foo", init_kwargs={"a": 1, "b": 2})
139
- foo_instance_2 = remote(Foo, name="foo_2", init_kwargs={"a": 3, "b": 2})
140
-
141
- foo_instance.foo()
142
- foo_instance_2.foo()
143
- foo_instance.foo.run()
144
- # foo_instance.foo.async_run()
@@ -1,137 +0,0 @@
1
- import inspect
2
- import json
3
- from typing import Any, Callable, Dict, List
4
-
5
- from truefoundry.deploy.function_service.remote import RemoteClass
6
- from truefoundry.deploy.function_service.utils import (
7
- create_pydantic_model_from_function_signature,
8
- get_qual_name,
9
- )
10
- from truefoundry.logger import logger
11
- from truefoundry.pydantic_v1 import BaseModel, Field, constr, validator
12
-
13
-
14
- def validate_we_can_create_pydantic_model_of_func_args(func: Callable):
15
- qual_name = get_qual_name(func)
16
- try:
17
- create_pydantic_model_from_function_signature(func, get_qual_name(func))
18
- except Exception as ex:
19
- raise Exception(
20
- f"Unable to create a route for {qual_name!r}.\n"
21
- "Please ensure that in the function type signature, you have only used in-built\n"
22
- "types like `int`, `float`, `str`, `bool`, `typing.Dict`, `typing.List`, typing.Optional`.\n"
23
- "To temporarily resolve this error, you can remove the unsupported type signatures.\n"
24
- ) from ex
25
-
26
-
27
- def path_pre_processor(path: str, prefix: str = "") -> str:
28
- path = path.strip("/")
29
-
30
- if not path:
31
- raise ValueError("path cannot be empty")
32
-
33
- prefix = prefix.strip("/")
34
- if not prefix:
35
- return f"/{path}"
36
-
37
- return f"/{prefix}/{path}"
38
-
39
-
40
- class Route(BaseModel):
41
- function_name: str
42
- http_method: str
43
- path: constr(regex=r"^[A-Za-z0-9\-_/]+$")
44
-
45
- qual_name: str
46
-
47
-
48
- class FunctionRoute(Route):
49
- module: str
50
-
51
- @classmethod
52
- def from_func(cls, func: Callable, path: str):
53
- validate_we_can_create_pydantic_model_of_func_args(func)
54
- return cls(
55
- function_name=func.__name__,
56
- http_method="POST",
57
- path=path_pre_processor(path or func.__name__),
58
- qual_name=get_qual_name(func),
59
- module=func.__module__,
60
- )
61
-
62
-
63
- class ClassRoute(BaseModel):
64
- class_name: str
65
- init_kwargs: Dict[str, Any] = Field(default_factory=dict)
66
- module: str
67
-
68
- routes: List[Route] = Field(default_factory=list)
69
-
70
- @validator("init_kwargs")
71
- def init_kwargs_is_json_serializable(cls, v, values):
72
- try:
73
- json.dumps(v)
74
- except Exception as ex:
75
- class_name = values.get("class_name")
76
- raise ValueError(
77
- f"init_kwargs {v!r} of class {class_name!r} is not JSON serializable"
78
- ) from ex
79
-
80
- return v
81
-
82
- @classmethod
83
- def from_class(cls, remote_class: RemoteClass):
84
- routes = []
85
- methods = inspect.getmembers(remote_class.class_, predicate=inspect.isfunction)
86
-
87
- for method_name, method in methods:
88
- if method_name.startswith("_"):
89
- continue
90
- validate_we_can_create_pydantic_model_of_func_args(method)
91
- route = Route(
92
- function_name=method_name,
93
- http_method="POST",
94
- path=path_pre_processor(prefix=remote_class.name, path=method_name),
95
- qual_name=remote_class.get_qual_name(method),
96
- )
97
- routes.append(route)
98
-
99
- return cls(
100
- class_name=remote_class.class_.__name__,
101
- init_kwargs=remote_class.init_kwargs,
102
- routes=routes,
103
- module=remote_class.class_.__module__,
104
- )
105
-
106
-
107
- class RouteGroups(BaseModel):
108
- functions: List[FunctionRoute] = Field(default_factory=list)
109
- classes: Dict[str, ClassRoute] = Field(default_factory=dict)
110
-
111
- def register_function(self, func, path):
112
- function_route = FunctionRoute.from_func(func=func, path=path)
113
- logger.info(
114
- "Function %r from module %r will be deployed on path '%s %s'.",
115
- function_route.function_name,
116
- function_route.module,
117
- function_route.http_method,
118
- function_route.path,
119
- )
120
- self.functions.append(function_route)
121
-
122
- def register_class(self, remote_class: RemoteClass):
123
- if remote_class.name in self.classes:
124
- raise ValueError(
125
- f"name {remote_class.name!r} is already used to register a class"
126
- )
127
- class_route = ClassRoute.from_class(remote_class)
128
- for route in class_route.routes:
129
- logger.info(
130
- "Method %r from `%s:%s` will be deployed on path '%s %s'.",
131
- route.function_name,
132
- class_route.class_name,
133
- remote_class.name,
134
- route.http_method,
135
- route.path,
136
- )
137
- self.classes[remote_class.name] = class_route
@@ -1,113 +0,0 @@
1
- from threading import Thread
2
- from typing import Any, Callable, Dict, Optional, Union
3
-
4
- import yaml
5
-
6
- from truefoundry.deploy.auto_gen.models import Port, Resources
7
- from truefoundry.deploy.function_service.app import (
8
- build_and_run_app_in_background_thread,
9
- )
10
- from truefoundry.deploy.function_service.build import BuildConfig
11
- from truefoundry.deploy.function_service.remote import RemoteClass
12
- from truefoundry.deploy.function_service.route import RouteGroups
13
- from truefoundry.deploy.v2.lib.deployable_patched_models import Service
14
- from truefoundry.deploy.v2.lib.patched_models import Build, LocalSource
15
- from truefoundry.logger import logger
16
-
17
-
18
- class FunctionService:
19
- def __init__(
20
- self,
21
- name: str,
22
- build_config: Optional[BuildConfig] = None,
23
- resources: Optional[Resources] = None,
24
- replicas: int = 1,
25
- port: Union[int, Port] = 8000,
26
- env: Optional[Dict[str, str]] = None,
27
- ):
28
- self._name = name
29
- self._build_config = build_config or BuildConfig()
30
- self._resources = resources or Resources()
31
- self._replicas = replicas
32
- if isinstance(port, int):
33
- port = Port(port=port, expose=False)
34
- if not port.host:
35
- logger.warning(
36
- "No host is set for the port. This is not an issue if you don't "
37
- "want an exposed endpoint or are just testing locally.\n"
38
- "However, for actual deployment it is required to pass an "
39
- "instance of `truefoundry.deploy.Port` with "
40
- "`host` argument defined.\n"
41
- "E.g. `FunctionService(name='...', port=Port(port=8000, host='...', path='...'), ...)`"
42
- )
43
- self._port = port
44
- self._env = env or {}
45
-
46
- self._route_groups: RouteGroups = RouteGroups()
47
-
48
- @property
49
- def route_groups(self) -> RouteGroups:
50
- return self._route_groups
51
-
52
- def __repr__(self):
53
- return yaml.dump(
54
- {
55
- "name": self._name,
56
- "build_config": self._build_config.dict(),
57
- "resources": self._resources.dict(),
58
- "routes": self._route_groups.dict(),
59
- "replicas": self._replicas,
60
- "port": self._port.dict(),
61
- "env": self._env,
62
- },
63
- indent=2,
64
- )
65
-
66
- def register_function(
67
- self,
68
- func: Callable,
69
- *,
70
- path: Optional[str] = None,
71
- ):
72
- self._route_groups.register_function(func=func, path=path)
73
-
74
- def register_class(
75
- self,
76
- class_,
77
- *,
78
- init_kwargs: Optional[Dict[str, Any]] = None,
79
- name: Optional[str] = None,
80
- ):
81
- # TODO: I need to rethink this `RemoteClass`.
82
- # I am mixing up multiple responsibilities here.
83
- # For now, I am removing the burden of using `remote` from the user when deploying
84
- # an instance of a class.
85
- remote_class = RemoteClass(class_, init_kwargs=init_kwargs, name=name)
86
- self._route_groups.register_class(remote_class=remote_class)
87
-
88
- def run(self) -> Thread:
89
- return build_and_run_app_in_background_thread(
90
- route_groups=self._route_groups, port=self._port.port
91
- )
92
-
93
- def get_deployment_definition(self) -> Service:
94
- # Keeping this function right now so that later,
95
- # the constructor of the application call this function
96
- # to get the component spec, if an object of this class
97
- # is directly passed as a component
98
- tfy_python_build_config = self._build_config.to_tfy_python_build_config(
99
- port=self._port.port, route_groups=self._route_groups
100
- )
101
- service = Service(
102
- name=self._name,
103
- image=Build(build_source=LocalSource(), build_spec=tfy_python_build_config),
104
- resources=self._resources,
105
- replicas=self._replicas,
106
- ports=[self._port],
107
- env=self._env,
108
- )
109
- return service
110
-
111
- def deploy(self, workspace_fqn: str, wait: bool = True):
112
- service = self.get_deployment_definition()
113
- service.deploy(workspace_fqn=workspace_fqn, wait=wait)
@@ -1,53 +0,0 @@
1
- import inspect
2
- from typing import Any
3
-
4
- from truefoundry.pydantic_v1 import BaseModel
5
- from truefoundry.pydantic_v1 import create_model as pydantic_create_model
6
-
7
-
8
- def get_qual_name(obj):
9
- return f"{obj.__module__}.{obj.__qualname__}"
10
-
11
-
12
- def create_pydantic_model_from_function_signature(func, model_name: str):
13
- # https://github.com/pydantic/pydantic/issues/1391
14
- (
15
- args,
16
- _,
17
- varkw,
18
- defaults,
19
- kwonlyargs,
20
- kwonlydefaults,
21
- annotations,
22
- ) = inspect.getfullargspec(func)
23
- defaults = defaults or []
24
- args = args or []
25
- if len(args) > 0 and args[0] == "self":
26
- del args[0]
27
-
28
- non_default_args = len(args) - len(defaults)
29
- defaults = [
30
- ...,
31
- ] * non_default_args + list(defaults)
32
-
33
- keyword_only_params = {
34
- param: kwonlydefaults.get(param, Any) for param in kwonlyargs
35
- }
36
- params = {
37
- param: (annotations.get(param, Any), default)
38
- for param, default in zip(args, defaults)
39
- }
40
-
41
- class Config:
42
- extra = "allow"
43
-
44
- # Allow extra params if there is a **kwargs parameter in the function signature
45
- config = Config if varkw else None
46
-
47
- return pydantic_create_model(
48
- model_name,
49
- **params,
50
- **keyword_only_params,
51
- __base__=BaseModel,
52
- __config__=config,
53
- )
@@ -1,12 +0,0 @@
1
- try:
2
- import langchain as _
3
- except Exception as ex:
4
- raise Exception(
5
- "Failed to import langchain. "
6
- "Please install langchain by using `pip install langchain` command"
7
- ) from ex
8
- from truefoundry.langchain.deprecated import TruefoundryLLM, TruefoundryPlaygroundLLM
9
- from truefoundry.langchain.truefoundry_chat import TrueFoundryChat
10
- from truefoundry.langchain.truefoundry_embeddings import TrueFoundryEmbeddings
11
- from truefoundry.langchain.truefoundry_llm import TrueFoundryLLM
12
- from truefoundry.langchain.utils import ModelParameters