itzam 1.0.0__py3-none-any.whl → 1.1.0__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.
- itzam/__init__.py +4 -2
- itzam/objects/__init__.py +4 -0
- itzam/objects/client.py +70 -0
- itzam/objects/models.py +9 -0
- {itzam-1.0.0.dist-info → itzam-1.1.0.dist-info}/METADATA +7 -1
- {itzam-1.0.0.dist-info → itzam-1.1.0.dist-info}/RECORD +8 -5
- {itzam-1.0.0.dist-info → itzam-1.1.0.dist-info}/WHEEL +0 -0
- {itzam-1.0.0.dist-info → itzam-1.1.0.dist-info}/top_level.txt +0 -0
itzam/__init__.py
CHANGED
@@ -14,10 +14,11 @@ response = client.text.generate(
|
|
14
14
|
print(response.text)
|
15
15
|
```
|
16
16
|
"""
|
17
|
-
from .text
|
17
|
+
from .text import TextClient
|
18
18
|
from .threads import ThreadsClient
|
19
19
|
from .runs import RunsClient
|
20
20
|
from .models import ModelsClient
|
21
|
+
from .objects import ObjectsClient
|
21
22
|
import dotenv, os
|
22
23
|
|
23
24
|
class Itzam:
|
@@ -37,4 +38,5 @@ class Itzam:
|
|
37
38
|
self.text = TextClient(base_url=base_url, api_key=api_key)
|
38
39
|
self.threads = ThreadsClient(base_url=base_url, api_key=api_key)
|
39
40
|
self.runs = RunsClient(base_url=base_url, api_key=api_key)
|
40
|
-
self.models = ModelsClient(base_url=base_url, api_key=api_key)
|
41
|
+
self.models = ModelsClient(base_url=base_url, api_key=api_key)
|
42
|
+
self.objects = ObjectsClient(base_url=base_url, api_key=api_key)
|
itzam/objects/client.py
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
from ..base.client import BaseClient
|
2
|
+
from ..text import Attachment
|
3
|
+
from .models import Response
|
4
|
+
import json
|
5
|
+
|
6
|
+
class ObjectsClient(BaseClient):
|
7
|
+
"""
|
8
|
+
Client for interacting with the Itzam API's objects endpoint.
|
9
|
+
This client provides methods to manage and interact with objects in the Itzam system.
|
10
|
+
"""
|
11
|
+
|
12
|
+
def __init__(self, base_url: str, api_key: str):
|
13
|
+
"""
|
14
|
+
Initialize the ObjectsClient with the base URL and API key.
|
15
|
+
|
16
|
+
:param base_url: The base URL for the Itzam API.
|
17
|
+
:param api_key: The API key for authentication.
|
18
|
+
"""
|
19
|
+
super().__init__(base_url=base_url, api_key=api_key)
|
20
|
+
|
21
|
+
def generate(
|
22
|
+
self,
|
23
|
+
input: str,
|
24
|
+
schema: dict,
|
25
|
+
workflow_slug: str | None = None,
|
26
|
+
thread_id: str | None = None,
|
27
|
+
attachments: list[Attachment] = None,
|
28
|
+
stream: bool = False
|
29
|
+
):
|
30
|
+
"""
|
31
|
+
Generate text using the specified model and prompt.
|
32
|
+
If stream=True, returns a generator yielding text deltas.
|
33
|
+
"""
|
34
|
+
if not workflow_slug and not thread_id:
|
35
|
+
raise ValueError("Either 'thread_id' or 'worflow_slug' must be provided.")
|
36
|
+
endpoint = "/api/v1/generate/object"
|
37
|
+
|
38
|
+
data = {
|
39
|
+
"input": input,
|
40
|
+
"schema": schema,
|
41
|
+
}
|
42
|
+
if workflow_slug:
|
43
|
+
data["workflowSlug"] = workflow_slug
|
44
|
+
if thread_id:
|
45
|
+
data["threadId"] = thread_id
|
46
|
+
if attachments:
|
47
|
+
data["attachments"] = [attachment.model_dump() for attachment in attachments]
|
48
|
+
|
49
|
+
if stream == True:
|
50
|
+
return self._stream_object("/api/v1/stream/object", data)
|
51
|
+
else:
|
52
|
+
response = self.request(method="POST", endpoint=endpoint, data=data)
|
53
|
+
return Response.model_validate(response.json())
|
54
|
+
|
55
|
+
def _stream_object(self, endpoint, data):
|
56
|
+
"""
|
57
|
+
Internal method to handle streaming text responses.
|
58
|
+
Yields text deltas as they arrive.
|
59
|
+
"""
|
60
|
+
response = self.request(method="POST", endpoint=endpoint, data=data, stream=True)
|
61
|
+
for line in response.iter_lines():
|
62
|
+
if line:
|
63
|
+
try:
|
64
|
+
event = json.loads(line.decode("utf-8").removeprefix("data: "))
|
65
|
+
if event.get("type") == "text-delta":
|
66
|
+
yield event.get("textDelta")
|
67
|
+
elif event.get("type") == "object":
|
68
|
+
yield str(event.get("object"))
|
69
|
+
except Exception as e:
|
70
|
+
continue
|
itzam/objects/models.py
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
from pydantic import BaseModel, Field
|
2
|
+
from ..text import ResponseMetadata
|
3
|
+
|
4
|
+
class Response(BaseModel):
|
5
|
+
"""
|
6
|
+
Represents the response from the object generation API.
|
7
|
+
"""
|
8
|
+
metadata: ResponseMetadata = Field(description="Metadata about the generation process")
|
9
|
+
object: dict = Field(description="The generated object based on the schema provided")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: itzam
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: Python SDK to interact with Itzam's API
|
5
5
|
Author-email: Joaquim Cassano <joaquim@cassano.com.br>
|
6
6
|
Requires-Python: <4.0,>=3.10
|
@@ -9,6 +9,8 @@ Requires-Dist: pydantic
|
|
9
9
|
Requires-Dist: requests
|
10
10
|
Requires-Dist: rich
|
11
11
|
|
12
|
+

|
13
|
+

|
12
14
|
# Itzam python sdk
|
13
15
|

|
14
16
|
|
@@ -59,6 +61,10 @@ client = Itzam()
|
|
59
61
|
- **Runs**: Inspect previous runs and their metadata.
|
60
62
|
|
61
63
|
## Usage Examples
|
64
|
+
### See available models
|
65
|
+
```shell
|
66
|
+
python3 -m itzam.models
|
67
|
+
```
|
62
68
|
|
63
69
|
### Generate Text
|
64
70
|
|
@@ -1,10 +1,13 @@
|
|
1
|
-
itzam/__init__.py,sha256=
|
1
|
+
itzam/__init__.py,sha256=EF_ElsUjkMlHLTFz5AqLrtBfWMTntXQ6xUNGlVD-sfI,1383
|
2
2
|
itzam/base/__init__.py,sha256=DalvyyupMefIabAm2Zr08bJEgMe_4YW18wZAghz9ng4,98
|
3
3
|
itzam/base/client.py,sha256=PoZ8qfSVOSKFEqQmspr0EcOdFHWHUkaAZryxJ7xrhYg,1395
|
4
4
|
itzam/models/__init__.py,sha256=zQnpPpnTxv1UN1nryKH0IbUPMRJj_-Z6GhIgT0Z0Dk8,69
|
5
5
|
itzam/models/__main__.py,sha256=A5m-oX_MYktOObynqzFNpzwzhFM-s7d3Dn0q_OP0l4I,868
|
6
6
|
itzam/models/client.py,sha256=oyzZbsbNTtQaEapiP-RPBgevBWeYDPwZ_hMmrjpGsoE,568
|
7
7
|
itzam/models/models.py,sha256=exr_ZgRSkERB_0-gJaWfYYcGxwa3dnVx69TkEbGrDzo,329
|
8
|
+
itzam/objects/__init__.py,sha256=mtOAakOo6jOcmRgEC1CY5whHB5H40XQwetKFSbbJRUY,103
|
9
|
+
itzam/objects/client.py,sha256=UOwohJtffDEb96V4MPELu95SzASJ1TceTqfKi9-cRGA,2515
|
10
|
+
itzam/objects/models.py,sha256=RPBq5geEUiuZbzHmL7HGbUWuBw-Kjjgjk3cjIkB-bys,359
|
8
11
|
itzam/runs/__init__.py,sha256=krE8QnjXNZ-lhVAVnHh7kTSMiXJdCEJc1Jm7iu57A4k,63
|
9
12
|
itzam/runs/client.py,sha256=zgjCUghl4-a_FwYWOFe6n1hbX0kv66G2IS0XHxcz8w4,527
|
10
13
|
itzam/runs/models.py,sha256=feYO8lljmwoOk3IY1zXlZ_rZRYev890V1iQwbrVL6rs,828
|
@@ -15,7 +18,7 @@ itzam/threads/__init__.py,sha256=-JGYGwOaiiozh3f-PWKZKIKWMN8WY4Wj1Y1SWbV74CA,109
|
|
15
18
|
itzam/threads/client.py,sha256=jXALIcUhiNi4kdmQNf3BGD_WjDGeXHSVknZ41tNwAi8,1816
|
16
19
|
itzam/threads/models.py,sha256=RYgiDmm9hsgJbuI88Zu3MGfNhmsE7-UMokrs7P9-Y1Y,829
|
17
20
|
itzam/utils/exceptions.py,sha256=Zmxn-ZQjNFwRqHFKTg2uxQf53f7cKi2sgbj65XXIHuE,5749
|
18
|
-
itzam-1.
|
19
|
-
itzam-1.
|
20
|
-
itzam-1.
|
21
|
-
itzam-1.
|
21
|
+
itzam-1.1.0.dist-info/METADATA,sha256=avVuH3ndReAlSYNDLWtP2AsqDp1OG7zNcniUjH6JwKo,2614
|
22
|
+
itzam-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
itzam-1.1.0.dist-info/top_level.txt,sha256=krzAg5bkN3qcDdhHvmUgpOOWct4KcdpwbfeR-p-QHJE,6
|
24
|
+
itzam-1.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|