Skip to content

Commit caa70f7

Browse files
docs(sdk): make embeddings example first
1 parent 5d4a1b9 commit caa70f7

File tree

3 files changed

+91
-88
lines changed

3 files changed

+91
-88
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 4
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/isaacus%2Fisaacus-ee884a4336559147aacf9a927a540f21e9760f00d2d5588af00fa8a25e2707d9.yml
33
openapi_spec_hash: 2ba78bd360942c63a7d08dba791f00d2
4-
config_hash: efa2ea406c5ecd6883ff8b0fb428e579
4+
config_hash: a85580968a69d8d6fadf96e5e2d6870e

README.md

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ client = Isaacus(
3232
api_key=os.environ.get("ISAACUS_API_KEY"), # This is the default and can be omitted
3333
)
3434

35-
universal_classification_response = client.classifications.universal.create(
36-
model="kanon-universal-classifier",
37-
query="This is a confidentiality clause.",
38-
texts=["I agree not to tell anyone about the document."],
35+
embedding_response = client.embeddings.create(
36+
model="kanon-2-embedder",
37+
texts=[
38+
"Are restraints of trade enforceable under English law?",
39+
"What is a non-compete clause?",
40+
],
3941
)
40-
print(universal_classification_response.classifications)
42+
print(embedding_response.embeddings)
4143
```
4244

4345
While you can provide an `api_key` keyword argument,
@@ -60,12 +62,14 @@ client = AsyncIsaacus(
6062

6163

6264
async def main() -> None:
63-
universal_classification_response = await client.classifications.universal.create(
64-
model="kanon-universal-classifier",
65-
query="This is a confidentiality clause.",
66-
texts=["I agree not to tell anyone about the document."],
65+
embedding_response = await client.embeddings.create(
66+
model="kanon-2-embedder",
67+
texts=[
68+
"Are restraints of trade enforceable under English law?",
69+
"What is a non-compete clause?",
70+
],
6771
)
68-
print(universal_classification_response.classifications)
72+
print(embedding_response.embeddings)
6973

7074

7175
asyncio.run(main())
@@ -97,12 +101,14 @@ async def main() -> None:
97101
api_key="My API Key",
98102
http_client=DefaultAioHttpClient(),
99103
) as client:
100-
universal_classification_response = await client.classifications.universal.create(
101-
model="kanon-universal-classifier",
102-
query="This is a confidentiality clause.",
103-
texts=["I agree not to tell anyone about the document."],
104+
embedding_response = await client.embeddings.create(
105+
model="kanon-2-embedder",
106+
texts=[
107+
"Are restraints of trade enforceable under English law?",
108+
"What is a non-compete clause?",
109+
],
104110
)
105-
print(universal_classification_response.classifications)
111+
print(embedding_response.embeddings)
106112

107113

108114
asyncio.run(main())
@@ -155,10 +161,12 @@ from isaacus import Isaacus
155161
client = Isaacus()
156162

157163
try:
158-
client.classifications.universal.create(
159-
model="kanon-universal-classifier",
160-
query="This is a confidentiality clause.",
161-
texts=["I agree not to tell anyone about the document."],
164+
client.embeddings.create(
165+
model="kanon-2-embedder",
166+
texts=[
167+
"Are restraints of trade enforceable under English law?",
168+
"What is a non-compete clause?",
169+
],
162170
)
163171
except isaacus.APIConnectionError as e:
164172
print("The server could not be reached")
@@ -202,10 +210,12 @@ client = Isaacus(
202210
)
203211

204212
# Or, configure per-request:
205-
client.with_options(max_retries=5).classifications.universal.create(
206-
model="kanon-universal-classifier",
207-
query="This is a confidentiality clause.",
208-
texts=["I agree not to tell anyone about the document."],
213+
client.with_options(max_retries=5).embeddings.create(
214+
model="kanon-2-embedder",
215+
texts=[
216+
"Are restraints of trade enforceable under English law?",
217+
"What is a non-compete clause?",
218+
],
209219
)
210220
```
211221

@@ -229,10 +239,12 @@ client = Isaacus(
229239
)
230240

231241
# Override per-request:
232-
client.with_options(timeout=5.0).classifications.universal.create(
233-
model="kanon-universal-classifier",
234-
query="This is a confidentiality clause.",
235-
texts=["I agree not to tell anyone about the document."],
242+
client.with_options(timeout=5.0).embeddings.create(
243+
model="kanon-2-embedder",
244+
texts=[
245+
"Are restraints of trade enforceable under English law?",
246+
"What is a non-compete clause?",
247+
],
236248
)
237249
```
238250

@@ -274,15 +286,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
274286
from isaacus import Isaacus
275287

276288
client = Isaacus()
277-
response = client.classifications.universal.with_raw_response.create(
278-
model="kanon-universal-classifier",
279-
query="This is a confidentiality clause.",
280-
texts=["I agree not to tell anyone about the document."],
289+
response = client.embeddings.with_raw_response.create(
290+
model="kanon-2-embedder",
291+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
281292
)
282293
print(response.headers.get('X-My-Header'))
283294

284-
universal = response.parse() # get the object that `classifications.universal.create()` would have returned
285-
print(universal.classifications)
295+
embedding = response.parse() # get the object that `embeddings.create()` would have returned
296+
print(embedding.embeddings)
286297
```
287298

288299
These methods return an [`APIResponse`](https://github.com/isaacus-dev/isaacus-python/tree/main/src/isaacus/_response.py) object.
@@ -296,10 +307,12 @@ The above interface eagerly reads the full response body when you make the reque
296307
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
297308

298309
```python
299-
with client.classifications.universal.with_streaming_response.create(
300-
model="kanon-universal-classifier",
301-
query="This is a confidentiality clause.",
302-
texts=["I agree not to tell anyone about the document."],
310+
with client.embeddings.with_streaming_response.create(
311+
model="kanon-2-embedder",
312+
texts=[
313+
"Are restraints of trade enforceable under English law?",
314+
"What is a non-compete clause?",
315+
],
303316
) as response:
304317
print(response.headers.get("X-My-Header"))
305318

tests/test_client.py

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -712,27 +712,25 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
712712
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
713713
@pytest.mark.respx(base_url=base_url)
714714
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None:
715-
respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error"))
715+
respx_mock.post("/embeddings").mock(side_effect=httpx.TimeoutException("Test timeout error"))
716716

717717
with pytest.raises(APITimeoutError):
718-
client.classifications.universal.with_streaming_response.create(
719-
model="kanon-universal-classifier",
720-
query="This is a confidentiality clause.",
721-
texts=["I agree not to tell anyone about the document."],
718+
client.embeddings.with_streaming_response.create(
719+
model="kanon-2-embedder",
720+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
722721
).__enter__()
723722

724723
assert _get_open_connections(self.client) == 0
725724

726725
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
727726
@pytest.mark.respx(base_url=base_url)
728727
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None:
729-
respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500))
728+
respx_mock.post("/embeddings").mock(return_value=httpx.Response(500))
730729

731730
with pytest.raises(APIStatusError):
732-
client.classifications.universal.with_streaming_response.create(
733-
model="kanon-universal-classifier",
734-
query="This is a confidentiality clause.",
735-
texts=["I agree not to tell anyone about the document."],
731+
client.embeddings.with_streaming_response.create(
732+
model="kanon-2-embedder",
733+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
736734
).__enter__()
737735
assert _get_open_connections(self.client) == 0
738736

@@ -760,12 +758,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
760758
return httpx.Response(500)
761759
return httpx.Response(200)
762760

763-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
761+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
764762

765-
response = client.classifications.universal.with_raw_response.create(
766-
model="kanon-universal-classifier",
767-
query="This is a confidentiality clause.",
768-
texts=["I agree not to tell anyone about the document."],
763+
response = client.embeddings.with_raw_response.create(
764+
model="kanon-2-embedder",
765+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
769766
)
770767

771768
assert response.retries_taken == failures_before_success
@@ -788,12 +785,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
788785
return httpx.Response(500)
789786
return httpx.Response(200)
790787

791-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
788+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
792789

793-
response = client.classifications.universal.with_raw_response.create(
794-
model="kanon-universal-classifier",
795-
query="This is a confidentiality clause.",
796-
texts=["I agree not to tell anyone about the document."],
790+
response = client.embeddings.with_raw_response.create(
791+
model="kanon-2-embedder",
792+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
797793
extra_headers={"x-stainless-retry-count": Omit()},
798794
)
799795

@@ -816,12 +812,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
816812
return httpx.Response(500)
817813
return httpx.Response(200)
818814

819-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
815+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
820816

821-
response = client.classifications.universal.with_raw_response.create(
822-
model="kanon-universal-classifier",
823-
query="This is a confidentiality clause.",
824-
texts=["I agree not to tell anyone about the document."],
817+
response = client.embeddings.with_raw_response.create(
818+
model="kanon-2-embedder",
819+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
825820
extra_headers={"x-stainless-retry-count": "42"},
826821
)
827822

@@ -1551,27 +1546,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15511546
async def test_retrying_timeout_errors_doesnt_leak(
15521547
self, respx_mock: MockRouter, async_client: AsyncIsaacus
15531548
) -> None:
1554-
respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error"))
1549+
respx_mock.post("/embeddings").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15551550

15561551
with pytest.raises(APITimeoutError):
1557-
await async_client.classifications.universal.with_streaming_response.create(
1558-
model="kanon-universal-classifier",
1559-
query="This is a confidentiality clause.",
1560-
texts=["I agree not to tell anyone about the document."],
1552+
await async_client.embeddings.with_streaming_response.create(
1553+
model="kanon-2-embedder",
1554+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
15611555
).__aenter__()
15621556

15631557
assert _get_open_connections(self.client) == 0
15641558

15651559
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15661560
@pytest.mark.respx(base_url=base_url)
15671561
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncIsaacus) -> None:
1568-
respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500))
1562+
respx_mock.post("/embeddings").mock(return_value=httpx.Response(500))
15691563

15701564
with pytest.raises(APIStatusError):
1571-
await async_client.classifications.universal.with_streaming_response.create(
1572-
model="kanon-universal-classifier",
1573-
query="This is a confidentiality clause.",
1574-
texts=["I agree not to tell anyone about the document."],
1565+
await async_client.embeddings.with_streaming_response.create(
1566+
model="kanon-2-embedder",
1567+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
15751568
).__aenter__()
15761569
assert _get_open_connections(self.client) == 0
15771570

@@ -1600,12 +1593,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16001593
return httpx.Response(500)
16011594
return httpx.Response(200)
16021595

1603-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
1596+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
16041597

1605-
response = await client.classifications.universal.with_raw_response.create(
1606-
model="kanon-universal-classifier",
1607-
query="This is a confidentiality clause.",
1608-
texts=["I agree not to tell anyone about the document."],
1598+
response = await client.embeddings.with_raw_response.create(
1599+
model="kanon-2-embedder",
1600+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
16091601
)
16101602

16111603
assert response.retries_taken == failures_before_success
@@ -1629,12 +1621,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16291621
return httpx.Response(500)
16301622
return httpx.Response(200)
16311623

1632-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
1624+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
16331625

1634-
response = await client.classifications.universal.with_raw_response.create(
1635-
model="kanon-universal-classifier",
1636-
query="This is a confidentiality clause.",
1637-
texts=["I agree not to tell anyone about the document."],
1626+
response = await client.embeddings.with_raw_response.create(
1627+
model="kanon-2-embedder",
1628+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
16381629
extra_headers={"x-stainless-retry-count": Omit()},
16391630
)
16401631

@@ -1658,12 +1649,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16581649
return httpx.Response(500)
16591650
return httpx.Response(200)
16601651

1661-
respx_mock.post("/classifications/universal").mock(side_effect=retry_handler)
1652+
respx_mock.post("/embeddings").mock(side_effect=retry_handler)
16621653

1663-
response = await client.classifications.universal.with_raw_response.create(
1664-
model="kanon-universal-classifier",
1665-
query="This is a confidentiality clause.",
1666-
texts=["I agree not to tell anyone about the document."],
1654+
response = await client.embeddings.with_raw_response.create(
1655+
model="kanon-2-embedder",
1656+
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
16671657
extra_headers={"x-stainless-retry-count": "42"},
16681658
)
16691659

0 commit comments

Comments
 (0)