codemie-sdk-python 0.1.79__py3-none-any.whl → 0.1.81__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 codemie-sdk-python might be problematic. Click here for more details.
- codemie_sdk/models/assistant.py +9 -2
- codemie_sdk/services/assistant.py +14 -1
- {codemie_sdk_python-0.1.79.dist-info → codemie_sdk_python-0.1.81.dist-info}/METADATA +46 -3
- {codemie_sdk_python-0.1.79.dist-info → codemie_sdk_python-0.1.81.dist-info}/RECORD +5 -5
- {codemie_sdk_python-0.1.79.dist-info → codemie_sdk_python-0.1.81.dist-info}/WHEEL +0 -0
codemie_sdk/models/assistant.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import uuid
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from enum import Enum
|
|
6
|
-
from typing import List, Optional, Any, Union, Dict
|
|
6
|
+
from typing import List, Optional, Any, Union, Dict, Type
|
|
7
7
|
|
|
8
8
|
from pydantic import BaseModel, Field, ConfigDict, model_validator
|
|
9
9
|
|
|
@@ -227,12 +227,19 @@ class AssistantChatRequest(BaseModel):
|
|
|
227
227
|
default=None, description="Provide additional metadata"
|
|
228
228
|
)
|
|
229
229
|
tools_config: Optional[List[ToolConfig]] = None
|
|
230
|
+
output_schema: Optional[dict | Type[BaseModel]] = Field(
|
|
231
|
+
default=None,
|
|
232
|
+
description="Structured output schema for the agent. \
|
|
233
|
+
If specified, `generated` field in response will have the same type",
|
|
234
|
+
)
|
|
230
235
|
|
|
231
236
|
|
|
232
237
|
class BaseModelResponse(BaseModel):
|
|
233
238
|
"""Model for chat response from assistant."""
|
|
234
239
|
|
|
235
|
-
generated: str = Field(
|
|
240
|
+
generated: str | dict | BaseModel = Field(
|
|
241
|
+
description="Generated response. If output_schema in request is specified, corresponds with its type"
|
|
242
|
+
)
|
|
236
243
|
time_elapsed: Optional[float] = Field(
|
|
237
244
|
default=None, alias="timeElapsed", description="Time taken for generation"
|
|
238
245
|
)
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import json
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import List, Union, Optional, Dict, Any, Literal
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
from copy import deepcopy
|
|
6
8
|
|
|
7
9
|
import requests
|
|
8
10
|
|
|
@@ -180,12 +182,23 @@ class AssistantService:
|
|
|
180
182
|
Returns:
|
|
181
183
|
Chat response or streaming response
|
|
182
184
|
"""
|
|
183
|
-
|
|
185
|
+
pydantic_schema = None
|
|
186
|
+
if issubclass(request.output_schema, BaseModel):
|
|
187
|
+
pydantic_schema = deepcopy(request.output_schema)
|
|
188
|
+
request.output_schema = request.output_schema.model_json_schema()
|
|
189
|
+
|
|
190
|
+
response = self._api.post(
|
|
184
191
|
f"/v1/assistants/{assistant_id}/model",
|
|
185
192
|
BaseModelResponse,
|
|
186
193
|
json_data=request.model_dump(exclude_none=True, by_alias=True),
|
|
187
194
|
stream=request.stream,
|
|
188
195
|
)
|
|
196
|
+
if not request.stream and pydantic_schema:
|
|
197
|
+
# we do conversion to the BaseModel here because self._parse_response don't see actual request model,
|
|
198
|
+
# where reflected desired output format for structured output
|
|
199
|
+
response.generated = pydantic_schema.model_validate(response.generated)
|
|
200
|
+
|
|
201
|
+
return response
|
|
189
202
|
|
|
190
203
|
def upload_file_to_chat(self, file_path: Path):
|
|
191
204
|
"""Upload a file to assistant chat and return the response containing file_url."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: codemie-sdk-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.81
|
|
4
4
|
Summary: CodeMie SDK for Python
|
|
5
5
|
Author: Vadym Vlasenko
|
|
6
6
|
Author-email: vadym_vlasenko@epam.com
|
|
@@ -182,7 +182,50 @@ chat_request = AssistantChatRequest(
|
|
|
182
182
|
response = client.assistant.chat("assistant-id", chat_request)
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
7. **
|
|
185
|
+
7. **Utilize structured outputs with Assistant**
|
|
186
|
+
```python
|
|
187
|
+
from pydantic import BaseModel
|
|
188
|
+
|
|
189
|
+
class OutputSchema(BaseModel):
|
|
190
|
+
requirements: list[str]
|
|
191
|
+
|
|
192
|
+
chat_request = AssistantChatRequest(
|
|
193
|
+
text="Your message here",
|
|
194
|
+
stream=False,
|
|
195
|
+
output_schema=OutputSchema
|
|
196
|
+
# Additional parameters
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
response = client.assistants.chat("id", chat_request)
|
|
200
|
+
# response.generated is a Pydantic object
|
|
201
|
+
```
|
|
202
|
+
Or using JSON schema in dict format
|
|
203
|
+
```python
|
|
204
|
+
output_schema = {
|
|
205
|
+
"properties": {
|
|
206
|
+
"requirements": {
|
|
207
|
+
"items": {"type": "string"},
|
|
208
|
+
"title": "Requirements",
|
|
209
|
+
"type": "array",
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"required": ["requirements"],
|
|
213
|
+
"title": "OutputSchema",
|
|
214
|
+
"type": "object",
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
chat_request = AssistantChatRequest(
|
|
218
|
+
text="Your message here",
|
|
219
|
+
stream=False,
|
|
220
|
+
output_schema=output_schema
|
|
221
|
+
# Additional parameters
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
response = client.assistants.chat("id", chat_request)
|
|
225
|
+
# response.generated is a dict corresponded with JSON schema
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
8. **Work with Prebuilt Assistants**
|
|
186
229
|
```python
|
|
187
230
|
# List prebuilt assistants
|
|
188
231
|
prebuilt = client.assistant.get_prebuilt()
|
|
@@ -191,7 +234,7 @@ prebuilt = client.assistant.get_prebuilt()
|
|
|
191
234
|
prebuilt_assistant = client.assistant.get_prebuilt_by_slug("assistant-slug")
|
|
192
235
|
```
|
|
193
236
|
|
|
194
|
-
|
|
237
|
+
9. **Get Available Tools**
|
|
195
238
|
```python
|
|
196
239
|
tools = client.assistant.get_tools()
|
|
197
240
|
```
|
|
@@ -5,7 +5,7 @@ codemie_sdk/client/__init__.py,sha256=yf6C39MmrJ6gK9ZHMhBeynKwUUYVSUTQbKxU8-4qpK
|
|
|
5
5
|
codemie_sdk/client/client.py,sha256=dVcWqd-ruWd8GOZ3_33C3LnHgUyyxIoCKxKYPYbBPq8,4373
|
|
6
6
|
codemie_sdk/exceptions.py,sha256=XoVPyognx-JmyVxLHkZPAcX1CMi1OoT1diBFJLU54so,1183
|
|
7
7
|
codemie_sdk/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
codemie_sdk/models/assistant.py,sha256=
|
|
8
|
+
codemie_sdk/models/assistant.py,sha256=qIRJgM0cR_xjFbDLQ8yPypRXD-tJUqt2Ny47WffrXOo,8852
|
|
9
9
|
codemie_sdk/models/common.py,sha256=gmZ-ps8TbaieNKr0kUKoQEjhVrHD2CAYomOpZQRatH8,1195
|
|
10
10
|
codemie_sdk/models/datasource.py,sha256=u6X1xXZ3ZR9CWH0B0bSw3IjC7KyEwtRKHIc6ZuhJwsg,10813
|
|
11
11
|
codemie_sdk/models/integration.py,sha256=c2D7QsM9HJ9zpupkjKz1v60rtBMGgTyJLYXUyAzS5no,2240
|
|
@@ -14,7 +14,7 @@ codemie_sdk/models/task.py,sha256=J4ZFRY3s8qBGrqB5NLQF0rMbInLh4s7OEZ0ZfmnW0Ho,14
|
|
|
14
14
|
codemie_sdk/models/user.py,sha256=Q0rjimZh-IbeaPfq6b6fk6ZaCtwLqWHEIlU863suCS4,1777
|
|
15
15
|
codemie_sdk/models/workflow.py,sha256=h3ZM-2bBucRd9CzZUYDTU0rGR1ihEN7cxkHgQmJfJVc,2394
|
|
16
16
|
codemie_sdk/models/workflow_state.py,sha256=CMYFQZ7sy4QxmnWmc83TFfqP7TG_3rW5MdH5fxsS9kY,1251
|
|
17
|
-
codemie_sdk/services/assistant.py,sha256=
|
|
17
|
+
codemie_sdk/services/assistant.py,sha256=4El_J_fPsj5OR4bN7EnmsNY9n02TLxt4uSw8s4b7J_s,7660
|
|
18
18
|
codemie_sdk/services/datasource.py,sha256=gIP9D-sq4733x9f0mWL87bMI1pWYxIsv5eYXkAs0O6Q,7150
|
|
19
19
|
codemie_sdk/services/integration.py,sha256=CrUfO-4_JwtCt8Qig3RP2uTi1uaTkedyTaPdkFY509g,5410
|
|
20
20
|
codemie_sdk/services/llm.py,sha256=0-e4_7RvLHs2giCyoQ5U4KDTh6p5VXgPKNxnDP9ZDFU,1100
|
|
@@ -25,6 +25,6 @@ codemie_sdk/services/workflow_execution.py,sha256=aGoT3rdTmh5-doAsrmBBjLEuOfvL5a
|
|
|
25
25
|
codemie_sdk/services/workflow_execution_state.py,sha256=tXoaa8yT09xgYEUNiHhVULe76TwGwVgZupMIUyyLxdo,2070
|
|
26
26
|
codemie_sdk/utils/__init__.py,sha256=BXAJJfAzO89-kMYvWWo9wSNhSbGgF3vB1In9sePFhMM,109
|
|
27
27
|
codemie_sdk/utils/http.py,sha256=YzE53y1r7PBUKcEQt-gGYduRY06I8xzqVRzlj9f_voA,10084
|
|
28
|
-
codemie_sdk_python-0.1.
|
|
29
|
-
codemie_sdk_python-0.1.
|
|
30
|
-
codemie_sdk_python-0.1.
|
|
28
|
+
codemie_sdk_python-0.1.81.dist-info/METADATA,sha256=-Dx6Pf-_kjlOIpA0kccg5dLStF8PP6hhndQH3UHyV0A,23146
|
|
29
|
+
codemie_sdk_python-0.1.81.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
30
|
+
codemie_sdk_python-0.1.81.dist-info/RECORD,,
|
|
File without changes
|