Skip to content

Commit 1b33d5e

Browse files
feat(api): api update (#21)
1 parent 65f793b commit 1b33d5e

File tree

7 files changed

+92
-16
lines changed

7 files changed

+92
-16
lines changed

.stats.yml

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

src/hyperspell/resources/query.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def retrieve(
5151
*,
5252
query: str,
5353
collections: List[str] | NotGiven = NOT_GIVEN,
54+
filter: query_retrieve_params.Filter | NotGiven = NOT_GIVEN,
5455
max_results: int | NotGiven = NOT_GIVEN,
5556
query_type: Literal["auto", "semantic", "keyword"] | NotGiven = NOT_GIVEN,
5657
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -68,6 +69,8 @@ def retrieve(
6869
6970
collections: Only query documents in these collections.
7071
72+
filter: Filter the query results.
73+
7174
max_results: Maximum number of results to return.
7275
7376
query_type: Type of query to run.
@@ -86,6 +89,7 @@ def retrieve(
8689
{
8790
"query": query,
8891
"collections": collections,
92+
"filter": filter,
8993
"max_results": max_results,
9094
"query_type": query_type,
9195
},
@@ -123,6 +127,7 @@ async def retrieve(
123127
*,
124128
query: str,
125129
collections: List[str] | NotGiven = NOT_GIVEN,
130+
filter: query_retrieve_params.Filter | NotGiven = NOT_GIVEN,
126131
max_results: int | NotGiven = NOT_GIVEN,
127132
query_type: Literal["auto", "semantic", "keyword"] | NotGiven = NOT_GIVEN,
128133
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -140,6 +145,8 @@ async def retrieve(
140145
141146
collections: Only query documents in these collections.
142147
148+
filter: Filter the query results.
149+
143150
max_results: Maximum number of results to return.
144151
145152
query_type: Type of query to run.
@@ -158,6 +165,7 @@ async def retrieve(
158165
{
159166
"query": query,
160167
"collections": collections,
168+
"filter": filter,
161169
"max_results": max_results,
162170
"query_type": query_type,
163171
},

src/hyperspell/types/document.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,22 @@ class Document(BaseModel):
4242

4343
sections: Optional[List[Section]] = None
4444

45-
service: Optional[Literal["slack", "s3", "gmail", "notion", "google_docs", "api"]] = None
45+
source: Optional[
46+
Literal[
47+
"generic",
48+
"generic_chat",
49+
"generic_email",
50+
"generic_transcript",
51+
"generic_legal",
52+
"website",
53+
"slack",
54+
"s3",
55+
"gmail",
56+
"notion",
57+
"google_docs",
58+
]
59+
] = None
4660

4761
status: Optional[Literal["pending", "processing", "completed", "failed"]] = None
4862

4963
title: Optional[str] = None
50-
51-
type: Optional[Literal["chat", "email", "generic", "transcript", "legal"]] = None

src/hyperspell/types/document_list_params.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,25 @@ class Filter(TypedDict, total=False):
2929
chunk_type: List[Literal["text", "markdown", "table", "image", "messages", "message"]]
3030
"""Only query chunks of these types."""
3131

32-
document_type: List[Literal["chat", "email", "generic", "transcript", "legal"]]
33-
"""Only query documents of these types."""
34-
3532
end_date: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")]
3633
"""Only query documents before this date."""
3734

38-
provider: List[Literal["slack", "s3", "gmail", "notion", "google_docs", "api"]]
39-
"""Only query documents from these providers."""
35+
source: List[
36+
Literal[
37+
"generic",
38+
"generic_chat",
39+
"generic_email",
40+
"generic_transcript",
41+
"generic_legal",
42+
"website",
43+
"slack",
44+
"s3",
45+
"gmail",
46+
"notion",
47+
"google_docs",
48+
]
49+
]
50+
"""Only query documents of these types."""
4051

4152
start_date: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")]
4253
"""Only query documents on or after this date."""

src/hyperspell/types/query_retrieve_params.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import List
6-
from typing_extensions import Literal, Required, TypedDict
5+
from typing import List, Union
6+
from datetime import datetime
7+
from typing_extensions import Literal, Required, Annotated, TypedDict
78

8-
__all__ = ["QueryRetrieveParams"]
9+
from .._utils import PropertyInfo
10+
11+
__all__ = ["QueryRetrieveParams", "Filter"]
912

1013

1114
class QueryRetrieveParams(TypedDict, total=False):
@@ -15,8 +18,39 @@ class QueryRetrieveParams(TypedDict, total=False):
1518
collections: List[str]
1619
"""Only query documents in these collections."""
1720

21+
filter: Filter
22+
"""Filter the query results."""
23+
1824
max_results: int
1925
"""Maximum number of results to return."""
2026

2127
query_type: Literal["auto", "semantic", "keyword"]
2228
"""Type of query to run."""
29+
30+
31+
class Filter(TypedDict, total=False):
32+
chunk_type: List[Literal["text", "markdown", "table", "image", "messages", "message"]]
33+
"""Only query chunks of these types."""
34+
35+
end_date: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")]
36+
"""Only query documents before this date."""
37+
38+
source: List[
39+
Literal[
40+
"generic",
41+
"generic_chat",
42+
"generic_email",
43+
"generic_transcript",
44+
"generic_legal",
45+
"website",
46+
"slack",
47+
"s3",
48+
"gmail",
49+
"notion",
50+
"google_docs",
51+
]
52+
]
53+
"""Only query documents of these types."""
54+
55+
start_date: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")]
56+
"""Only query documents on or after this date."""

tests/api_resources/test_documents.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ def test_method_list_with_all_params(self, client: Hyperspell) -> None:
6262
collections=[0],
6363
filter={
6464
"chunk_type": ["text"],
65-
"document_type": ["chat"],
6665
"end_date": parse_datetime("2019-12-27T18:11:19.117Z"),
67-
"provider": ["slack"],
66+
"source": ["generic"],
6867
"start_date": parse_datetime("2019-12-27T18:11:19.117Z"),
6968
},
7069
limit=0,
@@ -144,9 +143,8 @@ async def test_method_list_with_all_params(self, async_client: AsyncHyperspell)
144143
collections=[0],
145144
filter={
146145
"chunk_type": ["text"],
147-
"document_type": ["chat"],
148146
"end_date": parse_datetime("2019-12-27T18:11:19.117Z"),
149-
"provider": ["slack"],
147+
"source": ["generic"],
150148
"start_date": parse_datetime("2019-12-27T18:11:19.117Z"),
151149
},
152150
limit=0,

tests/api_resources/test_query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from hyperspell import Hyperspell, AsyncHyperspell
1111
from tests.utils import assert_matches_type
12+
from hyperspell._utils import parse_datetime
1213

1314
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
1415

@@ -28,6 +29,12 @@ def test_method_retrieve_with_all_params(self, client: Hyperspell) -> None:
2829
query = client.query.retrieve(
2930
query="query",
3031
collections=["string"],
32+
filter={
33+
"chunk_type": ["text"],
34+
"end_date": parse_datetime("2019-12-27T18:11:19.117Z"),
35+
"source": ["generic"],
36+
"start_date": parse_datetime("2019-12-27T18:11:19.117Z"),
37+
},
3138
max_results=0,
3239
query_type="auto",
3340
)
@@ -73,6 +80,12 @@ async def test_method_retrieve_with_all_params(self, async_client: AsyncHyperspe
7380
query = await async_client.query.retrieve(
7481
query="query",
7582
collections=["string"],
83+
filter={
84+
"chunk_type": ["text"],
85+
"end_date": parse_datetime("2019-12-27T18:11:19.117Z"),
86+
"source": ["generic"],
87+
"start_date": parse_datetime("2019-12-27T18:11:19.117Z"),
88+
},
7689
max_results=0,
7790
query_type="auto",
7891
)

0 commit comments

Comments
 (0)