lightning-sdk 0.2.21rc0__py3-none-any.whl → 0.2.21rc1__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.
lightning_sdk/__init__.py CHANGED
@@ -31,6 +31,6 @@ __all__ = [
31
31
  "User",
32
32
  ]
33
33
 
34
- __version__ = "0.2.21.rc0"
34
+ __version__ = "0.2.21.rc1"
35
35
  _check_version_and_prompt_upgrade(__version__)
36
36
  _set_tqdm_envvars_noninteractive()
@@ -282,10 +282,11 @@ class DeploymentApi:
282
282
 
283
283
  requires_release = False
284
284
  requires_release |= apply_change(deployment.spec, "image", image)
285
+
285
286
  requires_release |= apply_change(deployment.spec, "entrypoint", entrypoint)
286
287
  requires_release |= apply_change(deployment.spec, "command", command)
287
288
  requires_release |= apply_change(deployment.spec, "env", to_env(env))
288
- requires_release |= apply_change(deployment.spec, "readiness_probe", to_health_check(health_check))
289
+ requires_release |= apply_change(deployment.spec, "readiness_probe", to_health_check(health_check, False))
289
290
  requires_release |= apply_change(deployment.spec, "cluster_id", cloud_account)
290
291
  requires_release |= apply_change(deployment.spec, "spot", spot)
291
292
  requires_release |= apply_change(deployment.spec, "quantity", quantity)
