Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"extensions": [
"ms-python.python"
],
"settings": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": ".venv/bin/python",
"python.defaultInterpreterPath": ".venv/bin/python",
Expand Down
44 changes: 3 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
lint:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/hyperspell-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
runs-on: ubuntu-latest
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand All @@ -40,8 +40,8 @@ jobs:
name: build
permissions:
contents: read
id-token: write
runs-on: ${{ github.repository == 'stainless-sdks/hyperspell-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}

runs-on: ubuntu-latest
Comment thread
entelligence-ai-pr-reviews[bot] marked this conversation as resolved.
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Expand All @@ -55,41 +55,3 @@ jobs:

- name: Run build
run: uv build

- name: Get GitHub OIDC Token
if: |-
github.repository == 'stainless-sdks/hyperspell-python' &&
!startsWith(github.ref, 'refs/heads/stl/')
id: github-oidc
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: core.setOutput('github_token', await core.getIDToken());

- name: Upload tarball
if: |-
github.repository == 'stainless-sdks/hyperspell-python' &&
!startsWith(github.ref, 'refs/heads/stl/')
env:
URL: https://pkg.stainless.com/s
AUTH: ${{ steps.github-oidc.outputs.github_token }}
SHA: ${{ github.sha }}
run: ./scripts/utils/upload-artifact.sh

test:
timeout-minutes: 10
name: test
runs-on: ${{ github.repository == 'stainless-sdks/hyperspell-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install uv
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
with:
version: '0.10.2'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test
25 changes: 25 additions & 0 deletions .github/workflows/sdk-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: SDK tests

on:
push:
branches: ['**']
pull_request:

jobs:
test:
name: test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install uv
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
with:
version: '0.10.2'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 31
configured_endpoints: 41
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import os
from hyperspell import Hyperspell

client = Hyperspell(
user_id="My User ID",
api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted
)

Expand All @@ -62,6 +63,7 @@ import asyncio
from hyperspell import AsyncHyperspell

client = AsyncHyperspell(
user_id="My User ID",
api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted
)

Expand Down Expand Up @@ -100,6 +102,7 @@ from hyperspell import AsyncHyperspell

async def main() -> None:
async with AsyncHyperspell(
user_id="My User ID",
api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted
http_client=DefaultAioHttpClient(),
) as client:
Expand Down Expand Up @@ -130,14 +133,16 @@ This library provides auto-paginating iterators with each list response, so you
```python
from hyperspell import Hyperspell

client = Hyperspell()
client = Hyperspell(
user_id="My User ID",
)

all_memories = []
all_context_documents = []
# Automatically fetches more pages as needed.
for memory in client.memories.list():
# Do something with memory here
all_memories.append(memory)
print(all_memories)
for context_document in client.context_documents.list():
# Do something with context_document here
all_context_documents.append(context_document)
print(all_context_documents)
```

Or, asynchronously:
Expand All @@ -146,15 +151,17 @@ Or, asynchronously:
import asyncio
from hyperspell import AsyncHyperspell

client = AsyncHyperspell()
client = AsyncHyperspell(
user_id="My User ID",
)


async def main() -> None:
all_memories = []
all_context_documents = []
# Iterate through items across all pages, issuing requests as needed.
async for memory in client.memories.list():
all_memories.append(memory)
print(all_memories)
async for context_document in client.context_documents.list():
all_context_documents.append(context_document)
print(all_context_documents)


asyncio.run(main())
Expand All @@ -163,23 +170,23 @@ asyncio.run(main())
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:

```python
first_page = await client.memories.list()
first_page = await client.context_documents.list()
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
print(f"number of items we just fetched: {len(next_page.items)}")
print(f"number of items we just fetched: {len(next_page.documents)}")

# Remove `await` for non-async usage.
```

Or just work directly with the returned data:

```python
first_page = await client.memories.list()
first_page = await client.context_documents.list()

print(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."
for memory in first_page.items:
print(memory.resource_id)
for context_document in first_page.documents:
print(context_document.document_id)

# Remove `await` for non-async usage.
```
Expand All @@ -191,13 +198,14 @@ Nested parameters are dictionaries, typed using `TypedDict`, for example:
```python
from hyperspell import Hyperspell

client = Hyperspell()
client = Hyperspell(
user_id="My User ID",
)

query_result = client.memories.search(
query="What does Hyperspell do?",
options={"filter": {}},
config = client.context_documents.config.update(
structure={},
)
print(query_result.options)
print(config.structure)
```

## File uploads
Expand All @@ -208,7 +216,9 @@ Request parameters that correspond to file uploads can be passed as `bytes`, or
from pathlib import Path
from hyperspell import Hyperspell

client = Hyperspell()
client = Hyperspell(
user_id="My User ID",
)

client.memories.upload(
file=Path("/path/to/file"),
Expand All @@ -230,7 +240,9 @@ All errors inherit from `hyperspell.APIError`.
import hyperspell
from hyperspell import Hyperspell

client = Hyperspell()
client = Hyperspell(
user_id="My User ID",
)

try:
client.memories.add(
Expand Down Expand Up @@ -273,6 +285,7 @@ from hyperspell import Hyperspell

# Configure the default for all requests:
client = Hyperspell(
user_id="My User ID",
# default is 2
max_retries=0,
)
Expand All @@ -293,12 +306,14 @@ from hyperspell import Hyperspell

# Configure the default for all requests:
client = Hyperspell(
user_id="My User ID",
# 20 seconds (default is 1 minute)
timeout=20.0,
)

# More granular control:
client = Hyperspell(
user_id="My User ID",
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
)

Expand Down Expand Up @@ -345,7 +360,9 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
```py
from hyperspell import Hyperspell

client = Hyperspell()
client = Hyperspell(
user_id="My User ID",
)
response = client.memories.with_raw_response.add(
text="...",
)
Expand Down Expand Up @@ -424,6 +441,7 @@ import httpx
from hyperspell import Hyperspell, DefaultHttpxClient

client = Hyperspell(
user_id="My User ID",
# Or use the `HYPERSPELL_BASE_URL` env var
base_url="http://my.test.server.example.com:8083",
http_client=DefaultHttpxClient(
Expand All @@ -446,7 +464,9 @@ By default the library closes underlying HTTP connections whenever the client is
```py
from hyperspell import Hyperspell

with Hyperspell() as client:
with Hyperspell(
user_id="My User ID",
) as client:
# make requests here
...

Expand Down
Loading
Loading