lightning-sdk 0.2.13__py3-none-any.whl → 0.2.14__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 +1 -1
- lightning_sdk/api/llm_api.py +11 -0
- lightning_sdk/llm/llm.py +42 -0
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/METADATA +1 -1
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/RECORD +9 -9
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/LICENSE +0 -0
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/WHEEL +0 -0
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/entry_points.txt +0 -0
- {lightning_sdk-0.2.13.dist-info → lightning_sdk-0.2.14.dist-info}/top_level.txt +0 -0
lightning_sdk/__init__.py
CHANGED
lightning_sdk/api/llm_api.py
CHANGED
|
@@ -44,3 +44,14 @@ class LLMApi:
|
|
|
44
44
|
body["conversation_id"] = conversation_id
|
|
45
45
|
result = self._client.assistants_service_start_conversation(body, assistant_id)
|
|
46
46
|
return result.result
|
|
47
|
+
|
|
48
|
+
def list_conversations(self, assistant_id: str) -> List[str]:
|
|
49
|
+
result = self._client.assistants_service_list_conversations(assistant_id)
|
|
50
|
+
return result.conversations
|
|
51
|
+
|
|
52
|
+
def get_conversation(self, assistant_id: str, conversation_id: str) -> V1ConversationResponseChunk:
|
|
53
|
+
result = self._client.assistants_service_get_conversation(assistant_id, conversation_id)
|
|
54
|
+
return result.messages
|
|
55
|
+
|
|
56
|
+
def reset_conversation(self, assistant_id: str, conversation_id: str) -> None:
|
|
57
|
+
self._client.assistants_service_delete_conversation(assistant_id, conversation_id)
|
lightning_sdk/llm/llm.py
CHANGED
|
@@ -95,6 +95,14 @@ class LLM:
|
|
|
95
95
|
available_models_str = "\n".join(available_models)
|
|
96
96
|
raise ValueError(f"Model '{self._model_name}' not found. \nAvailable models: \n{available_models_str}")
|
|
97
97
|
|
|
98
|
+
def _get_conversations(self) -> Dict[str, str]:
|
|
99
|
+
# TODO: after updating backend, this will fetch conversations from backend
|
|
100
|
+
# conversations = self._llm_api.list_conversations(assistant_id=self._model.id)
|
|
101
|
+
return self._conversations
|
|
102
|
+
|
|
103
|
+
def _fetch_conversations(self) -> None:
|
|
104
|
+
self._conversations = self._get_conversations()
|
|
105
|
+
|
|
98
106
|
def chat(
|
|
99
107
|
self,
|
|
100
108
|
prompt: str,
|
|
@@ -102,6 +110,9 @@ class LLM:
|
|
|
102
110
|
max_completion_tokens: Optional[int] = 500,
|
|
103
111
|
conversation: Optional[str] = None,
|
|
104
112
|
) -> str:
|
|
113
|
+
if conversation and conversation not in self._conversations:
|
|
114
|
+
self._fetch_conversations()
|
|
115
|
+
|
|
105
116
|
conversation_id = self._conversations.get(conversation) if conversation else None
|
|
106
117
|
output = self._llm_api.start_conversation(
|
|
107
118
|
prompt=prompt,
|
|
@@ -115,4 +126,35 @@ class LLM:
|
|
|
115
126
|
return output.choices[0].delta.content
|
|
116
127
|
|
|
117
128
|
def list_conversations(self) -> List[Dict]:
|
|
129
|
+
self._fetch_conversations()
|
|
118
130
|
return list(self._conversations.keys())
|
|
131
|
+
|
|
132
|
+
def _get_conversation_messages(self, conversation_id: str) -> Optional[str]:
|
|
133
|
+
return self._llm_api.get_conversation(assistant_id=self._model.id, conversation_id=conversation_id)
|
|
134
|
+
|
|
135
|
+
def get_history(self, conversation: str) -> Optional[List[Dict]]:
|
|
136
|
+
# TODO: after updating backend, this will fetch conversation from backend
|
|
137
|
+
if conversation not in self._conversations:
|
|
138
|
+
self._fetch_conversations()
|
|
139
|
+
|
|
140
|
+
if conversation not in self._conversations:
|
|
141
|
+
raise ValueError(
|
|
142
|
+
f"Conversation '{conversation}' not found. \nAvailable conversations: {self._conversations.keys()}"
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
messages = self._get_conversation_messages(self._conversations[conversation])
|
|
146
|
+
history = []
|
|
147
|
+
for message in messages:
|
|
148
|
+
if message.author.role == "user":
|
|
149
|
+
history.append({"role": "user", "content": message.content[0].parts[0]})
|
|
150
|
+
elif message.author.role == "assistant":
|
|
151
|
+
history.append({"role": "assistant", "content": message.content[0].parts[0]})
|
|
152
|
+
return history
|
|
153
|
+
|
|
154
|
+
def reset_conversation(self, conversation: str) -> None:
|
|
155
|
+
if conversation in self._conversations:
|
|
156
|
+
self._llm_api.reset_conversation(
|
|
157
|
+
assistant_id=self._model.id,
|
|
158
|
+
conversation_id=self._conversations[conversation],
|
|
159
|
+
)
|
|
160
|
+
del self._conversations[conversation]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
docs/source/conf.py,sha256=r8yX20eC-4mHhMTd0SbQb5TlSWHhO6wnJ0VJ_FBFpag,13249
|
|
2
|
-
lightning_sdk/__init__.py,sha256=
|
|
2
|
+
lightning_sdk/__init__.py,sha256=5uT8otWW3sR7bBtcfzQlVQzvLN_jbk_TLePZWQ6NNOs,1105
|
|
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/constants.py,sha256=ztl1PTUBULnqTf3DyKUSJaV_O20hNtUYT6XvAYIrmIk,749
|
|
@@ -22,7 +22,7 @@ lightning_sdk/api/cluster_api.py,sha256=OxAhEdNt-9bYQ-u3MCADdVGsilXf2e7Wcxvb73Cm
|
|
|
22
22
|
lightning_sdk/api/deployment_api.py,sha256=8ZH2q08oc2jnPlPEBwZXmtv4DyHRZ9BnK1FxR_EztMA,24013
|
|
23
23
|
lightning_sdk/api/job_api.py,sha256=_mMAI_BG_48i-BLwCP_U72zgmM5zYa2KUZ7u66HWkIc,13568
|
|
24
24
|
lightning_sdk/api/lit_container_api.py,sha256=jCJVwd-3MNjejL9FyvH89pzt-SeG3G8qCJD16iTMJAQ,11454
|
|
25
|
-
lightning_sdk/api/llm_api.py,sha256=
|
|
25
|
+
lightning_sdk/api/llm_api.py,sha256=l98CRD0miK7vAr2VL_LhdStA70zWaUuNt9mBQmCUH5Q,2237
|
|
26
26
|
lightning_sdk/api/mmt_api.py,sha256=-v7ATab-ThAM-HRClS92Ehxuu9MlBfdKWWFCGvVUHiM,8962
|
|
27
27
|
lightning_sdk/api/org_api.py,sha256=Ze3z_ATVrukobujV5YdC42DKj45Vuwl7X52q_Vr-o3U,803
|
|
28
28
|
lightning_sdk/api/pipeline_api.py,sha256=P5P9C6qOpyBGU0t5N68h1LuFAsAKmPPgkac6uObrYKw,1676
|
|
@@ -999,7 +999,7 @@ lightning_sdk/lightning_cloud/utils/dataset.py,sha256=4nUspe8iAaRPgSYpXA2uAQCgyd
|
|
|
999
999
|
lightning_sdk/lightning_cloud/utils/name_generator.py,sha256=MkciuA10332V0mcE2PxLIiwWomWE0Fm_gNGK01vwRr4,58046
|
|
1000
1000
|
lightning_sdk/lightning_cloud/utils/network.py,sha256=axPgl8rhyPcPjxiztDxyksfxax3VNg2OXL5F5Uc81b4,406
|
|
1001
1001
|
lightning_sdk/llm/__init__.py,sha256=ErZva0HqN2iPtK_6hI6GN7A_HPGNrHo3wYh7vyFdO3Q,57
|
|
1002
|
-
lightning_sdk/llm/llm.py,sha256=
|
|
1002
|
+
lightning_sdk/llm/llm.py,sha256=RhdTcIXgV6Xg7osVa1yRgbp8Gxcu12hFwnouu4xuqTM,6542
|
|
1003
1003
|
lightning_sdk/mmt/__init__.py,sha256=ExMu90-96bGBnyp5h0CErQszUGB1-PcjC4-R8_NYbeY,117
|
|
1004
1004
|
lightning_sdk/mmt/base.py,sha256=B3HC-c82bPHprEZh1mhLCPCrCE8BOKqwIhY7xCF9CXg,15152
|
|
1005
1005
|
lightning_sdk/mmt/mmt.py,sha256=swdGP1DOM42a_QmmY1vg3--6ZBDiC4zToAzU9Eycv4U,13446
|
|
@@ -1017,9 +1017,9 @@ lightning_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
|
|
|
1017
1017
|
lightning_sdk/utils/dynamic.py,sha256=glUTO1JC9APtQ6Gr9SO02a3zr56-sPAXM5C3NrTpgyQ,1959
|
|
1018
1018
|
lightning_sdk/utils/enum.py,sha256=h2JRzqoBcSlUdanFHmkj_j5DleBHAu1esQYUsdNI-hU,4106
|
|
1019
1019
|
lightning_sdk/utils/resolve.py,sha256=6qlBUkOmcFTjhQx_CAGfnvWBbMYp6XrCV_sX_IqplLE,6748
|
|
1020
|
-
lightning_sdk-0.2.
|
|
1021
|
-
lightning_sdk-0.2.
|
|
1022
|
-
lightning_sdk-0.2.
|
|
1023
|
-
lightning_sdk-0.2.
|
|
1024
|
-
lightning_sdk-0.2.
|
|
1025
|
-
lightning_sdk-0.2.
|
|
1020
|
+
lightning_sdk-0.2.14.dist-info/LICENSE,sha256=uFIuZwj5z-4TeF2UuacPZ1o17HkvKObT8fY50qN84sg,1064
|
|
1021
|
+
lightning_sdk-0.2.14.dist-info/METADATA,sha256=bmhQYn6Gi59jOr7B_AboKowMqISbVM-riZ_efmogEd8,3992
|
|
1022
|
+
lightning_sdk-0.2.14.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
1023
|
+
lightning_sdk-0.2.14.dist-info/entry_points.txt,sha256=msB9PJWIJ784dX-OP8by51d4IbKYH3Fj1vCuA9oXjHY,68
|
|
1024
|
+
lightning_sdk-0.2.14.dist-info/top_level.txt,sha256=ps8doKILFXmN7F1mHncShmnQoTxKBRPIcchC8TpoBw4,19
|
|
1025
|
+
lightning_sdk-0.2.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|