@@ -524,8 +525,12 @@ def to_endpoint(
524
525
 
525
526
 
526
527
  def to_health_check(
527
- health_check: Optional[Union[HttpHealthCheck, ExecHealthCheck]] = None
528
+ health_check: Optional[Union[HttpHealthCheck, ExecHealthCheck]] = None,
529
+ use_default: bool = True,
528
530
  ) -> Optional[V1JobHealthCheckConfig]:
531
+ if health_check is None and not use_default:
532
+ return None
533
+
529
534
  # Use Default health check if none is provided
530
535
  if not health_check:
531
536
  return V1JobHealthCheckConfig(
@@ -11,7 +11,7 @@ LICENSE_SIGNING_URL = f"{env.LIGHTNING_CLOUD_URL}?settings=licenses"
11
11
 
12
12
 
13
13
  def generate_url_user_settings(redirect_to: str = LICENSE_SIGNING_URL) -> str:
14
- params = urlencode({"redirectTo": redirect_to, "mode": "licenses", "okbhrt": LICENSE_CODE})
14
+ params = urlencode({"redirectTo": redirect_to, "okbhrt": LICENSE_CODE})
15
15
  return f"{env.LIGHTNING_CLOUD_URL}/sign-in?{params}"
16
16
 
17
17
 
@@ -276,8 +276,8 @@ class Deployment:
276
276
  cloud_account=cloud_account,
277
277
  machine=machine,
278
278
  image=image,
279
- entrypoint=entrypoint or "",
280
- command=command or "",
279
+ entrypoint=entrypoint,
280
+ command=command,
281
281
  ports=ports,
282
282
  custom_domain=custom_domain,
283
283
  auth=auth,
@@ -340,7 +340,7 @@ class Deployment:
340
340
  return None
341
341
 
342
342
  @property
343
- def readiness_probe(self) -> Optional[Union[HttpHealthCheck, ExecHealthCheck]]:
343
+ def health_check(self) -> Optional[Union[HttpHealthCheck, ExecHealthCheck]]:
344
344
  """The health check to validate the replicas are ready to receive traffic."""
345
345
  if self._deployment:
346
346
  self._deployment = self._deployment_api.get_deployment_by_name(self._name, self._teamspace.id)
@@ -467,6 +467,20 @@ class Deployment:
467
467
  return self._deployment.spec.image
468
468
  return None
469
469
 
470
+ @property
471
+ def entrypoint(self) -> Optional[str]:
472
+ if self._deployment:
473
+ self._deployment = self._deployment_api.get_deployment_by_name(self._name, self._teamspace.id)
474
+ return self._deployment.spec.entrypoint
475
+ return None
476
+
477
+ @property
478
+ def command(self) -> Optional[str]:
479
+ if self._deployment:
480
+ self._deployment = self._deployment_api.get_deployment_by_name(self._name, self._teamspace.id)
481
+ return self._deployment.spec.command
482
+ return None
483
+
470
484
  @property
471
485
  def _session(self) -> Any:
472
486
  if self._request_session is None:
@@ -1,4 +1,3 @@
1
- from lightning_sdk.llm.asyncllm import AsyncLLM
2
1
  from lightning_sdk.llm.llm import LLM
3
2
 
4
- __all__ = ["LLM", "AsyncLLM"]
3
+ __all__ = ["LLM"]
lightning_sdk/llm/llm.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  import warnings
3
- from typing import Dict, Generator, List, Optional, Set, Tuple, Union
3
+ from typing import AsyncGenerator, Dict, Generator, List, Optional, Set, Tuple, Union
4
4
 
5
5
  from lightning_sdk.api.llm_api import LLMApi
6
6
  from lightning_sdk.cli.teamspace_menu import _TeamspacesMenu
@@ -18,6 +18,7 @@ class LLM:
18
18
  self,
19
19
  name: str,
20
20
  teamspace: Optional[str] = None,
21
+ enable_async: Optional[bool] = False,
21
22
  ) -> None:
22
23
  """Initializes the LLM instance with teamspace information, which is required for billing purposes.
23
24
 
@@ -30,6 +31,7 @@ class LLM:
30
31
  name (str): The name of the model or resource.
31
32
  teamspace (Optional[str]): The specified teamspace for billing. If not provided, it will be resolved
32
33
  through the above methods.
34
+ enable_async (Optional[bool]): Enable async requests
33
35
 
34
36
  Raises:
35
37
  ValueError: If teamspace information cannot be resolved.
@@ -67,6 +69,7 @@ class LLM:
67
69
  self._model_provider, self._model_name = self._parse_model_name(name)
68
70
 
69
71
  self._llm_api = LLMApi()
72
+ self._enable_async = enable_async
70
73
 
71
74
  try:
72
75
  # check if it is a org model
@@ -174,6 +177,36 @@ class LLM:
174
177
  for line in result:
175
178
  yield line.choices[0].delta.content
176
179
 
180
+ async def _async_chat(
181
+ self,
182
+ prompt: str,
183
+ system_prompt: Optional[str] = None,
184
+ max_completion_tokens: Optional[int] = 500,
185
+ images: Optional[Union[List[str], str]] = None,
186
+ conversation: Optional[str] = None,
187
+ metadata: Optional[Dict[str, str]] = None,
188
+ stream: bool = False,
189
+ upload_local_images: bool = False,
190
+ ) -> Union[str, AsyncGenerator[str, None]]:
191
+ conversation_id = self._conversations.get(conversation) if conversation else None
192
+ output = await self._llm_api.async_start_conversation(
193
+ prompt=prompt,
194
+ system_prompt=system_prompt,
195
+ max_completion_tokens=max_completion_tokens,
196
+ images=images,
197
+ assistant_id=self._model.id,
198
+ conversation_id=conversation_id,
199
+ billing_project_id=self._teamspace.id,
200
+ metadata=metadata,
201
+ name=conversation,
202
+ stream=stream,
203
+ )
204
+ if not stream:
205
+ if conversation and not conversation_id:
206
+ self._conversations[conversation] = output.conversation_id
207
+ return output.choices[0].delta.content
208
+ raise NotImplementedError("Streaming is not supported in this client.")
209
+
177
210
  def chat(
178
211
  self,
179
212
  prompt: str,
@@ -198,6 +231,19 @@ class LLM:
198
231
  self._teamspace.upload_file(file_path=image, remote_path=f"images/{os.path.basename(image)}")
199
232
 
200
233
  conversation_id = self._conversations.get(conversation) if conversation else None
234
+
235
+ if self._enable_async:
236
+ return self._async_chat(
237
+ prompt,
238
+ system_prompt,
239
+ max_completion_tokens,
240
+ images,
241
+ conversation,
242
+ metadata,
243
+ stream,
244
+ upload_local_images,
245
+ )
246
+
201
247
  output = self._llm_api.start_conversation(
202
248
  prompt=prompt,
203
249
  system_prompt=system_prompt,
@@ -63,7 +63,7 @@ class Pipeline:
63
63
  pipeline = None
64
64
 
65
65
  if name.startswith("pip_"):
66
- pipeline = self._pipeline_api.get_pipeline_by_id(name, self._teamspace.id)
66
+ pipeline = self._pipeline_api.get_pipeline_by_id(self._teamspace.id, name)
67
67
 
68
68
  if pipeline:
69
69
  self._name = pipeline.name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lightning_sdk
3
- Version: 0.2.21rc0
3
+ Version: 0.2.21rc1
4
4
  Summary: SDK to develop using Lightning AI Studios
5
5
  Author-email: Lightning-AI <justus@lightning.ai>
6
6
  License: MIT License
@@ -1,5 +1,5 @@
1
1
  docs/source/conf.py,sha256=r8yX20eC-4mHhMTd0SbQb5TlSWHhO6wnJ0VJ_FBFpag,13249
2
- lightning_sdk/__init__.py,sha256=iYr_Snl9t-FCjzSekdEUcAwh9Thp-bA_WsbMQQ4C25k,1109
2
+ lightning_sdk/__init__.py,sha256=rf_9sAIQvu29ycoVRuBKYsXAYo6IEB7sIlB6OYkdZc4,1109
3
3
  lightning_sdk/agents.py,sha256=ly6Ma1j0ZgGPFyvPvMN28JWiB9dATIstFa5XM8pMi6I,1577
4
4
  lightning_sdk/ai_hub.py,sha256=iI1vNhgcz_Ff1c3rN1ogN7dK-r-HXRj6NMtS2cA14UA,6925
5
5
  lightning_sdk/base_studio.py,sha256=-ZnnZl5fG4w3BOQAelQndg7wEao2jGxpaYrpujlB7OQ,3353
@@ -21,9 +21,9 @@ lightning_sdk/api/agents_api.py,sha256=G47TbFo9kYqnBMqdw2RW-lfS1VAUBSXDmzs6fpIEM
21
21
  lightning_sdk/api/ai_hub_api.py,sha256=azqDZ-PzasVAcoQHno7k7OO_xFOHQ4NDozxF8jEh83Y,7864
22
22
  lightning_sdk/api/base_studio_api.py,sha256=cipTG4I5OvFLDVAbM1E0lvGjP9YhhoByfa9mQFF9ueI,3383
23
23
  lightning_sdk/api/cluster_api.py,sha256=mfHGKHy-RNpI7nKlhw9Zc7Jv6f4DCFq-qRIwOR3VptY,3972
24
- lightning_sdk/api/deployment_api.py,sha256=Dw4NaFiNTYhqz099N5hYZzF-K0dUoWnGK2vE--iUy1c,24104
24
+ lightning_sdk/api/deployment_api.py,sha256=Bogjf0rqdxVQmi7rbwZLSvevSlLVk7eIFaXFi6R75EM,24213
25
25
  lightning_sdk/api/job_api.py,sha256=_mMAI_BG_48i-BLwCP_U72zgmM5zYa2KUZ7u66HWkIc,13568
26
- lightning_sdk/api/license_api.py,sha256=7pdff1MwwcRL7SJmDoIrqmJNUewXQYiVLFx8e5uc5eY,2426
26
+ lightning_sdk/api/license_api.py,sha256=IVaexSSXHyeu1RBQ5Cab1XqswdnVueDvntH9TMlZp-4,2406
27
27
  lightning_sdk/api/lit_container_api.py,sha256=jCJVwd-3MNjejL9FyvH89pzt-SeG3G8qCJD16iTMJAQ,11454
28
28
  lightning_sdk/api/llm_api.py,sha256=GKQrk7Id_E4_Bp4j70ebSEgiB--iVrCd9SEA1D0VG2I,7180
29
29
  lightning_sdk/api/mmt_api.py,sha256=-v7ATab-ThAM-HRClS92Ehxuu9MlBfdKWWFCGvVUHiM,8962
@@ -64,7 +64,7 @@ lightning_sdk/cli/deploy/_auth.py,sha256=F3W2eU33LIsfFu7AQyBRN01BL800vJJFJCHwg0B
64
64
  lightning_sdk/cli/deploy/devbox.py,sha256=HOQMWehwaveawVTyBDaZhNZs_NL5g4RCWs_lf0hIW5U,6800
65
65
  lightning_sdk/cli/deploy/serve.py,sha256=qqml7oYf4IPcoiL13P2ly247_PQ8IGv-8hM2NBWePJc,14458
66
66
  lightning_sdk/deployment/__init__.py,sha256=dXsa4psDzFYFklsq3JC-2V_L4FQjGZnQAf-ZiVlqG9c,545
67
- lightning_sdk/deployment/deployment.py,sha256=Bdgbc7pKke2BnDd2eqJNGT34Q2XngCJznQojfXS_vRc,20116
67
+ lightning_sdk/deployment/deployment.py,sha256=BTAo--qbkLXuaUhTJIkWHiMmSJv4t5MNPEBB0T2wdkk,20627
68
68
  lightning_sdk/job/__init__.py,sha256=1MxjQ6rHkyUHCypSW9RuXuVMVH11WiqhIXcU2LCFMwE,64
69
69
  lightning_sdk/job/base.py,sha256=TS5KavtfBAFbLbNqqumEizY9edjO1joSmtUdcO5CThQ,17748
70
70
  lightning_sdk/job/job.py,sha256=1Xf0ne4wwXpkb_GJgWD8mfueJZoKR8G4lC5T6OXijlw,13075
@@ -1041,16 +1041,15 @@ lightning_sdk/lightning_cloud/utils/data_connection.py,sha256=esKg01F9vdb05fLUf0
1041
1041
  lightning_sdk/lightning_cloud/utils/dataset.py,sha256=4nUspe8iAaRPgSYpXA2uAQCgydm78kJzhOIx3C9qKls,2011
1042
1042
  lightning_sdk/lightning_cloud/utils/name_generator.py,sha256=MkciuA10332V0mcE2PxLIiwWomWE0Fm_gNGK01vwRr4,58046
1043
1043
  lightning_sdk/lightning_cloud/utils/network.py,sha256=axPgl8rhyPcPjxiztDxyksfxax3VNg2OXL5F5Uc81b4,406
1044
- lightning_sdk/llm/__init__.py,sha256=nTdp5J7hoCsfqKla18Ta9ixAVfl_XAFyXKMuTkWgRmY,117
1045
- lightning_sdk/llm/asyncllm.py,sha256=ERNm5PzdzuzwDWfkpd77B-C5TBpMqjedt9XPIoT2puI,1946
1046
- lightning_sdk/llm/llm.py,sha256=kS6NSDywqbhkkluxZYOaKSgBjxGm6xvwtwPUp0m1SsQ,10667
1044
+ lightning_sdk/llm/__init__.py,sha256=ErZva0HqN2iPtK_6hI6GN7A_HPGNrHo3wYh7vyFdO3Q,57
1045
+ lightning_sdk/llm/llm.py,sha256=cb3oXqX2-eEq3WK1pUFWbSD8GYGNvHCQYwJyak58vfo,12410
1047
1046
  lightning_sdk/mmt/__init__.py,sha256=ExMu90-96bGBnyp5h0CErQszUGB1-PcjC4-R8_NYbeY,117
1048
1047
  lightning_sdk/mmt/base.py,sha256=B3HC-c82bPHprEZh1mhLCPCrCE8BOKqwIhY7xCF9CXg,15152
1049
1048
  lightning_sdk/mmt/mmt.py,sha256=swdGP1DOM42a_QmmY1vg3--6ZBDiC4zToAzU9Eycv4U,13446
1050
1049
  lightning_sdk/mmt/v1.py,sha256=TxLtL0ssDoP8eyleDaFyYr4evkOKbLJcckLVIfalOno,8429
1051
1050
  lightning_sdk/mmt/v2.py,sha256=Em1XBoqViqUMKm-sshzdMcSH5UTtZZwbJcsgqY6-mw0,9625
1052
1051
  lightning_sdk/pipeline/__init__.py,sha256=uZS2v8HPGfNz2SrCCVrZ9EhihS3kd6aGtwJLbuaI3dA,167
1053
- lightning_sdk/pipeline/pipeline.py,sha256=CCRcHUjL24yKm24NMB5xzK1sre6bQ5sY07tMifmpqI0,3762
1052
+ lightning_sdk/pipeline/pipeline.py,sha256=-zNPzr8r32R4ciAL2bOS8vGXElZDe5lOYhdkZuHRswY,3762
1054
1053
  lightning_sdk/pipeline/types.py,sha256=HvBu4rtQfKFewXy3_MxE9OjCmVBlrGZzvrZJKqMZJFg,10578
1055
1054
  lightning_sdk/pipeline/utils.py,sha256=qOxvrYYw8XMd6aknGi5_FFxLvcPwNUuGaHoanx7TZXs,2655
1056
1055
  lightning_sdk/services/__init__.py,sha256=wi1yv0SCnfJub5tOq8y9SblK3-CEseHJuvH-HmtAy7U,229
@@ -1062,9 +1061,9 @@ lightning_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
1062
1061
  lightning_sdk/utils/dynamic.py,sha256=glUTO1JC9APtQ6Gr9SO02a3zr56-sPAXM5C3NrTpgyQ,1959
1063
1062
  lightning_sdk/utils/enum.py,sha256=h2JRzqoBcSlUdanFHmkj_j5DleBHAu1esQYUsdNI-hU,4106
1064
1063
  lightning_sdk/utils/resolve.py,sha256=6qlBUkOmcFTjhQx_CAGfnvWBbMYp6XrCV_sX_IqplLE,6748
1065
- lightning_sdk-0.2.21rc0.dist-info/LICENSE,sha256=uFIuZwj5z-4TeF2UuacPZ1o17HkvKObT8fY50qN84sg,1064
1066
- lightning_sdk-0.2.21rc0.dist-info/METADATA,sha256=r0pcAiTb5R12dc_B9wX9XtzUoOSmDhUSCLaGRhS6apY,3995
1067
- lightning_sdk-0.2.21rc0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1068
- lightning_sdk-0.2.21rc0.dist-info/entry_points.txt,sha256=msB9PJWIJ784dX-OP8by51d4IbKYH3Fj1vCuA9oXjHY,68
1069
- lightning_sdk-0.2.21rc0.dist-info/top_level.txt,sha256=ps8doKILFXmN7F1mHncShmnQoTxKBRPIcchC8TpoBw4,19
1070
- lightning_sdk-0.2.21rc0.dist-info/RECORD,,
1064
+ lightning_sdk-0.2.21rc1.dist-info/LICENSE,sha256=uFIuZwj5z-4TeF2UuacPZ1o17HkvKObT8fY50qN84sg,1064
1065
+ lightning_sdk-0.2.21rc1.dist-info/METADATA,sha256=24lp7VIkBYRgwZR9Gy999K2r-IdRZrd-AjN0ip87PUY,3995
1066
+ lightning_sdk-0.2.21rc1.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1067
+ lightning_sdk-0.2.21rc1.dist-info/entry_points.txt,sha256=msB9PJWIJ784dX-OP8by51d4IbKYH3Fj1vCuA9oXjHY,68
1068
+ lightning_sdk-0.2.21rc1.dist-info/top_level.txt,sha256=ps8doKILFXmN7F1mHncShmnQoTxKBRPIcchC8TpoBw4,19
1069
+ lightning_sdk-0.2.21rc1.dist-info/RECORD,,
@@ -1,48 +0,0 @@
1
- import os
2
- from typing import AsyncGenerator, Dict, List, Optional, Union
3
-
4
- from lightning_sdk.llm.llm import LLM
5
-
6
-
7
- class AsyncLLM(LLM):
8
- async def chat(
9
- self,
10
- prompt: str,
11
- system_prompt: Optional[str] = None,
12
- max_completion_tokens: Optional[int] = 500,
13
- images: Optional[Union[List[str], str]] = None,
14
- conversation: Optional[str] = None,
15
- metadata: Optional[Dict[str, str]] = None,
16
- stream: bool = False,
17
- upload_local_images: bool = False,
18
- ) -> Union[str, AsyncGenerator[str, None]]:
19
- if conversation and conversation not in self._conversations:
20
- self._get_conversations()
21
-
22
- if images:
23
- if isinstance(images, str):
24
- images = [images]
25
- for image in images:
26
- if not isinstance(image, str):
27
- raise NotImplementedError(f"Image type {type(image)} are not supported yet.")
28
- if not image.startswith("http") and upload_local_images:
29
- self._teamspace.upload_file(file_path=image, remote_path=f"images/{os.path.basename(image)}")
30
-
31
- conversation_id = self._conversations.get(conversation) if conversation else None
32
- output = await self._llm_api.async_start_conversation(
33
- prompt=prompt,
34
- system_prompt=system_prompt,
35
- max_completion_tokens=max_completion_tokens,
36
- images=images,
37
- assistant_id=self._model.id,
38
- conversation_id=conversation_id,
39
- billing_project_id=self._teamspace.id,
40
- metadata=metadata,
41
- name=conversation,
42
- stream=stream,
43
- )
44
- if not stream:
45
- if conversation and not conversation_id:
46
- self._conversations[conversation] = output.conversation_id
47
- return output.choices[0].delta.content
48
- return self._stream_chat_response(output, conversation=conversation)