Skip to content

Commit

Permalink
feat(api): OpenAPI spec update (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 9, 2024
1 parent dea31ce commit b2bbd21
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 44
configured_endpoints: 43
3 changes: 1 addition & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ Methods:
Types:

```python
from dataherald.types import SqlGenerationListResponse, SqlGenerationExecuteResponse
from dataherald.types import SqlGenerationListResponse
```

Methods:

- <code title="post /api/prompts/sql-generations">client.sql_generations.<a href="./src/dataherald/resources/sql_generations/sql_generations.py">create</a>(\*\*<a href="src/dataherald/types/sql_generation_create_params.py">params</a>) -> <a href="./src/dataherald/types/shared/sql_generation_response.py">SqlGenerationResponse</a></code>
- <code title="get /api/sql-generations/{id}">client.sql_generations.<a href="./src/dataherald/resources/sql_generations/sql_generations.py">retrieve</a>(id) -> <a href="./src/dataherald/types/shared/sql_generation_response.py">SqlGenerationResponse</a></code>
- <code title="get /api/sql-generations">client.sql_generations.<a href="./src/dataherald/resources/sql_generations/sql_generations.py">list</a>(\*\*<a href="src/dataherald/types/sql_generation_list_params.py">params</a>) -> <a href="./src/dataherald/types/sql_generation_list_response.py">SqlGenerationListResponse</a></code>
- <code title="post /api/sql-generations/{id}/execute">client.sql_generations.<a href="./src/dataherald/resources/sql_generations/sql_generations.py">execute</a>(id, \*\*<a href="src/dataherald/types/sql_generation_execute_params.py">params</a>) -> <a href="./src/dataherald/types/sql_generation_execute_response.py">SqlGenerationExecuteResponse</a></code>

## NlGenerations

Expand Down
4 changes: 4 additions & 0 deletions examples/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File generated from our OpenAPI spec by Stainless.

This directory can be used to store example files demonstrating usage of this SDK.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
41 changes: 19 additions & 22 deletions src/dataherald/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
Body,
Omit,
Query,
ModelT,
Headers,
Timeout,
NotGiven,
Expand All @@ -61,7 +60,6 @@
HttpxSendArgs,
AsyncTransport,
RequestOptions,
UnknownResponse,
ModelBuilderProtocol,
BinaryResponseContent,
)
Expand Down Expand Up @@ -142,7 +140,7 @@ def __init__(
self.params = params


class BasePage(GenericModel, Generic[ModelT]):
class BasePage(GenericModel, Generic[_T]):
"""
Defines the core interface for pagination.
Expand All @@ -155,7 +153,7 @@ class BasePage(GenericModel, Generic[ModelT]):
"""

_options: FinalRequestOptions = PrivateAttr()
_model: Type[ModelT] = PrivateAttr()
_model: Type[_T] = PrivateAttr()

def has_next_page(self) -> bool:
items = self._get_page_items()
Expand All @@ -166,7 +164,7 @@ def has_next_page(self) -> bool:
def next_page_info(self) -> Optional[PageInfo]:
...

def _get_page_items(self) -> Iterable[ModelT]: # type: ignore[empty-body]
def _get_page_items(self) -> Iterable[_T]: # type: ignore[empty-body]
...

def _params_from_url(self, url: URL) -> httpx.QueryParams:
Expand All @@ -191,13 +189,13 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions:
raise ValueError("Unexpected PageInfo state")


class BaseSyncPage(BasePage[ModelT], Generic[ModelT]):
class BaseSyncPage(BasePage[_T], Generic[_T]):
_client: SyncAPIClient = pydantic.PrivateAttr()

def _set_private_attributes(
self,
client: SyncAPIClient,
model: Type[ModelT],
model: Type[_T],
options: FinalRequestOptions,
) -> None:
self._model = model
Expand All @@ -212,7 +210,7 @@ def _set_private_attributes(
# methods should continue to work as expected as there is an alternative method
# to cast a model to a dictionary, model.dict(), which is used internally
# by pydantic.
def __iter__(self) -> Iterator[ModelT]: # type: ignore
def __iter__(self) -> Iterator[_T]: # type: ignore
for page in self.iter_pages():
for item in page._get_page_items():
yield item
Expand All @@ -237,13 +235,13 @@ def get_next_page(self: SyncPageT) -> SyncPageT:
return self._client._request_api_list(self._model, page=self.__class__, options=options)


class AsyncPaginator(Generic[ModelT, AsyncPageT]):
class AsyncPaginator(Generic[_T, AsyncPageT]):
def __init__(
self,
client: AsyncAPIClient,
options: FinalRequestOptions,
page_cls: Type[AsyncPageT],
model: Type[ModelT],
model: Type[_T],
) -> None:
self._model = model
self._client = client
Expand All @@ -266,7 +264,7 @@ def _parser(resp: AsyncPageT) -> AsyncPageT:

return await self._client.request(self._page_cls, self._options)

async def __aiter__(self) -> AsyncIterator[ModelT]:
async def __aiter__(self) -> AsyncIterator[_T]:
# https://github.com/microsoft/pyright/issues/3464
page = cast(
AsyncPageT,
Expand All @@ -276,20 +274,20 @@ async def __aiter__(self) -> AsyncIterator[ModelT]:
yield item


class BaseAsyncPage(BasePage[ModelT], Generic[ModelT]):
class BaseAsyncPage(BasePage[_T], Generic[_T]):
_client: AsyncAPIClient = pydantic.PrivateAttr()

def _set_private_attributes(
self,
model: Type[ModelT],
model: Type[_T],
client: AsyncAPIClient,
options: FinalRequestOptions,
) -> None:
self._model = model
self._client = client
self._options = options

async def __aiter__(self) -> AsyncIterator[ModelT]:
async def __aiter__(self) -> AsyncIterator[_T]:
async for page in self.iter_pages():
for item in page._get_page_items():
yield item
Expand Down Expand Up @@ -528,7 +526,7 @@ def _process_response_data(
if data is None:
return cast(ResponseT, None)

if cast_to is UnknownResponse:
if cast_to is object:
return cast(ResponseT, data)

try:
Expand Down Expand Up @@ -970,7 +968,7 @@ def _retry_request(

def _request_api_list(
self,
model: Type[ModelT],
model: Type[object],
page: Type[SyncPageT],
options: FinalRequestOptions,
) -> SyncPageT:
Expand Down Expand Up @@ -1132,7 +1130,7 @@ def get_api_list(
self,
path: str,
*,
model: Type[ModelT],
model: Type[object],
page: Type[SyncPageT],
body: Body | None = None,
options: RequestOptions = {},
Expand Down Expand Up @@ -1434,10 +1432,10 @@ async def _retry_request(

def _request_api_list(
self,
model: Type[ModelT],
model: Type[_T],
page: Type[AsyncPageT],
options: FinalRequestOptions,
) -> AsyncPaginator[ModelT, AsyncPageT]:
) -> AsyncPaginator[_T, AsyncPageT]:
return AsyncPaginator(client=self, options=options, page_cls=page, model=model)

@overload
Expand Down Expand Up @@ -1584,13 +1582,12 @@ def get_api_list(
self,
path: str,
*,
# TODO: support paginating `str`
model: Type[ModelT],
model: Type[_T],
page: Type[AsyncPageT],
body: Body | None = None,
options: RequestOptions = {},
method: str = "get",
) -> AsyncPaginator[ModelT, AsyncPageT]:
) -> AsyncPaginator[_T, AsyncPageT]:
opts = FinalRequestOptions.construct(method=method, url=path, json_data=body, **options)
return self._request_api_list(model, page, opts)

Expand Down
4 changes: 2 additions & 2 deletions src/dataherald/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import httpx

from ._types import NoneType, UnknownResponse, BinaryResponseContent
from ._types import NoneType, BinaryResponseContent
from ._utils import is_given, extract_type_var_from_base
from ._models import BaseModel, is_basemodel
from ._constants import RAW_RESPONSE_HEADER
Expand Down Expand Up @@ -162,7 +162,7 @@ def _parse(self) -> R:
# `ResponseT` TypeVar, however if that TypeVar is ever updated in the future, then
# this function would become unsafe but a type checker would not report an error.
if (
cast_to is not UnknownResponse
cast_to is not object
and not origin is list
and not origin is dict
and not origin is Union
Expand Down
17 changes: 11 additions & 6 deletions src/dataherald/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ class RequestOptions(TypedDict, total=False):
idempotency_key: str


# Sentinel class used when the response type is an object with an unknown schema
class UnknownResponse:
...


# Sentinel class used until PEP 0661 is accepted
class NotGiven:
"""
Expand Down Expand Up @@ -339,7 +334,17 @@ def get(self, __key: str) -> str | None:

ResponseT = TypeVar(
"ResponseT",
bound="Union[str, None, BaseModel, List[Any], Dict[str, Any], Response, UnknownResponse, ModelBuilderProtocol, BinaryResponseContent]",
bound=Union[
object,
str,
None,
"BaseModel",
List[Any],
Dict[str, Any],
Response,
ModelBuilderProtocol,
BinaryResponseContent,
],
)

StrBytesIntFloat = Union[str, bytes, int, float]
Expand Down
4 changes: 4 additions & 0 deletions src/dataherald/lib/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File generated from our OpenAPI spec by Stainless.

This directory can be used to store custom files to expand the SDK.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
database_connection_update_params,
)
from .drivers import Drivers, AsyncDrivers, DriversWithRawResponse, AsyncDriversWithRawResponse
from ..._types import (
NOT_GIVEN,
Body,
Query,
Headers,
NotGiven,
)
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._utils import maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
Expand Down
8 changes: 1 addition & 7 deletions src/dataherald/resources/database_connections/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

import httpx

from ..._types import (
NOT_GIVEN,
Body,
Query,
Headers,
NotGiven,
)
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper
Expand Down
13 changes: 3 additions & 10 deletions src/dataherald/resources/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@

import httpx

from .._types import (
NOT_GIVEN,
Body,
Query,
Headers,
NotGiven,
UnknownResponse,
)
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper
Expand Down Expand Up @@ -43,7 +36,7 @@ def heartbeat(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=UnknownResponse,
cast_to=object,
)


Expand All @@ -68,7 +61,7 @@ async def heartbeat(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=UnknownResponse,
cast_to=object,
)


Expand Down
20 changes: 9 additions & 11 deletions src/dataherald/resources/finetunings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
finetuning_list_params,
finetuning_create_params,
)
from .._types import (
NOT_GIVEN,
Body,
Query,
Headers,
NotGiven,
)
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
Expand All @@ -38,8 +32,9 @@ def with_raw_response(self) -> FinetuningsWithRawResponse:
def create(
self,
*,
base_llm: finetuning_create_params.BaseLlm,
db_connection_id: str,
alias: str | NotGiven = NOT_GIVEN,
base_llm: finetuning_create_params.BaseLlm | NotGiven = NOT_GIVEN,
golden_records: List[str] | NotGiven = NOT_GIVEN,
metadata: object | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -65,8 +60,9 @@ def create(
"/api/finetunings",
body=maybe_transform(
{
"base_llm": base_llm,
"db_connection_id": db_connection_id,
"alias": alias,
"base_llm": base_llm,
"golden_records": golden_records,
"metadata": metadata,
},
Expand Down Expand Up @@ -155,8 +151,9 @@ def with_raw_response(self) -> AsyncFinetuningsWithRawResponse:
async def create(
self,
*,
base_llm: finetuning_create_params.BaseLlm,
db_connection_id: str,
alias: str | NotGiven = NOT_GIVEN,
base_llm: finetuning_create_params.BaseLlm | NotGiven = NOT_GIVEN,
golden_records: List[str] | NotGiven = NOT_GIVEN,
metadata: object | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -182,8 +179,9 @@ async def create(
"/api/finetunings",
body=maybe_transform(
{
"base_llm": base_llm,
"db_connection_id": db_connection_id,
"alias": alias,
"base_llm": base_llm,
"golden_records": golden_records,
"metadata": metadata,
},
Expand Down
8 changes: 1 addition & 7 deletions src/dataherald/resources/generations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
generation_update_params,
generation_sql_generation_params,
)
from .._types import (
NOT_GIVEN,
Body,
Query,
Headers,
NotGiven,
)
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
Expand Down
Loading

0 comments on commit b2bbd21

Please sign in to comment.