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 .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 41
configured_endpoints: 36
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ client = Hyperspell(
user_id="My User ID",
)

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

Or, asynchronously:
Expand All @@ -157,11 +157,11 @@ client = AsyncHyperspell(


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


asyncio.run(main())
Expand All @@ -170,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.context_documents.list()
first_page = await client.entities.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.documents)}")
print(f"number of items we just fetched: {len(next_page.items)}")

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

Or just work directly with the returned data:

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

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

# Remove `await` for non-async usage.
```
Expand All @@ -202,10 +202,11 @@ client = Hyperspell(
user_id="My User ID",
)

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

## File uploads
Expand Down
65 changes: 15 additions & 50 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,74 +108,39 @@ Methods:

- <code title="get /integrations/web_crawler/index">client.integrations.web_crawler.<a href="./src/hyperspell/resources/integrations/web_crawler.py">index</a>(\*\*<a href="src/hyperspell/types/integrations/web_crawler_index_params.py">params</a>) -> <a href="./src/hyperspell/types/integrations/web_crawler_index_response.py">WebCrawlerIndexResponse</a></code>

# ContextDocuments
# Entities

Types:

```python
from hyperspell.types import (
ContextDocumentListResponse,
ContextDocumentGenerateResponse,
ContextDocumentGetResponse,
)
```

Methods:

- <code title="get /context-documents">client.context_documents.<a href="./src/hyperspell/resources/context_documents/context_documents.py">list</a>(\*\*<a href="src/hyperspell/types/context_document_list_params.py">params</a>) -> <a href="./src/hyperspell/types/context_document_list_response.py">SyncContextDocumentsCursorPage[ContextDocumentListResponse]</a></code>
- <code title="post /context-documents/generate">client.context_documents.<a href="./src/hyperspell/resources/context_documents/context_documents.py">generate</a>(\*\*<a href="src/hyperspell/types/context_document_generate_params.py">params</a>) -> <a href="./src/hyperspell/types/context_document_generate_response.py">ContextDocumentGenerateResponse</a></code>
- <code title="get /context-documents/{document_id}">client.context_documents.<a href="./src/hyperspell/resources/context_documents/context_documents.py">get</a>(document_id) -> <a href="./src/hyperspell/types/context_document_get_response.py">ContextDocumentGetResponse</a></code>

## Trees

Types:

```python
from hyperspell.types.context_documents import (
TreeGenerateResponse,
TreeGetResponse,
TreeGetLatestResponse,
TreeProgressResponse,
)
from hyperspell.types import EntityListResponse, EntityGetResponse, EntitySearchResponse
```

Methods:

- <code title="post /context-documents/tree">client.context_documents.trees.<a href="./src/hyperspell/resources/context_documents/trees.py">generate</a>(\*\*<a href="src/hyperspell/types/context_documents/tree_generate_params.py">params</a>) -> <a href="./src/hyperspell/types/context_documents/tree_generate_response.py">TreeGenerateResponse</a></code>
- <code title="get /context-documents/tree/by-id/{tree_id}">client.context_documents.trees.<a href="./src/hyperspell/resources/context_documents/trees.py">get</a>(tree_id) -> <a href="./src/hyperspell/types/context_documents/tree_get_response.py">TreeGetResponse</a></code>
- <code title="get /context-documents/tree/latest">client.context_documents.trees.<a href="./src/hyperspell/resources/context_documents/trees.py">get_latest</a>(\*\*<a href="src/hyperspell/types/context_documents/tree_get_latest_params.py">params</a>) -> <a href="./src/hyperspell/types/context_documents/tree_get_latest_response.py">TreeGetLatestResponse</a></code>
- <code title="get /context-documents/tree/{tree_id}/progress">client.context_documents.trees.<a href="./src/hyperspell/resources/context_documents/trees.py">progress</a>(tree_id) -> <a href="./src/hyperspell/types/context_documents/tree_progress_response.py">TreeProgressResponse</a></code>
- <code title="get /entities">client.entities.<a href="./src/hyperspell/resources/entities.py">list</a>(\*\*<a href="src/hyperspell/types/entity_list_params.py">params</a>) -> <a href="./src/hyperspell/types/entity_list_response.py">SyncEntityCursorPage[EntityListResponse]</a></code>
- <code title="get /entities/{entity_id}">client.entities.<a href="./src/hyperspell/resources/entities.py">get</a>(entity_id) -> <a href="./src/hyperspell/types/entity_get_response.py">EntityGetResponse</a></code>
- <code title="post /entities/search">client.entities.<a href="./src/hyperspell/resources/entities.py">search</a>(\*\*<a href="src/hyperspell/types/entity_search_params.py">params</a>) -> <a href="./src/hyperspell/types/entity_search_response.py">EntitySearchResponse</a></code>

## Digests
# Live

Types:

```python
from hyperspell.types.context_documents import DigestListResponse, DigestGenerateResponse
```

Methods:

- <code title="get /context-documents/digest/list">client.context_documents.digests.<a href="./src/hyperspell/resources/context_documents/digests.py">list</a>(\*\*<a href="src/hyperspell/types/context_documents/digest_list_params.py">params</a>) -> <a href="./src/hyperspell/types/context_documents/digest_list_response.py">DigestListResponse</a></code>
- <code title="post /context-documents/digest">client.context_documents.digests.<a href="./src/hyperspell/resources/context_documents/digests.py">generate</a>(\*\*<a href="src/hyperspell/types/context_documents/digest_generate_params.py">params</a>) -> <a href="./src/hyperspell/types/context_documents/digest_generate_response.py">DigestGenerateResponse</a></code>

## Config

Types:

```python
from hyperspell.types.context_documents import (
ConfigUpdateResponse,
ConfigGetResponse,
ConfigResetResponse,
from hyperspell.types import (
LiveGetResourceResponse,
LiveListResourcesResponse,
LiveListSourcesResponse,
LiveSearchResponse,
)
```

Methods:

- <code title="patch /context-documents/config">client.context_documents.config.<a href="./src/hyperspell/resources/context_documents/config.py">update</a>(\*\*<a href="src/hyperspell/types/context_documents/config_update_params.py">params</a>) -> <a href="./src/hyperspell/types/context_documents/config_update_response.py">ConfigUpdateResponse</a></code>
- <code title="get /context-documents/config">client.context_documents.config.<a href="./src/hyperspell/resources/context_documents/config.py">get</a>() -> <a href="./src/hyperspell/types/context_documents/config_get_response.py">ConfigGetResponse</a></code>
- <code title="post /context-documents/config/reset">client.context_documents.config.<a href="./src/hyperspell/resources/context_documents/config.py">reset</a>() -> <a href="./src/hyperspell/types/context_documents/config_reset_response.py">ConfigResetResponse</a></code>
- <code title="get /live/{source}/resources/{resource_id}">client.live.<a href="./src/hyperspell/resources/live.py">get_resource</a>(resource_id, \*, source, \*\*<a href="src/hyperspell/types/live_get_resource_params.py">params</a>) -> <a href="./src/hyperspell/types/live_get_resource_response.py">LiveGetResourceResponse</a></code>
- <code title="get /live/{source}/resources">client.live.<a href="./src/hyperspell/resources/live.py">list_resources</a>(source, \*\*<a href="src/hyperspell/types/live_list_resources_params.py">params</a>) -> <a href="./src/hyperspell/types/live_list_resources_response.py">SyncCursorPage[LiveListResourcesResponse]</a></code>
- <code title="get /live/sources">client.live.<a href="./src/hyperspell/resources/live.py">list_sources</a>() -> <a href="./src/hyperspell/types/live_list_sources_response.py">LiveListSourcesResponse</a></code>
- <code title="post /live/{source}/search">client.live.<a href="./src/hyperspell/resources/live.py">search</a>(source, \*\*<a href="src/hyperspell/types/live_search_params.py">params</a>) -> <a href="./src/hyperspell/types/live_search_response.py">LiveSearchResponse</a></code>

# Memories

Expand Down
2 changes: 1 addition & 1 deletion scripts/mock

Large diffs are not rendered by default.

78 changes: 58 additions & 20 deletions src/hyperspell/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@
if TYPE_CHECKING:
from .resources import (
auth,
live,
vaults,
actions,
folders,
entities,
evaluate,
memories,
sessions,
connections,
integrations,
context_documents,
)
from .resources.auth import AuthResource, AsyncAuthResource
from .resources.live import LiveResource, AsyncLiveResource
from .resources.vaults import VaultsResource, AsyncVaultsResource
from .resources.actions import ActionsResource, AsyncActionsResource
from .resources.folders import FoldersResource, AsyncFoldersResource
from .resources.entities import EntitiesResource, AsyncEntitiesResource
from .resources.evaluate import EvaluateResource, AsyncEvaluateResource
from .resources.memories import MemoriesResource, AsyncMemoriesResource
from .resources.sessions import SessionsResource, AsyncSessionsResource
from .resources.connections import ConnectionsResource, AsyncConnectionsResource
from .resources.integrations.integrations import IntegrationsResource, AsyncIntegrationsResource
from .resources.context_documents.context_documents import ContextDocumentsResource, AsyncContextDocumentsResource

__all__ = [
"Timeout",
Expand Down Expand Up @@ -157,10 +159,16 @@ def integrations(self) -> IntegrationsResource:
return IntegrationsResource(self)

@cached_property
def context_documents(self) -> ContextDocumentsResource:
from .resources.context_documents import ContextDocumentsResource
def entities(self) -> EntitiesResource:
from .resources.entities import EntitiesResource

return ContextDocumentsResource(self)
return EntitiesResource(self)

@cached_property
def live(self) -> LiveResource:
from .resources.live import LiveResource

return LiveResource(self)

@cached_property
def memories(self) -> MemoriesResource:
Expand Down Expand Up @@ -401,10 +409,16 @@ def integrations(self) -> AsyncIntegrationsResource:
return AsyncIntegrationsResource(self)

@cached_property
def context_documents(self) -> AsyncContextDocumentsResource:
from .resources.context_documents import AsyncContextDocumentsResource
def entities(self) -> AsyncEntitiesResource:
from .resources.entities import AsyncEntitiesResource

return AsyncContextDocumentsResource(self)
return AsyncEntitiesResource(self)

@cached_property
def live(self) -> AsyncLiveResource:
from .resources.live import AsyncLiveResource

return AsyncLiveResource(self)

@cached_property
def memories(self) -> AsyncMemoriesResource:
Expand Down Expand Up @@ -583,10 +597,16 @@ def integrations(self) -> integrations.IntegrationsResourceWithRawResponse:
return IntegrationsResourceWithRawResponse(self._client.integrations)

@cached_property
def context_documents(self) -> context_documents.ContextDocumentsResourceWithRawResponse:
from .resources.context_documents import ContextDocumentsResourceWithRawResponse
def entities(self) -> entities.EntitiesResourceWithRawResponse:
from .resources.entities import EntitiesResourceWithRawResponse

return EntitiesResourceWithRawResponse(self._client.entities)

@cached_property
def live(self) -> live.LiveResourceWithRawResponse:
from .resources.live import LiveResourceWithRawResponse

return ContextDocumentsResourceWithRawResponse(self._client.context_documents)
return LiveResourceWithRawResponse(self._client.live)

@cached_property
def memories(self) -> memories.MemoriesResourceWithRawResponse:
Expand Down Expand Up @@ -650,10 +670,16 @@ def integrations(self) -> integrations.AsyncIntegrationsResourceWithRawResponse:
return AsyncIntegrationsResourceWithRawResponse(self._client.integrations)

@cached_property
def context_documents(self) -> context_documents.AsyncContextDocumentsResourceWithRawResponse:
from .resources.context_documents import AsyncContextDocumentsResourceWithRawResponse
def entities(self) -> entities.AsyncEntitiesResourceWithRawResponse:
from .resources.entities import AsyncEntitiesResourceWithRawResponse

return AsyncContextDocumentsResourceWithRawResponse(self._client.context_documents)
return AsyncEntitiesResourceWithRawResponse(self._client.entities)

@cached_property
def live(self) -> live.AsyncLiveResourceWithRawResponse:
from .resources.live import AsyncLiveResourceWithRawResponse

return AsyncLiveResourceWithRawResponse(self._client.live)

@cached_property
def memories(self) -> memories.AsyncMemoriesResourceWithRawResponse:
Expand Down Expand Up @@ -717,10 +743,16 @@ def integrations(self) -> integrations.IntegrationsResourceWithStreamingResponse
return IntegrationsResourceWithStreamingResponse(self._client.integrations)

@cached_property
def context_documents(self) -> context_documents.ContextDocumentsResourceWithStreamingResponse:
from .resources.context_documents import ContextDocumentsResourceWithStreamingResponse
def entities(self) -> entities.EntitiesResourceWithStreamingResponse:
from .resources.entities import EntitiesResourceWithStreamingResponse

return ContextDocumentsResourceWithStreamingResponse(self._client.context_documents)
return EntitiesResourceWithStreamingResponse(self._client.entities)

@cached_property
def live(self) -> live.LiveResourceWithStreamingResponse:
from .resources.live import LiveResourceWithStreamingResponse

return LiveResourceWithStreamingResponse(self._client.live)

@cached_property
def memories(self) -> memories.MemoriesResourceWithStreamingResponse:
Expand Down Expand Up @@ -784,10 +816,16 @@ def integrations(self) -> integrations.AsyncIntegrationsResourceWithStreamingRes
return AsyncIntegrationsResourceWithStreamingResponse(self._client.integrations)

@cached_property
def context_documents(self) -> context_documents.AsyncContextDocumentsResourceWithStreamingResponse:
from .resources.context_documents import AsyncContextDocumentsResourceWithStreamingResponse
def entities(self) -> entities.AsyncEntitiesResourceWithStreamingResponse:
from .resources.entities import AsyncEntitiesResourceWithStreamingResponse

return AsyncEntitiesResourceWithStreamingResponse(self._client.entities)

@cached_property
def live(self) -> live.AsyncLiveResourceWithStreamingResponse:
from .resources.live import AsyncLiveResourceWithStreamingResponse

return AsyncContextDocumentsResourceWithStreamingResponse(self._client.context_documents)
return AsyncLiveResourceWithStreamingResponse(self._client.live)

@cached_property
def memories(self) -> memories.AsyncMemoriesResourceWithStreamingResponse:
Expand Down
22 changes: 11 additions & 11 deletions src/hyperspell/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage

__all__ = ["SyncCursorPage", "AsyncCursorPage", "SyncContextDocumentsCursorPage", "AsyncContextDocumentsCursorPage"]
__all__ = ["SyncCursorPage", "AsyncCursorPage", "SyncEntityCursorPage", "AsyncEntityCursorPage"]

_T = TypeVar("_T")

Expand Down Expand Up @@ -50,16 +50,16 @@ def next_page_info(self) -> Optional[PageInfo]:
return PageInfo(params={"cursor": next_cursor})


class SyncContextDocumentsCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
documents: List[_T]
class SyncEntityCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
next_cursor: Optional[str] = None

@override
def _get_page_items(self) -> List[_T]:
documents = self.documents
if not documents:
items = self.items
if not items:
return []
return documents
return items

@override
def next_page_info(self) -> Optional[PageInfo]:
Expand All @@ -70,16 +70,16 @@ def next_page_info(self) -> Optional[PageInfo]:
return PageInfo(params={"cursor": next_cursor})


class AsyncContextDocumentsCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
documents: List[_T]
class AsyncEntityCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
next_cursor: Optional[str] = None

@override
def _get_page_items(self) -> List[_T]:
documents = self.documents
if not documents:
items = self.items
if not items:
return []
return documents
return items

@override
def next_page_info(self) -> Optional[PageInfo]:
Expand Down
Loading
Loading