Skip to content

Commit 31d127f

Browse files
feat(api): api update
1 parent 03e3ffa commit 31d127f

17 files changed

+223
-306
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Create releases
2+
on:
3+
schedule:
4+
- cron: '0 5 * * *' # every day at 5am UTC
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
release:
11+
name: release
12+
if: github.ref == 'refs/heads/main' && github.repository == 'hyperspell/python-sdk'
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: stainless-api/trigger-release-please@v1
19+
id: release
20+
with:
21+
repo: ${{ github.event.repository.full_name }}
22+
stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}
23+
24+
- name: Install Rye
25+
if: ${{ steps.release.outputs.releases_created }}
26+
run: |
27+
curl -sSf https://rye.astral.sh/get | bash
28+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
29+
env:
30+
RYE_VERSION: '0.44.0'
31+
RYE_INSTALL_OPTION: '--yes'
32+
33+
- name: Publish to PyPI
34+
if: ${{ steps.release.outputs.releases_created }}
35+
run: |
36+
bash ./bin/publish-pypi
37+
env:
38+
PYPI_TOKEN: ${{ secrets.HYPERSPELL_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.github/workflows/publish-pypi.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
# This workflow is triggered when a GitHub release is created.
2-
# It can also be run manually to re-publish to PyPI in case it failed for some reason.
3-
# You can run this workflow by navigating to https://www.github.com/hyperspell/python-sdk/actions/workflows/publish-pypi.yml
1+
# workflow for re-running publishing to PyPI in case it fails for some reason
2+
# you can run this workflow by navigating to https://www.github.com/hyperspell/python-sdk/actions/workflows/publish-pypi.yml
43
name: Publish PyPI
54
on:
65
workflow_dispatch:
76

8-
release:
9-
types: [published]
10-
117
jobs:
128
publish:
139
name: publish

.github/workflows/release-doctor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ jobs:
1818
run: |
1919
bash ./bin/check-release-environment
2020
env:
21+
STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}
2122
PYPI_TOKEN: ${{ secrets.HYPERSPELL_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 10
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-036faa49b258b84e5e0b005039461bfc4942c718fb105444d863b9d7af2922f2.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-4e177b58fa8cf23ba450d5247fcad65a6bbe1921ae3d5d42180e496e40a9864f.yml

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ client = Hyperspell(
3232
)
3333

3434
document_status = client.documents.add(
35-
collection="collection",
3635
text="text",
3736
)
3837
print(document_status.id)
@@ -59,7 +58,6 @@ client = AsyncHyperspell(
5958

6059
async def main() -> None:
6160
document_status = await client.documents.add(
62-
collection="collection",
6361
text="text",
6462
)
6563
print(document_status.id)
@@ -163,12 +161,12 @@ from hyperspell import Hyperspell
163161
client = Hyperspell()
164162

165163
response = client.query.search(
166-
collections="string",
167164
query="query",
168165
filter={
169166
"end_date": parse_datetime("2019-12-27T18:11:19.117Z"),
170167
"source": ["generic"],
171168
"start_date": parse_datetime("2019-12-27T18:11:19.117Z"),
169+
"types": ["generic"],
172170
},
173171
)
174172
print(response.filter)
@@ -209,7 +207,6 @@ client = Hyperspell()
209207

210208
try:
211209
client.documents.add(
212-
collection="collection",
213210
text="text",
214211
)
215212
except hyperspell.APIConnectionError as e:
@@ -255,7 +252,6 @@ client = Hyperspell(
255252

256253
# Or, configure per-request:
257254
client.with_options(max_retries=5).documents.add(
258-
collection="collection",
259255
text="text",
260256
)
261257
```
@@ -281,7 +277,6 @@ client = Hyperspell(
281277

282278
# Override per-request:
283279
client.with_options(timeout=5.0).documents.add(
284-
collection="collection",
285280
text="text",
286281
)
287282
```
@@ -325,7 +320,6 @@ from hyperspell import Hyperspell
325320

326321
client = Hyperspell()
327322
response = client.documents.with_raw_response.add(
328-
collection="collection",
329323
text="text",
330324
)
331325
print(response.headers.get('X-My-Header'))
@@ -346,7 +340,6 @@ To stream the response body, use `.with_streaming_response` instead, which requi
346340

347341
```python
348342
with client.documents.with_streaming_response.add(
349-
collection="collection",
350343
text="text",
351344
) as response:
352345
print(response.headers.get("X-My-Header"))

bin/check-release-environment

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
errors=()
44

5+
if [ -z "${STAINLESS_API_KEY}" ]; then
6+
errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.")
7+
fi
8+
59
if [ -z "${PYPI_TOKEN}" ]; then
610
errors+=("The HYPERSPELL_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
711
fi

src/hyperspell/resources/documents.py

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def with_streaming_response(self) -> DocumentsResourceWithStreamingResponse:
6161
def list(
6262
self,
6363
*,
64-
collection: str,
64+
collection: Optional[str] | NotGiven = NOT_GIVEN,
6565
cursor: Optional[str] | NotGiven = NOT_GIVEN,
6666
size: int | NotGiven = NOT_GIVEN,
6767
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -108,27 +108,10 @@ def list(
108108
def add(
109109
self,
110110
*,
111-
collection: str,
112111
text: str,
112+
collection: Optional[str] | NotGiven = NOT_GIVEN,
113113
date: Union[str, datetime] | NotGiven = NOT_GIVEN,
114-
source: Literal[
115-
"generic",
116-
"markdown",
117-
"chat",
118-
"email",
119-
"transcript",
120-
"legal",
121-
"website",
122-
"image",
123-
"pdf",
124-
"audio",
125-
"slack",
126-
"s3",
127-
"gmail",
128-
"notion",
129-
"google_docs",
130-
]
131-
| NotGiven = NOT_GIVEN,
114+
source: Literal["generic", "slack", "s3", "gmail", "notion", "google_docs", "hubspot"] | NotGiven = NOT_GIVEN,
132115
title: Optional[str] | NotGiven = NOT_GIVEN,
133116
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
134117
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -144,11 +127,12 @@ def add(
144127
once the processing is complete.
145128
146129
Args:
147-
collection: Name of the collection to add the document to. If the collection does not exist,
148-
it will be created.
149-
150130
text: Full text of the document.
151131
132+
collection: Name of the collection to add the document to. If the collection does not exist,
133+
it will be created. If not given, the document will be added to the user's
134+
default collection.
135+
152136
date: Date of the document. Depending on the document, this could be the creation date
153137
or date the document was last updated (eg. for a chat transcript, this would be
154138
the date of the last message). This helps the ranking algorithm and allows you
@@ -171,8 +155,8 @@ def add(
171155
"/documents/add",
172156
body=maybe_transform(
173157
{
174-
"collection": collection,
175158
"text": text,
159+
"collection": collection,
176160
"date": date,
177161
"source": source,
178162
"title": title,
@@ -188,8 +172,8 @@ def add(
188172
def add_url(
189173
self,
190174
*,
191-
collection: str,
192175
url: str,
176+
collection: Optional[str] | NotGiven = NOT_GIVEN,
193177
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
194178
# The extra values given here take precedence over values defined on the client or passed to this method.
195179
extra_headers: Headers | None = None,
@@ -204,11 +188,12 @@ def add_url(
204188
once the processing is complete.
205189
206190
Args:
207-
collection: Name of the collection to add the document to. If the collection does not exist,
208-
it will be created.
209-
210191
url: Source URL of the document.
211192
193+
collection: Name of the collection to add the document to. If the collection does not exist,
194+
it will be created. If not given, the document will be added to the user's
195+
default collection.
196+
212197
extra_headers: Send extra headers
213198
214199
extra_query: Add additional query parameters to the request
@@ -221,8 +206,8 @@ def add_url(
221206
"/documents/scrape",
222207
body=maybe_transform(
223208
{
224-
"collection": collection,
225209
"url": url,
210+
"collection": collection,
226211
},
227212
document_add_url_params.DocumentAddURLParams,
228213
),
@@ -340,7 +325,7 @@ def with_streaming_response(self) -> AsyncDocumentsResourceWithStreamingResponse
340325
def list(
341326
self,
342327
*,
343-
collection: str,
328+
collection: Optional[str] | NotGiven = NOT_GIVEN,
344329
cursor: Optional[str] | NotGiven = NOT_GIVEN,
345330
size: int | NotGiven = NOT_GIVEN,
346331
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -387,27 +372,10 @@ def list(
387372
async def add(
388373
self,
389374
*,
390-
collection: str,
391375
text: str,
376+
collection: Optional[str] | NotGiven = NOT_GIVEN,
392377
date: Union[str, datetime] | NotGiven = NOT_GIVEN,
393-
source: Literal[
394-
"generic",
395-
"markdown",
396-
"chat",
397-
"email",
398-
"transcript",
399-
"legal",
400-
"website",
401-
"image",
402-
"pdf",
403-
"audio",
404-
"slack",
405-
"s3",
406-
"gmail",
407-
"notion",
408-
"google_docs",
409-
]
410-
| NotGiven = NOT_GIVEN,
378+
source: Literal["generic", "slack", "s3", "gmail", "notion", "google_docs", "hubspot"] | NotGiven = NOT_GIVEN,
411379
title: Optional[str] | NotGiven = NOT_GIVEN,
412380
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
413381
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -423,11 +391,12 @@ async def add(
423391
once the processing is complete.
424392
425393
Args:
426-
collection: Name of the collection to add the document to. If the collection does not exist,
427-
it will be created.
428-
429394
text: Full text of the document.
430395
396+
collection: Name of the collection to add the document to. If the collection does not exist,
397+
it will be created. If not given, the document will be added to the user's
398+
default collection.
399+
431400
date: Date of the document. Depending on the document, this could be the creation date
432401
or date the document was last updated (eg. for a chat transcript, this would be
433402
the date of the last message). This helps the ranking algorithm and allows you
@@ -450,8 +419,8 @@ async def add(
450419
"/documents/add",
451420
body=await async_maybe_transform(
452421
{
453-
"collection": collection,
454422
"text": text,
423+
"collection": collection,
455424
"date": date,
456425
"source": source,
457426
"title": title,
@@ -467,8 +436,8 @@ async def add(
467436
async def add_url(
468437
self,
469438
*,
470-
collection: str,
471439
url: str,
440+
collection: Optional[str] | NotGiven = NOT_GIVEN,
472441
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
473442
# The extra values given here take precedence over values defined on the client or passed to this method.
474443
extra_headers: Headers | None = None,
@@ -483,11 +452,12 @@ async def add_url(
483452
once the processing is complete.
484453
485454
Args:
486-
collection: Name of the collection to add the document to. If the collection does not exist,
487-
it will be created.
488-
489455
url: Source URL of the document.
490456
457+
collection: Name of the collection to add the document to. If the collection does not exist,
458+
it will be created. If not given, the document will be added to the user's
459+
default collection.
460+
491461
extra_headers: Send extra headers
492462
493463
extra_query: Add additional query parameters to the request
@@ -500,8 +470,8 @@ async def add_url(
500470
"/documents/scrape",
501471
body=await async_maybe_transform(
502472
{
503-
"collection": collection,
504473
"url": url,
474+
"collection": collection,
505475
},
506476
document_add_url_params.DocumentAddURLParams,
507477
),

0 commit comments

Comments
 (0)