diff --git a/README.md b/README.md index 37f2d205..18f23d35 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,14 @@ from arcade_engine import ArcadeEngine client = ArcadeEngine() -chat_response = client.llm_completions.create() +chat_response = client.chat.completions() print(chat_response.id) ``` -While you can provide a `bearer_token` keyword argument, +While you can provide an `api_key` keyword argument, we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/) -to add `BEARER_TOKEN="My Bearer Token"` to your `.env` file -so that your Bearer Token is not stored in source control. +to add `ARCADE_API_KEY="My API Key"` to your `.env` file +so that your API Key is not stored in source control. ## Async usage @@ -52,7 +52,7 @@ client = AsyncArcadeEngine() async def main() -> None: - chat_response = await client.llm_completions.create() + chat_response = await client.chat.completions() print(chat_response.id) @@ -86,7 +86,7 @@ from arcade_engine import ArcadeEngine client = ArcadeEngine() try: - client.llm_completions.create() + client.chat.completions() except arcade_engine.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx. @@ -129,7 +129,7 @@ client = ArcadeEngine( ) # Or, configure per-request: -client.with_options(max_retries=5).llm_completions.create() +client.with_options(max_retries=5).chat.completions() ``` ### Timeouts @@ -152,7 +152,7 @@ client = ArcadeEngine( ) # Override per-request: -client.with_options(timeout=5.0).llm_completions.create() +client.with_options(timeout=5.0).chat.completions() ``` On timeout, an `APITimeoutError` is thrown. @@ -191,11 +191,11 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to from arcade_engine import ArcadeEngine client = ArcadeEngine() -response = client.llm_completions.with_raw_response.create() +response = client.chat.with_raw_response.completions() print(response.headers.get('X-My-Header')) -llm_completion = response.parse() # get the object that `llm_completions.create()` would have returned -print(llm_completion.id) +chat = response.parse() # get the object that `chat.completions()` would have returned +print(chat.id) ``` These methods return an [`APIResponse`](https://github.com/ArcadeAI/arcade-py/tree/main/src/arcade_engine/_response.py) object. @@ -209,7 +209,7 @@ The above interface eagerly reads the full response body when you make the reque To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods. ```python -with client.llm_completions.with_streaming_response.create() as response: +with client.chat.with_streaming_response.completions() as response: print(response.headers.get("X-My-Header")) for line in response.iter_lines(): diff --git a/api.md b/api.md index f3bd637b..6fc6e027 100644 --- a/api.md +++ b/api.md @@ -4,14 +4,14 @@ from arcade_engine.types import AuthorizationResponse ``` -# Authorization +# Auth Methods: -- client.authorization.authorize(\*\*params) -> AuthorizationResponse -- client.authorization.status(\*\*params) -> AuthorizationResponse +- client.auth.authorization(\*\*params) -> AuthorizationResponse +- client.auth.status(\*\*params) -> AuthorizationResponse -# LlmCompletions +# Chat Types: @@ -21,9 +21,9 @@ from arcade_engine.types import ChatResponse Methods: -- client.llm_completions.create(\*\*params) -> ChatResponse +- client.chat.completions(\*\*params) -> ChatResponse -# Operations +# Health Types: @@ -33,18 +33,18 @@ from arcade_engine.types import HealthSchema Methods: -- client.operations.health() -> HealthSchema +- client.health.list() -> HealthSchema # Tools Types: ```python -from arcade_engine.types import Definition, ToolResponse +from arcade_engine.types import Definition, Response ``` Methods: +- client.tools.retrieve(\*\*params) -> Definition - client.tools.authorize(\*\*params) -> AuthorizationResponse -- client.tools.definition(\*\*params) -> Definition -- client.tools.execute(\*\*params) -> ToolResponse +- client.tools.execute(\*\*params) -> Response diff --git a/src/arcade_engine/_client.py b/src/arcade_engine/_client.py index fc13d155..dce7550a 100644 --- a/src/arcade_engine/_client.py +++ b/src/arcade_engine/_client.py @@ -46,20 +46,20 @@ class ArcadeEngine(SyncAPIClient): - authorization: resources.AuthorizationResource - llm_completions: resources.LlmCompletionsResource - operations: resources.OperationsResource + auth: resources.AuthResource + chat: resources.ChatResource + health: resources.HealthResource tools: resources.ToolsResource with_raw_response: ArcadeEngineWithRawResponse with_streaming_response: ArcadeEngineWithStreamedResponse # client options - bearer_token: str + api_key: str def __init__( self, *, - bearer_token: str | None = None, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -81,15 +81,15 @@ def __init__( ) -> None: """Construct a new synchronous arcade-engine client instance. - This automatically infers the `bearer_token` argument from the `BEARER_TOKEN` environment variable if it is not provided. + This automatically infers the `api_key` argument from the `ARCADE_API_KEY` environment variable if it is not provided. """ - if bearer_token is None: - bearer_token = os.environ.get("BEARER_TOKEN") - if bearer_token is None: + if api_key is None: + api_key = os.environ.get("ARCADE_API_KEY") + if api_key is None: raise ArcadeEngineError( - "The bearer_token client option must be set either by passing bearer_token to the client or by setting the BEARER_TOKEN environment variable" + "The api_key client option must be set either by passing api_key to the client or by setting the ARCADE_API_KEY environment variable" ) - self.bearer_token = bearer_token + self.api_key = api_key if base_url is None: base_url = os.environ.get("ARCADE_ENGINE_BASE_URL") @@ -107,9 +107,9 @@ def __init__( _strict_response_validation=_strict_response_validation, ) - self.authorization = resources.AuthorizationResource(self) - self.llm_completions = resources.LlmCompletionsResource(self) - self.operations = resources.OperationsResource(self) + self.auth = resources.AuthResource(self) + self.chat = resources.ChatResource(self) + self.health = resources.HealthResource(self) self.tools = resources.ToolsResource(self) self.with_raw_response = ArcadeEngineWithRawResponse(self) self.with_streaming_response = ArcadeEngineWithStreamedResponse(self) @@ -122,8 +122,8 @@ def qs(self) -> Querystring: @property @override def auth_headers(self) -> dict[str, str]: - bearer_token = self.bearer_token - return {"Authorization": bearer_token} + api_key = self.api_key + return {"Authorization": api_key} @property @override @@ -137,7 +137,7 @@ def default_headers(self) -> dict[str, str | Omit]: def copy( self, *, - bearer_token: str | None = None, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, http_client: httpx.Client | None = None, @@ -171,7 +171,7 @@ def copy( http_client = http_client or self._client return self.__class__( - bearer_token=bearer_token or self.bearer_token, + api_key=api_key or self.api_key, base_url=base_url or self.base_url, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, http_client=http_client, @@ -220,20 +220,20 @@ def _make_status_error( class AsyncArcadeEngine(AsyncAPIClient): - authorization: resources.AsyncAuthorizationResource - llm_completions: resources.AsyncLlmCompletionsResource - operations: resources.AsyncOperationsResource + auth: resources.AsyncAuthResource + chat: resources.AsyncChatResource + health: resources.AsyncHealthResource tools: resources.AsyncToolsResource with_raw_response: AsyncArcadeEngineWithRawResponse with_streaming_response: AsyncArcadeEngineWithStreamedResponse # client options - bearer_token: str + api_key: str def __init__( self, *, - bearer_token: str | None = None, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -255,15 +255,15 @@ def __init__( ) -> None: """Construct a new async arcade-engine client instance. - This automatically infers the `bearer_token` argument from the `BEARER_TOKEN` environment variable if it is not provided. + This automatically infers the `api_key` argument from the `ARCADE_API_KEY` environment variable if it is not provided. """ - if bearer_token is None: - bearer_token = os.environ.get("BEARER_TOKEN") - if bearer_token is None: + if api_key is None: + api_key = os.environ.get("ARCADE_API_KEY") + if api_key is None: raise ArcadeEngineError( - "The bearer_token client option must be set either by passing bearer_token to the client or by setting the BEARER_TOKEN environment variable" + "The api_key client option must be set either by passing api_key to the client or by setting the ARCADE_API_KEY environment variable" ) - self.bearer_token = bearer_token + self.api_key = api_key if base_url is None: base_url = os.environ.get("ARCADE_ENGINE_BASE_URL") @@ -281,9 +281,9 @@ def __init__( _strict_response_validation=_strict_response_validation, ) - self.authorization = resources.AsyncAuthorizationResource(self) - self.llm_completions = resources.AsyncLlmCompletionsResource(self) - self.operations = resources.AsyncOperationsResource(self) + self.auth = resources.AsyncAuthResource(self) + self.chat = resources.AsyncChatResource(self) + self.health = resources.AsyncHealthResource(self) self.tools = resources.AsyncToolsResource(self) self.with_raw_response = AsyncArcadeEngineWithRawResponse(self) self.with_streaming_response = AsyncArcadeEngineWithStreamedResponse(self) @@ -296,8 +296,8 @@ def qs(self) -> Querystring: @property @override def auth_headers(self) -> dict[str, str]: - bearer_token = self.bearer_token - return {"Authorization": bearer_token} + api_key = self.api_key + return {"Authorization": api_key} @property @override @@ -311,7 +311,7 @@ def default_headers(self) -> dict[str, str | Omit]: def copy( self, *, - bearer_token: str | None = None, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, http_client: httpx.AsyncClient | None = None, @@ -345,7 +345,7 @@ def copy( http_client = http_client or self._client return self.__class__( - bearer_token=bearer_token or self.bearer_token, + api_key=api_key or self.api_key, base_url=base_url or self.base_url, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, http_client=http_client, @@ -395,33 +395,33 @@ def _make_status_error( class ArcadeEngineWithRawResponse: def __init__(self, client: ArcadeEngine) -> None: - self.authorization = resources.AuthorizationResourceWithRawResponse(client.authorization) - self.llm_completions = resources.LlmCompletionsResourceWithRawResponse(client.llm_completions) - self.operations = resources.OperationsResourceWithRawResponse(client.operations) + self.auth = resources.AuthResourceWithRawResponse(client.auth) + self.chat = resources.ChatResourceWithRawResponse(client.chat) + self.health = resources.HealthResourceWithRawResponse(client.health) self.tools = resources.ToolsResourceWithRawResponse(client.tools) class AsyncArcadeEngineWithRawResponse: def __init__(self, client: AsyncArcadeEngine) -> None: - self.authorization = resources.AsyncAuthorizationResourceWithRawResponse(client.authorization) - self.llm_completions = resources.AsyncLlmCompletionsResourceWithRawResponse(client.llm_completions) - self.operations = resources.AsyncOperationsResourceWithRawResponse(client.operations) + self.auth = resources.AsyncAuthResourceWithRawResponse(client.auth) + self.chat = resources.AsyncChatResourceWithRawResponse(client.chat) + self.health = resources.AsyncHealthResourceWithRawResponse(client.health) self.tools = resources.AsyncToolsResourceWithRawResponse(client.tools) class ArcadeEngineWithStreamedResponse: def __init__(self, client: ArcadeEngine) -> None: - self.authorization = resources.AuthorizationResourceWithStreamingResponse(client.authorization) - self.llm_completions = resources.LlmCompletionsResourceWithStreamingResponse(client.llm_completions) - self.operations = resources.OperationsResourceWithStreamingResponse(client.operations) + self.auth = resources.AuthResourceWithStreamingResponse(client.auth) + self.chat = resources.ChatResourceWithStreamingResponse(client.chat) + self.health = resources.HealthResourceWithStreamingResponse(client.health) self.tools = resources.ToolsResourceWithStreamingResponse(client.tools) class AsyncArcadeEngineWithStreamedResponse: def __init__(self, client: AsyncArcadeEngine) -> None: - self.authorization = resources.AsyncAuthorizationResourceWithStreamingResponse(client.authorization) - self.llm_completions = resources.AsyncLlmCompletionsResourceWithStreamingResponse(client.llm_completions) - self.operations = resources.AsyncOperationsResourceWithStreamingResponse(client.operations) + self.auth = resources.AsyncAuthResourceWithStreamingResponse(client.auth) + self.chat = resources.AsyncChatResourceWithStreamingResponse(client.chat) + self.health = resources.AsyncHealthResourceWithStreamingResponse(client.health) self.tools = resources.AsyncToolsResourceWithStreamingResponse(client.tools) diff --git a/src/arcade_engine/resources/__init__.py b/src/arcade_engine/resources/__init__.py index c1bfc0c8..7ac7a1ae 100644 --- a/src/arcade_engine/resources/__init__.py +++ b/src/arcade_engine/resources/__init__.py @@ -1,5 +1,21 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .auth import ( + AuthResource, + AsyncAuthResource, + AuthResourceWithRawResponse, + AsyncAuthResourceWithRawResponse, + AuthResourceWithStreamingResponse, + AsyncAuthResourceWithStreamingResponse, +) +from .chat import ( + ChatResource, + AsyncChatResource, + ChatResourceWithRawResponse, + AsyncChatResourceWithRawResponse, + ChatResourceWithStreamingResponse, + AsyncChatResourceWithStreamingResponse, +) from .tools import ( ToolsResource, AsyncToolsResource, @@ -8,50 +24,34 @@ ToolsResourceWithStreamingResponse, AsyncToolsResourceWithStreamingResponse, ) -from .operations import ( - OperationsResource, - AsyncOperationsResource, - OperationsResourceWithRawResponse, - AsyncOperationsResourceWithRawResponse, - OperationsResourceWithStreamingResponse, - AsyncOperationsResourceWithStreamingResponse, -) -from .authorization import ( - AuthorizationResource, - AsyncAuthorizationResource, - AuthorizationResourceWithRawResponse, - AsyncAuthorizationResourceWithRawResponse, - AuthorizationResourceWithStreamingResponse, - AsyncAuthorizationResourceWithStreamingResponse, -) -from .llm_completions import ( - LlmCompletionsResource, - AsyncLlmCompletionsResource, - LlmCompletionsResourceWithRawResponse, - AsyncLlmCompletionsResourceWithRawResponse, - LlmCompletionsResourceWithStreamingResponse, - AsyncLlmCompletionsResourceWithStreamingResponse, +from .health import ( + HealthResource, + AsyncHealthResource, + HealthResourceWithRawResponse, + AsyncHealthResourceWithRawResponse, + HealthResourceWithStreamingResponse, + AsyncHealthResourceWithStreamingResponse, ) __all__ = [ - "AuthorizationResource", - "AsyncAuthorizationResource", - "AuthorizationResourceWithRawResponse", - "AsyncAuthorizationResourceWithRawResponse", - "AuthorizationResourceWithStreamingResponse", - "AsyncAuthorizationResourceWithStreamingResponse", - "LlmCompletionsResource", - "AsyncLlmCompletionsResource", - "LlmCompletionsResourceWithRawResponse", - "AsyncLlmCompletionsResourceWithRawResponse", - "LlmCompletionsResourceWithStreamingResponse", - "AsyncLlmCompletionsResourceWithStreamingResponse", - "OperationsResource", - "AsyncOperationsResource", - "OperationsResourceWithRawResponse", - "AsyncOperationsResourceWithRawResponse", - "OperationsResourceWithStreamingResponse", - "AsyncOperationsResourceWithStreamingResponse", + "AuthResource", + "AsyncAuthResource", + "AuthResourceWithRawResponse", + "AsyncAuthResourceWithRawResponse", + "AuthResourceWithStreamingResponse", + "AsyncAuthResourceWithStreamingResponse", + "ChatResource", + "AsyncChatResource", + "ChatResourceWithRawResponse", + "AsyncChatResourceWithRawResponse", + "ChatResourceWithStreamingResponse", + "AsyncChatResourceWithStreamingResponse", + "HealthResource", + "AsyncHealthResource", + "HealthResourceWithRawResponse", + "AsyncHealthResourceWithRawResponse", + "HealthResourceWithStreamingResponse", + "AsyncHealthResourceWithStreamingResponse", "ToolsResource", "AsyncToolsResource", "ToolsResourceWithRawResponse", diff --git a/src/arcade_engine/resources/auth.py b/src/arcade_engine/resources/auth.py new file mode 100644 index 00000000..54783973 --- /dev/null +++ b/src/arcade_engine/resources/auth.py @@ -0,0 +1,284 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..types import auth_status_params, auth_authorization_params +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._utils import ( + maybe_transform, + async_maybe_transform, +) +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from .._base_client import make_request_options +from ..types.shared.authorization_response import AuthorizationResponse + +__all__ = ["AuthResource", "AsyncAuthResource"] + + +class AuthResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> AuthResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return AuthResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AuthResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return AuthResourceWithStreamingResponse(self) + + def authorization( + self, + *, + auth_requirement: auth_authorization_params.AuthRequirement, + user_id: str, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AuthorizationResponse: + """ + Starts the authorization process for given authorization requirements + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/v1/auth/authorize", + body=maybe_transform( + { + "auth_requirement": auth_requirement, + "user_id": user_id, + }, + auth_authorization_params.AuthAuthorizationParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=AuthorizationResponse, + ) + + def status( + self, + *, + authorization_id: str, + scopes: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AuthorizationResponse: + """ + Checks the status of an ongoing authorization process for a specific tool + + Args: + authorization_id: Authorization ID + + scopes: Scopes + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._get( + "/v1/auth/status", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "authorization_id": authorization_id, + "scopes": scopes, + }, + auth_status_params.AuthStatusParams, + ), + ), + cast_to=AuthorizationResponse, + ) + + +class AsyncAuthResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncAuthResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return AsyncAuthResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncAuthResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return AsyncAuthResourceWithStreamingResponse(self) + + async def authorization( + self, + *, + auth_requirement: auth_authorization_params.AuthRequirement, + user_id: str, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AuthorizationResponse: + """ + Starts the authorization process for given authorization requirements + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/v1/auth/authorize", + body=await async_maybe_transform( + { + "auth_requirement": auth_requirement, + "user_id": user_id, + }, + auth_authorization_params.AuthAuthorizationParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=AuthorizationResponse, + ) + + async def status( + self, + *, + authorization_id: str, + scopes: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AuthorizationResponse: + """ + Checks the status of an ongoing authorization process for a specific tool + + Args: + authorization_id: Authorization ID + + scopes: Scopes + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._get( + "/v1/auth/status", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=await async_maybe_transform( + { + "authorization_id": authorization_id, + "scopes": scopes, + }, + auth_status_params.AuthStatusParams, + ), + ), + cast_to=AuthorizationResponse, + ) + + +class AuthResourceWithRawResponse: + def __init__(self, auth: AuthResource) -> None: + self._auth = auth + + self.authorization = to_raw_response_wrapper( + auth.authorization, + ) + self.status = to_raw_response_wrapper( + auth.status, + ) + + +class AsyncAuthResourceWithRawResponse: + def __init__(self, auth: AsyncAuthResource) -> None: + self._auth = auth + + self.authorization = async_to_raw_response_wrapper( + auth.authorization, + ) + self.status = async_to_raw_response_wrapper( + auth.status, + ) + + +class AuthResourceWithStreamingResponse: + def __init__(self, auth: AuthResource) -> None: + self._auth = auth + + self.authorization = to_streamed_response_wrapper( + auth.authorization, + ) + self.status = to_streamed_response_wrapper( + auth.status, + ) + + +class AsyncAuthResourceWithStreamingResponse: + def __init__(self, auth: AsyncAuthResource) -> None: + self._auth = auth + + self.authorization = async_to_streamed_response_wrapper( + auth.authorization, + ) + self.status = async_to_streamed_response_wrapper( + auth.status, + ) diff --git a/src/arcade_engine/resources/chat.py b/src/arcade_engine/resources/chat.py new file mode 100644 index 00000000..fffa5c54 --- /dev/null +++ b/src/arcade_engine/resources/chat.py @@ -0,0 +1,295 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, List, Iterable +from typing_extensions import Literal + +import httpx + +from ..types import chat_completions_params +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._utils import ( + maybe_transform, + async_maybe_transform, +) +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from .._base_client import make_request_options +from ..types.chat_response import ChatResponse + +__all__ = ["ChatResource", "AsyncChatResource"] + + +class ChatResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> ChatResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return ChatResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ChatResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return ChatResourceWithStreamingResponse(self) + + def completions( + self, + *, + frequency_penalty: int | NotGiven = NOT_GIVEN, + logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN, + logprobs: bool | NotGiven = NOT_GIVEN, + max_tokens: int | NotGiven = NOT_GIVEN, + messages: Iterable[chat_completions_params.Message] | NotGiven = NOT_GIVEN, + model: str | NotGiven = NOT_GIVEN, + n: int | NotGiven = NOT_GIVEN, + parallel_tool_calls: object | NotGiven = NOT_GIVEN, + presence_penalty: int | NotGiven = NOT_GIVEN, + response_format: Literal["json_object", "text"] | NotGiven = NOT_GIVEN, + seed: int | NotGiven = NOT_GIVEN, + stop: List[str] | NotGiven = NOT_GIVEN, + stream: bool | NotGiven = NOT_GIVEN, + stream_options: chat_completions_params.StreamOptions | NotGiven = NOT_GIVEN, + temperature: float | NotGiven = NOT_GIVEN, + tool_choice: Literal["", "none", "auto", "required", "execute", "generate"] | NotGiven = NOT_GIVEN, + tools: object | NotGiven = NOT_GIVEN, + top_logprobs: int | NotGiven = NOT_GIVEN, + top_p: float | NotGiven = NOT_GIVEN, + user: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> ChatResponse: + """ + Talk to different LLM Chat APIs via OpenAI's API + + Args: + logit_bias: LogitBias is must be a token id string (specified by their token ID in the + tokenizer), not a word string. incorrect: `"logit_bias":{"You": 6}`, correct: + `"logit_bias":{"1639": 6}` refs: + https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias + + logprobs: LogProbs indicates whether to return log probabilities of the output tokens or + not. If true, returns the log probabilities of each output token returned in the + content of message. This option is currently not available on the + gpt-4-vision-preview model. + + parallel_tool_calls: Disable the default behavior of parallel tool calls by setting it: false. + + stream_options: Options for streaming response. Only set this when you set stream: true. + + tool_choice: This can be either a string or an ToolChoice object. + + top_logprobs: TopLogProbs is an integer between 0 and 5 specifying the number of most likely + tokens to return at each token position, each with an associated log + probability. logprobs must be set to true if this parameter is used. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/v1/chat/completions", + body=maybe_transform( + { + "frequency_penalty": frequency_penalty, + "logit_bias": logit_bias, + "logprobs": logprobs, + "max_tokens": max_tokens, + "messages": messages, + "model": model, + "n": n, + "parallel_tool_calls": parallel_tool_calls, + "presence_penalty": presence_penalty, + "response_format": response_format, + "seed": seed, + "stop": stop, + "stream": stream, + "stream_options": stream_options, + "temperature": temperature, + "tool_choice": tool_choice, + "tools": tools, + "top_logprobs": top_logprobs, + "top_p": top_p, + "user": user, + }, + chat_completions_params.ChatCompletionsParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ChatResponse, + ) + + +class AsyncChatResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncChatResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return AsyncChatResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncChatResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return AsyncChatResourceWithStreamingResponse(self) + + async def completions( + self, + *, + frequency_penalty: int | NotGiven = NOT_GIVEN, + logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN, + logprobs: bool | NotGiven = NOT_GIVEN, + max_tokens: int | NotGiven = NOT_GIVEN, + messages: Iterable[chat_completions_params.Message] | NotGiven = NOT_GIVEN, + model: str | NotGiven = NOT_GIVEN, + n: int | NotGiven = NOT_GIVEN, + parallel_tool_calls: object | NotGiven = NOT_GIVEN, + presence_penalty: int | NotGiven = NOT_GIVEN, + response_format: Literal["json_object", "text"] | NotGiven = NOT_GIVEN, + seed: int | NotGiven = NOT_GIVEN, + stop: List[str] | NotGiven = NOT_GIVEN, + stream: bool | NotGiven = NOT_GIVEN, + stream_options: chat_completions_params.StreamOptions | NotGiven = NOT_GIVEN, + temperature: float | NotGiven = NOT_GIVEN, + tool_choice: Literal["", "none", "auto", "required", "execute", "generate"] | NotGiven = NOT_GIVEN, + tools: object | NotGiven = NOT_GIVEN, + top_logprobs: int | NotGiven = NOT_GIVEN, + top_p: float | NotGiven = NOT_GIVEN, + user: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> ChatResponse: + """ + Talk to different LLM Chat APIs via OpenAI's API + + Args: + logit_bias: LogitBias is must be a token id string (specified by their token ID in the + tokenizer), not a word string. incorrect: `"logit_bias":{"You": 6}`, correct: + `"logit_bias":{"1639": 6}` refs: + https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias + + logprobs: LogProbs indicates whether to return log probabilities of the output tokens or + not. If true, returns the log probabilities of each output token returned in the + content of message. This option is currently not available on the + gpt-4-vision-preview model. + + parallel_tool_calls: Disable the default behavior of parallel tool calls by setting it: false. + + stream_options: Options for streaming response. Only set this when you set stream: true. + + tool_choice: This can be either a string or an ToolChoice object. + + top_logprobs: TopLogProbs is an integer between 0 and 5 specifying the number of most likely + tokens to return at each token position, each with an associated log + probability. logprobs must be set to true if this parameter is used. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/v1/chat/completions", + body=await async_maybe_transform( + { + "frequency_penalty": frequency_penalty, + "logit_bias": logit_bias, + "logprobs": logprobs, + "max_tokens": max_tokens, + "messages": messages, + "model": model, + "n": n, + "parallel_tool_calls": parallel_tool_calls, + "presence_penalty": presence_penalty, + "response_format": response_format, + "seed": seed, + "stop": stop, + "stream": stream, + "stream_options": stream_options, + "temperature": temperature, + "tool_choice": tool_choice, + "tools": tools, + "top_logprobs": top_logprobs, + "top_p": top_p, + "user": user, + }, + chat_completions_params.ChatCompletionsParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ChatResponse, + ) + + +class ChatResourceWithRawResponse: + def __init__(self, chat: ChatResource) -> None: + self._chat = chat + + self.completions = to_raw_response_wrapper( + chat.completions, + ) + + +class AsyncChatResourceWithRawResponse: + def __init__(self, chat: AsyncChatResource) -> None: + self._chat = chat + + self.completions = async_to_raw_response_wrapper( + chat.completions, + ) + + +class ChatResourceWithStreamingResponse: + def __init__(self, chat: ChatResource) -> None: + self._chat = chat + + self.completions = to_streamed_response_wrapper( + chat.completions, + ) + + +class AsyncChatResourceWithStreamingResponse: + def __init__(self, chat: AsyncChatResource) -> None: + self._chat = chat + + self.completions = async_to_streamed_response_wrapper( + chat.completions, + ) diff --git a/src/arcade_engine/resources/health.py b/src/arcade_engine/resources/health.py new file mode 100644 index 00000000..ec6d66ab --- /dev/null +++ b/src/arcade_engine/resources/health.py @@ -0,0 +1,135 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +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, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from .._base_client import make_request_options +from ..types.health_schema import HealthSchema + +__all__ = ["HealthResource", "AsyncHealthResource"] + + +class HealthResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> HealthResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return HealthResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> HealthResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return HealthResourceWithStreamingResponse(self) + + def list( + self, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> HealthSchema: + """Engine Health""" + return self._get( + "/v1/health", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=HealthSchema, + ) + + +class AsyncHealthResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncHealthResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#accessing-raw-response-data-eg-headers + """ + return AsyncHealthResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncHealthResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/ArcadeAI/arcade-py#with_streaming_response + """ + return AsyncHealthResourceWithStreamingResponse(self) + + async def list( + self, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> HealthSchema: + """Engine Health""" + return await self._get( + "/v1/health", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=HealthSchema, + ) + + +class HealthResourceWithRawResponse: + def __init__(self, health: HealthResource) -> None: + self._health = health + + self.list = to_raw_response_wrapper( + health.list, + ) + + +class AsyncHealthResourceWithRawResponse: + def __init__(self, health: AsyncHealthResource) -> None: + self._health = health + + self.list = async_to_raw_response_wrapper( + health.list, + ) + + +class HealthResourceWithStreamingResponse: + def __init__(self, health: HealthResource) -> None: + self._health = health + + self.list = to_streamed_response_wrapper( + health.list, + ) + + +class AsyncHealthResourceWithStreamingResponse: + def __init__(self, health: AsyncHealthResource) -> None: + self._health = health + + self.list = async_to_streamed_response_wrapper( + health.list, + ) diff --git a/src/arcade_engine/resources/tools.py b/src/arcade_engine/resources/tools.py index 9fd5c70a..290f4976 100644 --- a/src/arcade_engine/resources/tools.py +++ b/src/arcade_engine/resources/tools.py @@ -4,7 +4,7 @@ import httpx -from ..types import tool_execute_params, tool_authorize_params, tool_definition_params +from ..types import tool_execute_params, tool_retrieve_params, tool_authorize_params from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import ( maybe_transform, @@ -19,8 +19,8 @@ async_to_streamed_response_wrapper, ) from .._base_client import make_request_options +from ..types.response import Response from ..types.definition import Definition -from ..types.tool_response import ToolResponse from ..types.shared.authorization_response import AuthorizationResponse __all__ = ["ToolsResource", "AsyncToolsResource"] @@ -46,24 +46,25 @@ def with_streaming_response(self) -> ToolsResourceWithStreamingResponse: """ return ToolsResourceWithStreamingResponse(self) - def authorize( + def retrieve( self, *, - tool_name: str, - user_id: str, - tool_version: str | NotGiven = NOT_GIVEN, + director_id: str, + tool_id: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AuthorizationResponse: + ) -> Definition: """ - Authorizes a user for a specific tool by name + Returns the arcade tool specification for a specific tool Args: - tool_version: Optional: if not provided, latest version is assumed + director_id: Director ID + + tool_id: Tool ID extra_headers: Send extra headers @@ -73,41 +74,42 @@ def authorize( timeout: Override the client-level default timeout for this request, in seconds """ - return self._post( - "/v1/tools/authorize", - body=maybe_transform( - { - "tool_name": tool_name, - "user_id": user_id, - "tool_version": tool_version, - }, - tool_authorize_params.ToolAuthorizeParams, - ), + return self._get( + "/v1/tools/definition", options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "director_id": director_id, + "tool_id": tool_id, + }, + tool_retrieve_params.ToolRetrieveParams, + ), ), - cast_to=AuthorizationResponse, + cast_to=Definition, ) - def definition( + def authorize( self, *, - director_id: str, - tool_id: str, + tool_name: str, + user_id: str, + tool_version: str | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Definition: + ) -> AuthorizationResponse: """ - Returns the arcade tool specification for a specific tool + Authorizes a user for a specific tool by name Args: - director_id: Director ID - - tool_id: Tool ID + tool_version: Optional: if not provided, latest version is assumed extra_headers: Send extra headers @@ -117,22 +119,20 @@ def definition( timeout: Override the client-level default timeout for this request, in seconds """ - return self._get( - "/v1/tools/definition", + return self._post( + "/v1/tools/authorize", + body=maybe_transform( + { + "tool_name": tool_name, + "user_id": user_id, + "tool_version": tool_version, + }, + tool_authorize_params.ToolAuthorizeParams, + ), options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - query=maybe_transform( - { - "director_id": director_id, - "tool_id": tool_id, - }, - tool_definition_params.ToolDefinitionParams, - ), + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=Definition, + cast_to=AuthorizationResponse, ) def execute( @@ -148,7 +148,7 @@ def execute( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ToolResponse: + ) -> Response: """ Executes a tool by name and arguments @@ -177,7 +177,7 @@ def execute( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=ToolResponse, + cast_to=Response, ) @@ -201,24 +201,25 @@ def with_streaming_response(self) -> AsyncToolsResourceWithStreamingResponse: """ return AsyncToolsResourceWithStreamingResponse(self) - async def authorize( + async def retrieve( self, *, - tool_name: str, - user_id: str, - tool_version: str | NotGiven = NOT_GIVEN, + director_id: str, + tool_id: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AuthorizationResponse: + ) -> Definition: """ - Authorizes a user for a specific tool by name + Returns the arcade tool specification for a specific tool Args: - tool_version: Optional: if not provided, latest version is assumed + director_id: Director ID + + tool_id: Tool ID extra_headers: Send extra headers @@ -228,41 +229,42 @@ async def authorize( timeout: Override the client-level default timeout for this request, in seconds """ - return await self._post( - "/v1/tools/authorize", - body=await async_maybe_transform( - { - "tool_name": tool_name, - "user_id": user_id, - "tool_version": tool_version, - }, - tool_authorize_params.ToolAuthorizeParams, - ), + return await self._get( + "/v1/tools/definition", options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=await async_maybe_transform( + { + "director_id": director_id, + "tool_id": tool_id, + }, + tool_retrieve_params.ToolRetrieveParams, + ), ), - cast_to=AuthorizationResponse, + cast_to=Definition, ) - async def definition( + async def authorize( self, *, - director_id: str, - tool_id: str, + tool_name: str, + user_id: str, + tool_version: str | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Definition: + ) -> AuthorizationResponse: """ - Returns the arcade tool specification for a specific tool + Authorizes a user for a specific tool by name Args: - director_id: Director ID - - tool_id: Tool ID + tool_version: Optional: if not provided, latest version is assumed extra_headers: Send extra headers @@ -272,22 +274,20 @@ async def definition( timeout: Override the client-level default timeout for this request, in seconds """ - return await self._get( - "/v1/tools/definition", + return await self._post( + "/v1/tools/authorize", + body=await async_maybe_transform( + { + "tool_name": tool_name, + "user_id": user_id, + "tool_version": tool_version, + }, + tool_authorize_params.ToolAuthorizeParams, + ), options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - query=await async_maybe_transform( - { - "director_id": director_id, - "tool_id": tool_id, - }, - tool_definition_params.ToolDefinitionParams, - ), + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=Definition, + cast_to=AuthorizationResponse, ) async def execute( @@ -303,7 +303,7 @@ async def execute( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ToolResponse: + ) -> Response: """ Executes a tool by name and arguments @@ -332,7 +332,7 @@ async def execute( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=ToolResponse, + cast_to=Response, ) @@ -340,12 +340,12 @@ class ToolsResourceWithRawResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools + self.retrieve = to_raw_response_wrapper( + tools.retrieve, + ) self.authorize = to_raw_response_wrapper( tools.authorize, ) - self.definition = to_raw_response_wrapper( - tools.definition, - ) self.execute = to_raw_response_wrapper( tools.execute, ) @@ -355,12 +355,12 @@ class AsyncToolsResourceWithRawResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools + self.retrieve = async_to_raw_response_wrapper( + tools.retrieve, + ) self.authorize = async_to_raw_response_wrapper( tools.authorize, ) - self.definition = async_to_raw_response_wrapper( - tools.definition, - ) self.execute = async_to_raw_response_wrapper( tools.execute, ) @@ -370,12 +370,12 @@ class ToolsResourceWithStreamingResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools + self.retrieve = to_streamed_response_wrapper( + tools.retrieve, + ) self.authorize = to_streamed_response_wrapper( tools.authorize, ) - self.definition = to_streamed_response_wrapper( - tools.definition, - ) self.execute = to_streamed_response_wrapper( tools.execute, ) @@ -385,12 +385,12 @@ class AsyncToolsResourceWithStreamingResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools + self.retrieve = async_to_streamed_response_wrapper( + tools.retrieve, + ) self.authorize = async_to_streamed_response_wrapper( tools.authorize, ) - self.definition = async_to_streamed_response_wrapper( - tools.definition, - ) self.execute = async_to_streamed_response_wrapper( tools.execute, ) diff --git a/src/arcade_engine/types/__init__.py b/src/arcade_engine/types/__init__.py index edeee31b..708af8d8 100644 --- a/src/arcade_engine/types/__init__.py +++ b/src/arcade_engine/types/__init__.py @@ -3,13 +3,13 @@ from __future__ import annotations from .shared import AuthorizationResponse as AuthorizationResponse +from .response import Response as Response from .definition import Definition as Definition from .chat_response import ChatResponse as ChatResponse from .health_schema import HealthSchema as HealthSchema -from .tool_response import ToolResponse as ToolResponse +from .auth_status_params import AuthStatusParams as AuthStatusParams from .tool_execute_params import ToolExecuteParams as ToolExecuteParams +from .tool_retrieve_params import ToolRetrieveParams as ToolRetrieveParams from .tool_authorize_params import ToolAuthorizeParams as ToolAuthorizeParams -from .tool_definition_params import ToolDefinitionParams as ToolDefinitionParams -from .authorization_status_params import AuthorizationStatusParams as AuthorizationStatusParams -from .llm_completion_create_params import LlmCompletionCreateParams as LlmCompletionCreateParams -from .authorization_authorize_params import AuthorizationAuthorizeParams as AuthorizationAuthorizeParams +from .chat_completions_params import ChatCompletionsParams as ChatCompletionsParams +from .auth_authorization_params import AuthAuthorizationParams as AuthAuthorizationParams diff --git a/src/arcade_engine/types/auth_authorization_params.py b/src/arcade_engine/types/auth_authorization_params.py new file mode 100644 index 00000000..c881300b --- /dev/null +++ b/src/arcade_engine/types/auth_authorization_params.py @@ -0,0 +1,26 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import List +from typing_extensions import Required, TypedDict + +__all__ = ["AuthAuthorizationParams", "AuthRequirement", "AuthRequirementOauth2"] + + +class AuthAuthorizationParams(TypedDict, total=False): + auth_requirement: Required[AuthRequirement] + + user_id: Required[str] + + +class AuthRequirementOauth2(TypedDict, total=False): + authority: str + + scopes: List[str] + + +class AuthRequirement(TypedDict, total=False): + provider: Required[str] + + oauth2: AuthRequirementOauth2 diff --git a/src/arcade_engine/types/auth_status_params.py b/src/arcade_engine/types/auth_status_params.py new file mode 100644 index 00000000..6026fb39 --- /dev/null +++ b/src/arcade_engine/types/auth_status_params.py @@ -0,0 +1,17 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, Annotated, TypedDict + +from .._utils import PropertyInfo + +__all__ = ["AuthStatusParams"] + + +class AuthStatusParams(TypedDict, total=False): + authorization_id: Required[Annotated[str, PropertyInfo(alias="authorizationID")]] + """Authorization ID""" + + scopes: str + """Scopes""" diff --git a/src/arcade_engine/types/chat_completions_params.py b/src/arcade_engine/types/chat_completions_params.py new file mode 100644 index 00000000..6b388e59 --- /dev/null +++ b/src/arcade_engine/types/chat_completions_params.py @@ -0,0 +1,114 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, List, Iterable +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["ChatCompletionsParams", "Message", "MessageToolCall", "MessageToolCallFunction", "StreamOptions"] + + +class ChatCompletionsParams(TypedDict, total=False): + frequency_penalty: int + + logit_bias: Dict[str, int] + """ + LogitBias is must be a token id string (specified by their token ID in the + tokenizer), not a word string. incorrect: `"logit_bias":{"You": 6}`, correct: + `"logit_bias":{"1639": 6}` refs: + https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias + """ + + logprobs: bool + """ + LogProbs indicates whether to return log probabilities of the output tokens or + not. If true, returns the log probabilities of each output token returned in the + content of message. This option is currently not available on the + gpt-4-vision-preview model. + """ + + max_tokens: int + + messages: Iterable[Message] + + model: str + + n: int + + parallel_tool_calls: object + """Disable the default behavior of parallel tool calls by setting it: false.""" + + presence_penalty: int + + response_format: Literal["json_object", "text"] + + seed: int + + stop: List[str] + + stream: bool + + stream_options: StreamOptions + """Options for streaming response. Only set this when you set stream: true.""" + + temperature: float + + tool_choice: Literal["", "none", "auto", "required", "execute", "generate"] + """This can be either a string or an ToolChoice object.""" + + tools: object + + top_logprobs: int + """ + TopLogProbs is an integer between 0 and 5 specifying the number of most likely + tokens to return at each token position, each with an associated log + probability. logprobs must be set to true if this parameter is used. + """ + + top_p: float + + user: str + + +class MessageToolCallFunction(TypedDict, total=False): + arguments: str + + name: str + + +class MessageToolCall(TypedDict, total=False): + id: str + + function: MessageToolCallFunction + + type: Literal["function"] + + +class Message(TypedDict, total=False): + content: Required[str] + """The content of the message.""" + + role: Required[str] + """The role of the author of this message. + + One of system, user, tool, or assistant. + """ + + name: str + """tool Name""" + + tool_call_id: str + """tool_call_id""" + + tool_calls: Iterable[MessageToolCall] + """tool calls if any""" + + +class StreamOptions(TypedDict, total=False): + include_usage: bool + """ + If set, an additional chunk will be streamed before the data: [DONE] message. + The usage field on this chunk shows the token usage statistics for the entire + request, and the choices field will always be an empty array. All other chunks + will also include a usage field, but with a null value. + """ diff --git a/src/arcade_engine/types/response.py b/src/arcade_engine/types/response.py new file mode 100644 index 00000000..7a4b089e --- /dev/null +++ b/src/arcade_engine/types/response.py @@ -0,0 +1,43 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from pydantic import Field as FieldInfo + +from .._models import BaseModel + +__all__ = ["Response", "FinishedAt", "Output", "OutputError"] + + +class FinishedAt(BaseModel): + time_time: Optional[str] = FieldInfo(alias="time.Time", default=None) + + +class OutputError(BaseModel): + message: str + + additional_prompt_content: Optional[str] = None + + can_retry: Optional[bool] = None + + developer_message: Optional[str] = None + + retry_after_ms: Optional[int] = None + + +class Output(BaseModel): + value: object + + error: Optional[OutputError] = None + + +class Response(BaseModel): + invocation_id: str + + duration: Optional[float] = None + + finished_at: Optional[FinishedAt] = None + + output: Optional[Output] = None + + success: Optional[bool] = None diff --git a/src/arcade_engine/types/tool_retrieve_params.py b/src/arcade_engine/types/tool_retrieve_params.py new file mode 100644 index 00000000..878f8a79 --- /dev/null +++ b/src/arcade_engine/types/tool_retrieve_params.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +__all__ = ["ToolRetrieveParams"] + + +class ToolRetrieveParams(TypedDict, total=False): + director_id: Required[str] + """Director ID""" + + tool_id: Required[str] + """Tool ID""" diff --git a/tests/api_resources/test_auth.py b/tests/api_resources/test_auth.py new file mode 100644 index 00000000..cdeb9dd3 --- /dev/null +++ b/tests/api_resources/test_auth.py @@ -0,0 +1,196 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from tests.utils import assert_matches_type +from arcade_engine import ArcadeEngine, AsyncArcadeEngine +from arcade_engine.types.shared import AuthorizationResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestAuth: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_authorization(self, client: ArcadeEngine) -> None: + auth = client.auth.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_method_authorization_with_all_params(self, client: ArcadeEngine) -> None: + auth = client.auth.authorization( + auth_requirement={ + "provider": "provider", + "oauth2": { + "authority": "authority", + "scopes": ["string", "string", "string"], + }, + }, + user_id="user_id", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_raw_response_authorization(self, client: ArcadeEngine) -> None: + response = client.auth.with_raw_response.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + auth = response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_streaming_response_authorization(self, client: ArcadeEngine) -> None: + with client.auth.with_streaming_response.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + auth = response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_method_status(self, client: ArcadeEngine) -> None: + auth = client.auth.status( + authorization_id="authorizationID", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_method_status_with_all_params(self, client: ArcadeEngine) -> None: + auth = client.auth.status( + authorization_id="authorizationID", + scopes="scopes", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_raw_response_status(self, client: ArcadeEngine) -> None: + response = client.auth.with_raw_response.status( + authorization_id="authorizationID", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + auth = response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + def test_streaming_response_status(self, client: ArcadeEngine) -> None: + with client.auth.with_streaming_response.status( + authorization_id="authorizationID", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + auth = response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncAuth: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_authorization(self, async_client: AsyncArcadeEngine) -> None: + auth = await async_client.auth.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_method_authorization_with_all_params(self, async_client: AsyncArcadeEngine) -> None: + auth = await async_client.auth.authorization( + auth_requirement={ + "provider": "provider", + "oauth2": { + "authority": "authority", + "scopes": ["string", "string", "string"], + }, + }, + user_id="user_id", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_raw_response_authorization(self, async_client: AsyncArcadeEngine) -> None: + response = await async_client.auth.with_raw_response.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + auth = await response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_streaming_response_authorization(self, async_client: AsyncArcadeEngine) -> None: + async with async_client.auth.with_streaming_response.authorization( + auth_requirement={"provider": "provider"}, + user_id="user_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + auth = await response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_method_status(self, async_client: AsyncArcadeEngine) -> None: + auth = await async_client.auth.status( + authorization_id="authorizationID", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_method_status_with_all_params(self, async_client: AsyncArcadeEngine) -> None: + auth = await async_client.auth.status( + authorization_id="authorizationID", + scopes="scopes", + ) + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_raw_response_status(self, async_client: AsyncArcadeEngine) -> None: + response = await async_client.auth.with_raw_response.status( + authorization_id="authorizationID", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + auth = await response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + @parametrize + async def test_streaming_response_status(self, async_client: AsyncArcadeEngine) -> None: + async with async_client.auth.with_streaming_response.status( + authorization_id="authorizationID", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + auth = await response.parse() + assert_matches_type(AuthorizationResponse, auth, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_chat.py b/tests/api_resources/test_chat.py new file mode 100644 index 00000000..650a5a7a --- /dev/null +++ b/tests/api_resources/test_chat.py @@ -0,0 +1,318 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from tests.utils import assert_matches_type +from arcade_engine import ArcadeEngine, AsyncArcadeEngine +from arcade_engine.types import ChatResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestChat: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_completions(self, client: ArcadeEngine) -> None: + chat = client.chat.completions() + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + def test_method_completions_with_all_params(self, client: ArcadeEngine) -> None: + chat = client.chat.completions( + frequency_penalty=0, + logit_bias={"foo": 0}, + logprobs=True, + max_tokens=0, + messages=[ + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + ], + model="model", + n=0, + parallel_tool_calls={}, + presence_penalty=0, + response_format="json_object", + seed=0, + stop=["string", "string", "string"], + stream=True, + stream_options={"include_usage": True}, + temperature=0, + tool_choice="", + tools={}, + top_logprobs=0, + top_p=0, + user="user", + ) + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + def test_raw_response_completions(self, client: ArcadeEngine) -> None: + response = client.chat.with_raw_response.completions() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + chat = response.parse() + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + def test_streaming_response_completions(self, client: ArcadeEngine) -> None: + with client.chat.with_streaming_response.completions() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + chat = response.parse() + assert_matches_type(ChatResponse, chat, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncChat: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_completions(self, async_client: AsyncArcadeEngine) -> None: + chat = await async_client.chat.completions() + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + async def test_method_completions_with_all_params(self, async_client: AsyncArcadeEngine) -> None: + chat = await async_client.chat.completions( + frequency_penalty=0, + logit_bias={"foo": 0}, + logprobs=True, + max_tokens=0, + messages=[ + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + { + "content": "content", + "role": "role", + "name": "name", + "tool_call_id": "tool_call_id", + "tool_calls": [ + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + { + "id": "id", + "function": { + "arguments": "arguments", + "name": "name", + }, + "type": "function", + }, + ], + }, + ], + model="model", + n=0, + parallel_tool_calls={}, + presence_penalty=0, + response_format="json_object", + seed=0, + stop=["string", "string", "string"], + stream=True, + stream_options={"include_usage": True}, + temperature=0, + tool_choice="", + tools={}, + top_logprobs=0, + top_p=0, + user="user", + ) + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + async def test_raw_response_completions(self, async_client: AsyncArcadeEngine) -> None: + response = await async_client.chat.with_raw_response.completions() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + chat = await response.parse() + assert_matches_type(ChatResponse, chat, path=["response"]) + + @parametrize + async def test_streaming_response_completions(self, async_client: AsyncArcadeEngine) -> None: + async with async_client.chat.with_streaming_response.completions() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + chat = await response.parse() + assert_matches_type(ChatResponse, chat, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_health.py b/tests/api_resources/test_health.py new file mode 100644 index 00000000..169ad56c --- /dev/null +++ b/tests/api_resources/test_health.py @@ -0,0 +1,72 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from tests.utils import assert_matches_type +from arcade_engine import ArcadeEngine, AsyncArcadeEngine +from arcade_engine.types import HealthSchema + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestHealth: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_list(self, client: ArcadeEngine) -> None: + health = client.health.list() + assert_matches_type(HealthSchema, health, path=["response"]) + + @parametrize + def test_raw_response_list(self, client: ArcadeEngine) -> None: + response = client.health.with_raw_response.list() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + health = response.parse() + assert_matches_type(HealthSchema, health, path=["response"]) + + @parametrize + def test_streaming_response_list(self, client: ArcadeEngine) -> None: + with client.health.with_streaming_response.list() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + health = response.parse() + assert_matches_type(HealthSchema, health, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncHealth: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_list(self, async_client: AsyncArcadeEngine) -> None: + health = await async_client.health.list() + assert_matches_type(HealthSchema, health, path=["response"]) + + @parametrize + async def test_raw_response_list(self, async_client: AsyncArcadeEngine) -> None: + response = await async_client.health.with_raw_response.list() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + health = await response.parse() + assert_matches_type(HealthSchema, health, path=["response"]) + + @parametrize + async def test_streaming_response_list(self, async_client: AsyncArcadeEngine) -> None: + async with async_client.health.with_streaming_response.list() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + health = await response.parse() + assert_matches_type(HealthSchema, health, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_tools.py b/tests/api_resources/test_tools.py index 37ac2f84..fa8915eb 100644 --- a/tests/api_resources/test_tools.py +++ b/tests/api_resources/test_tools.py @@ -9,10 +9,7 @@ from tests.utils import assert_matches_type from arcade_engine import ArcadeEngine, AsyncArcadeEngine -from arcade_engine.types import ( - Definition, - ToolResponse, -) +from arcade_engine.types import Response, Definition from arcade_engine.types.shared import AuthorizationResponse base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -21,6 +18,40 @@ class TestTools: parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + @parametrize + def test_method_retrieve(self, client: ArcadeEngine) -> None: + tool = client.tools.retrieve( + director_id="director_id", + tool_id="tool_id", + ) + assert_matches_type(Definition, tool, path=["response"]) + + @parametrize + def test_raw_response_retrieve(self, client: ArcadeEngine) -> None: + response = client.tools.with_raw_response.retrieve( + director_id="director_id", + tool_id="tool_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + tool = response.parse() + assert_matches_type(Definition, tool, path=["response"]) + + @parametrize + def test_streaming_response_retrieve(self, client: ArcadeEngine) -> None: + with client.tools.with_streaming_response.retrieve( + director_id="director_id", + tool_id="tool_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + tool = response.parse() + assert_matches_type(Definition, tool, path=["response"]) + + assert cast(Any, response.is_closed) is True + @parametrize def test_method_authorize(self, client: ArcadeEngine) -> None: tool = client.tools.authorize( @@ -64,40 +95,6 @@ def test_streaming_response_authorize(self, client: ArcadeEngine) -> None: assert cast(Any, response.is_closed) is True - @parametrize - def test_method_definition(self, client: ArcadeEngine) -> None: - tool = client.tools.definition( - director_id="director_id", - tool_id="tool_id", - ) - assert_matches_type(Definition, tool, path=["response"]) - - @parametrize - def test_raw_response_definition(self, client: ArcadeEngine) -> None: - response = client.tools.with_raw_response.definition( - director_id="director_id", - tool_id="tool_id", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = response.parse() - assert_matches_type(Definition, tool, path=["response"]) - - @parametrize - def test_streaming_response_definition(self, client: ArcadeEngine) -> None: - with client.tools.with_streaming_response.definition( - director_id="director_id", - tool_id="tool_id", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - tool = response.parse() - assert_matches_type(Definition, tool, path=["response"]) - - assert cast(Any, response.is_closed) is True - @parametrize def test_method_execute(self, client: ArcadeEngine) -> None: tool = client.tools.execute( @@ -106,7 +103,7 @@ def test_method_execute(self, client: ArcadeEngine) -> None: tool_version="tool_version", user_id="user_id", ) - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) @parametrize def test_raw_response_execute(self, client: ArcadeEngine) -> None: @@ -120,7 +117,7 @@ def test_raw_response_execute(self, client: ArcadeEngine) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" tool = response.parse() - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) @parametrize def test_streaming_response_execute(self, client: ArcadeEngine) -> None: @@ -134,7 +131,7 @@ def test_streaming_response_execute(self, client: ArcadeEngine) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" tool = response.parse() - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) assert cast(Any, response.is_closed) is True @@ -142,6 +139,40 @@ def test_streaming_response_execute(self, client: ArcadeEngine) -> None: class TestAsyncTools: parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + @parametrize + async def test_method_retrieve(self, async_client: AsyncArcadeEngine) -> None: + tool = await async_client.tools.retrieve( + director_id="director_id", + tool_id="tool_id", + ) + assert_matches_type(Definition, tool, path=["response"]) + + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncArcadeEngine) -> None: + response = await async_client.tools.with_raw_response.retrieve( + director_id="director_id", + tool_id="tool_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + tool = await response.parse() + assert_matches_type(Definition, tool, path=["response"]) + + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncArcadeEngine) -> None: + async with async_client.tools.with_streaming_response.retrieve( + director_id="director_id", + tool_id="tool_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + tool = await response.parse() + assert_matches_type(Definition, tool, path=["response"]) + + assert cast(Any, response.is_closed) is True + @parametrize async def test_method_authorize(self, async_client: AsyncArcadeEngine) -> None: tool = await async_client.tools.authorize( @@ -185,40 +216,6 @@ async def test_streaming_response_authorize(self, async_client: AsyncArcadeEngin assert cast(Any, response.is_closed) is True - @parametrize - async def test_method_definition(self, async_client: AsyncArcadeEngine) -> None: - tool = await async_client.tools.definition( - director_id="director_id", - tool_id="tool_id", - ) - assert_matches_type(Definition, tool, path=["response"]) - - @parametrize - async def test_raw_response_definition(self, async_client: AsyncArcadeEngine) -> None: - response = await async_client.tools.with_raw_response.definition( - director_id="director_id", - tool_id="tool_id", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = await response.parse() - assert_matches_type(Definition, tool, path=["response"]) - - @parametrize - async def test_streaming_response_definition(self, async_client: AsyncArcadeEngine) -> None: - async with async_client.tools.with_streaming_response.definition( - director_id="director_id", - tool_id="tool_id", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - tool = await response.parse() - assert_matches_type(Definition, tool, path=["response"]) - - assert cast(Any, response.is_closed) is True - @parametrize async def test_method_execute(self, async_client: AsyncArcadeEngine) -> None: tool = await async_client.tools.execute( @@ -227,7 +224,7 @@ async def test_method_execute(self, async_client: AsyncArcadeEngine) -> None: tool_version="tool_version", user_id="user_id", ) - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) @parametrize async def test_raw_response_execute(self, async_client: AsyncArcadeEngine) -> None: @@ -241,7 +238,7 @@ async def test_raw_response_execute(self, async_client: AsyncArcadeEngine) -> No assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" tool = await response.parse() - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) @parametrize async def test_streaming_response_execute(self, async_client: AsyncArcadeEngine) -> None: @@ -255,6 +252,6 @@ async def test_streaming_response_execute(self, async_client: AsyncArcadeEngine) assert response.http_request.headers.get("X-Stainless-Lang") == "python" tool = await response.parse() - assert_matches_type(ToolResponse, tool, path=["response"]) + assert_matches_type(Response, tool, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/conftest.py b/tests/conftest.py index c211a35d..6ae0e005 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,7 +26,7 @@ def event_loop() -> Iterator[asyncio.AbstractEventLoop]: base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") -bearer_token = "My Bearer Token" +api_key = "My API Key" @pytest.fixture(scope="session") @@ -35,7 +35,7 @@ def client(request: FixtureRequest) -> Iterator[ArcadeEngine]: if not isinstance(strict, bool): raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") - with ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=strict) as client: + with ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client: yield client @@ -45,7 +45,5 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncArcadeEngi if not isinstance(strict, bool): raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") - async with AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=strict - ) as client: + async with AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client: yield client diff --git a/tests/test_client.py b/tests/test_client.py index 9e42c089..e7679a4f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -31,7 +31,7 @@ from .utils import update_env base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") -bearer_token = "My Bearer Token" +api_key = "My API Key" def _get_params(client: BaseClient[Any, Any]) -> dict[str, str]: @@ -53,7 +53,7 @@ def _get_open_connections(client: ArcadeEngine | AsyncArcadeEngine) -> int: class TestArcadeEngine: - client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) @pytest.mark.respx(base_url=base_url) def test_raw_response(self, respx_mock: MockRouter) -> None: @@ -79,9 +79,9 @@ def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client) - copied = self.client.copy(bearer_token="another My Bearer Token") - assert copied.bearer_token == "another My Bearer Token" - assert self.client.bearer_token == "My Bearer Token" + copied = self.client.copy(api_key="another My API Key") + assert copied.api_key == "another My API Key" + assert self.client.api_key == "My API Key" def test_copy_default_options(self) -> None: # options that have a default are overridden correctly @@ -101,10 +101,7 @@ def test_copy_default_options(self) -> None: def test_copy_default_headers(self) -> None: client = ArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_headers={"X-Foo": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} ) assert client.default_headers["X-Foo"] == "bar" @@ -138,7 +135,7 @@ def test_copy_default_headers(self) -> None: def test_copy_default_query(self) -> None: client = ArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, default_query={"foo": "bar"} + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} ) assert _get_params(client)["foo"] == "bar" @@ -263,7 +260,7 @@ def test_request_timeout(self) -> None: def test_client_timeout_option(self) -> None: client = ArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, timeout=httpx.Timeout(0) + base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0) ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -274,7 +271,7 @@ def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used with httpx.Client(timeout=None) as http_client: client = ArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -284,7 +281,7 @@ def test_http_client_timeout_option(self) -> None: # no timeout given to the httpx client should not use the httpx default with httpx.Client() as http_client: client = ArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -294,7 +291,7 @@ def test_http_client_timeout_option(self) -> None: # explicitly passing the default timeout currently results in it being ignored with httpx.Client(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: client = ArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -306,17 +303,14 @@ async def test_invalid_http_client(self) -> None: async with httpx.AsyncClient() as http_client: ArcadeEngine( base_url=base_url, - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=cast(Any, http_client), ) def test_default_headers_option(self) -> None: client = ArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_headers={"X-Foo": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("x-foo") == "bar" @@ -324,7 +318,7 @@ def test_default_headers_option(self) -> None: client2 = ArcadeEngine( base_url=base_url, - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, default_headers={ "X-Foo": "stainless", @@ -337,10 +331,7 @@ def test_default_headers_option(self) -> None: def test_default_query_option(self) -> None: client = ArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_query={"query_param": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) url = httpx.URL(request.url) @@ -541,7 +532,7 @@ class Model(BaseModel): def test_base_url_setter(self) -> None: client = ArcadeEngine( - base_url="https://example.com/from_init", bearer_token=bearer_token, _strict_response_validation=True + base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True ) assert client.base_url == "https://example.com/from_init/" @@ -551,20 +542,18 @@ def test_base_url_setter(self) -> None: def test_base_url_env(self) -> None: with update_env(ARCADE_ENGINE_BASE_URL="http://localhost:5000/from/env"): - client = ArcadeEngine(bearer_token=bearer_token, _strict_response_validation=True) + client = ArcadeEngine(api_key=api_key, _strict_response_validation=True) assert client.base_url == "http://localhost:5000/from/env/" @pytest.mark.parametrize( "client", [ ArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), ArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -585,13 +574,11 @@ def test_base_url_trailing_slash(self, client: ArcadeEngine) -> None: "client", [ ArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), ArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -612,13 +599,11 @@ def test_base_url_no_trailing_slash(self, client: ArcadeEngine) -> None: "client", [ ArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), ArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -636,7 +621,7 @@ def test_absolute_request_url(self, client: ArcadeEngine) -> None: assert request.url == "https://myapi.com/foo" def test_copied_client_does_not_close_http(self) -> None: - client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) assert not client.is_closed() copied = client.copy() @@ -647,7 +632,7 @@ def test_copied_client_does_not_close_http(self) -> None: assert not client.is_closed() def test_client_context_manager(self) -> None: - client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) with client as c2: assert c2 is client assert not c2.is_closed() @@ -669,10 +654,7 @@ class Model(BaseModel): def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): ArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - max_retries=cast(Any, None), + base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None) ) @pytest.mark.respx(base_url=base_url) @@ -682,12 +664,12 @@ class Model(BaseModel): respx_mock.get("/foo").mock(return_value=httpx.Response(200, text="my-custom-format")) - strict_client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + strict_client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): strict_client.get("/foo", cast_to=Model) - client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=False) + client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=False) response = client.get("/foo", cast_to=Model) assert isinstance(response, str) # type: ignore[unreachable] @@ -715,7 +697,7 @@ class Model(BaseModel): ) @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: - client = ArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = ArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) @@ -769,7 +751,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = client.llm_completions.with_raw_response.create() + response = client.chat.with_raw_response.completions() assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -793,7 +775,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = client.llm_completions.with_raw_response.create(extra_headers={"x-stainless-retry-count": Omit()}) + response = client.chat.with_raw_response.completions(extra_headers={"x-stainless-retry-count": Omit()}) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -816,13 +798,13 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = client.llm_completions.with_raw_response.create(extra_headers={"x-stainless-retry-count": "42"}) + response = client.chat.with_raw_response.completions(extra_headers={"x-stainless-retry-count": "42"}) assert response.http_request.headers.get("x-stainless-retry-count") == "42" class TestAsyncArcadeEngine: - client = AsyncArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio @@ -850,9 +832,9 @@ def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client) - copied = self.client.copy(bearer_token="another My Bearer Token") - assert copied.bearer_token == "another My Bearer Token" - assert self.client.bearer_token == "My Bearer Token" + copied = self.client.copy(api_key="another My API Key") + assert copied.api_key == "another My API Key" + assert self.client.api_key == "My API Key" def test_copy_default_options(self) -> None: # options that have a default are overridden correctly @@ -872,10 +854,7 @@ def test_copy_default_options(self) -> None: def test_copy_default_headers(self) -> None: client = AsyncArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_headers={"X-Foo": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} ) assert client.default_headers["X-Foo"] == "bar" @@ -909,7 +888,7 @@ def test_copy_default_headers(self) -> None: def test_copy_default_query(self) -> None: client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, default_query={"foo": "bar"} + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} ) assert _get_params(client)["foo"] == "bar" @@ -1034,7 +1013,7 @@ async def test_request_timeout(self) -> None: async def test_client_timeout_option(self) -> None: client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, timeout=httpx.Timeout(0) + base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0) ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -1045,7 +1024,7 @@ async def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used async with httpx.AsyncClient(timeout=None) as http_client: client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -1055,7 +1034,7 @@ async def test_http_client_timeout_option(self) -> None: # no timeout given to the httpx client should not use the httpx default async with httpx.AsyncClient() as http_client: client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -1065,7 +1044,7 @@ async def test_http_client_timeout_option(self) -> None: # explicitly passing the default timeout currently results in it being ignored async with httpx.AsyncClient(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True, http_client=http_client + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) @@ -1077,17 +1056,14 @@ def test_invalid_http_client(self) -> None: with httpx.Client() as http_client: AsyncArcadeEngine( base_url=base_url, - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=cast(Any, http_client), ) def test_default_headers_option(self) -> None: client = AsyncArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_headers={"X-Foo": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("x-foo") == "bar" @@ -1095,7 +1071,7 @@ def test_default_headers_option(self) -> None: client2 = AsyncArcadeEngine( base_url=base_url, - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, default_headers={ "X-Foo": "stainless", @@ -1108,10 +1084,7 @@ def test_default_headers_option(self) -> None: def test_default_query_option(self) -> None: client = AsyncArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - default_query={"query_param": "bar"}, + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) url = httpx.URL(request.url) @@ -1312,7 +1285,7 @@ class Model(BaseModel): def test_base_url_setter(self) -> None: client = AsyncArcadeEngine( - base_url="https://example.com/from_init", bearer_token=bearer_token, _strict_response_validation=True + base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True ) assert client.base_url == "https://example.com/from_init/" @@ -1322,20 +1295,18 @@ def test_base_url_setter(self) -> None: def test_base_url_env(self) -> None: with update_env(ARCADE_ENGINE_BASE_URL="http://localhost:5000/from/env"): - client = AsyncArcadeEngine(bearer_token=bearer_token, _strict_response_validation=True) + client = AsyncArcadeEngine(api_key=api_key, _strict_response_validation=True) assert client.base_url == "http://localhost:5000/from/env/" @pytest.mark.parametrize( "client", [ AsyncArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), AsyncArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1356,13 +1327,11 @@ def test_base_url_trailing_slash(self, client: AsyncArcadeEngine) -> None: "client", [ AsyncArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), AsyncArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1383,13 +1352,11 @@ def test_base_url_no_trailing_slash(self, client: AsyncArcadeEngine) -> None: "client", [ AsyncArcadeEngine( - base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, - _strict_response_validation=True, + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True ), AsyncArcadeEngine( base_url="http://localhost:5000/custom/path/", - bearer_token=bearer_token, + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1407,7 +1374,7 @@ def test_absolute_request_url(self, client: AsyncArcadeEngine) -> None: assert request.url == "https://myapi.com/foo" async def test_copied_client_does_not_close_http(self) -> None: - client = AsyncArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) assert not client.is_closed() copied = client.copy() @@ -1419,7 +1386,7 @@ async def test_copied_client_does_not_close_http(self) -> None: assert not client.is_closed() async def test_client_context_manager(self) -> None: - client = AsyncArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) async with client as c2: assert c2 is client assert not c2.is_closed() @@ -1442,10 +1409,7 @@ class Model(BaseModel): async def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): AsyncArcadeEngine( - base_url=base_url, - bearer_token=bearer_token, - _strict_response_validation=True, - max_retries=cast(Any, None), + base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None) ) @pytest.mark.respx(base_url=base_url) @@ -1456,14 +1420,12 @@ class Model(BaseModel): respx_mock.get("/foo").mock(return_value=httpx.Response(200, text="my-custom-format")) - strict_client = AsyncArcadeEngine( - base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True - ) + strict_client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): await strict_client.get("/foo", cast_to=Model) - client = AsyncArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=False) + client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=False) response = await client.get("/foo", cast_to=Model) assert isinstance(response, str) # type: ignore[unreachable] @@ -1492,7 +1454,7 @@ class Model(BaseModel): @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) @pytest.mark.asyncio async def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: - client = AsyncArcadeEngine(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True) + client = AsyncArcadeEngine(base_url=base_url, api_key=api_key, _strict_response_validation=True) headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) @@ -1549,7 +1511,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = await client.llm_completions.with_raw_response.create() + response = await client.chat.with_raw_response.completions() assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -1574,9 +1536,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = await client.llm_completions.with_raw_response.create( - extra_headers={"x-stainless-retry-count": Omit()} - ) + response = await client.chat.with_raw_response.completions(extra_headers={"x-stainless-retry-count": Omit()}) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -1600,8 +1560,6 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: respx_mock.post("/v1/chat/completions").mock(side_effect=retry_handler) - response = await client.llm_completions.with_raw_response.create( - extra_headers={"x-stainless-retry-count": "42"} - ) + response = await client.chat.with_raw_response.completions(extra_headers={"x-stainless-retry-count": "42"}) assert response.http_request.headers.get("x-stainless-retry-count") == "42"