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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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():
Expand Down
20 changes: 10 additions & 10 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from arcade_engine.types import AuthorizationResponse
```

# Authorization
# Auth

Methods:

- <code title="post /v1/auth/authorize">client.authorization.<a href="./src/arcade_engine/resources/authorization.py">authorize</a>(\*\*<a href="src/arcade_engine/types/authorization_authorize_params.py">params</a>) -> <a href="./src/arcade_engine/types/shared/authorization_response.py">AuthorizationResponse</a></code>
- <code title="get /v1/auth/status">client.authorization.<a href="./src/arcade_engine/resources/authorization.py">status</a>(\*\*<a href="src/arcade_engine/types/authorization_status_params.py">params</a>) -> <a href="./src/arcade_engine/types/shared/authorization_response.py">AuthorizationResponse</a></code>
- <code title="post /v1/auth/authorize">client.auth.<a href="./src/arcade_engine/resources/auth.py">authorization</a>(\*\*<a href="src/arcade_engine/types/auth_authorization_params.py">params</a>) -> <a href="./src/arcade_engine/types/shared/authorization_response.py">AuthorizationResponse</a></code>
- <code title="get /v1/auth/status">client.auth.<a href="./src/arcade_engine/resources/auth.py">status</a>(\*\*<a href="src/arcade_engine/types/auth_status_params.py">params</a>) -> <a href="./src/arcade_engine/types/shared/authorization_response.py">AuthorizationResponse</a></code>

# LlmCompletions
# Chat

Types:

Expand All @@ -21,9 +21,9 @@ from arcade_engine.types import ChatResponse

Methods:

- <code title="post /v1/chat/completions">client.llm_completions.<a href="./src/arcade_engine/resources/llm_completions.py">create</a>(\*\*<a href="src/arcade_engine/types/llm_completion_create_params.py">params</a>) -> <a href="./src/arcade_engine/types/chat_response.py">ChatResponse</a></code>
- <code title="post /v1/chat/completions">client.chat.<a href="./src/arcade_engine/resources/chat.py">completions</a>(\*\*<a href="src/arcade_engine/types/chat_completions_params.py">params</a>) -> <a href="./src/arcade_engine/types/chat_response.py">ChatResponse</a></code>

# Operations
# Health

Types:

Expand All @@ -33,18 +33,18 @@ from arcade_engine.types import HealthSchema

Methods:

- <code title="get /v1/health">client.operations.<a href="./src/arcade_engine/resources/operations.py">health</a>() -> <a href="./src/arcade_engine/types/health_schema.py">HealthSchema</a></code>
- <code title="get /v1/health">client.health.<a href="./src/arcade_engine/resources/health.py">list</a>() -> <a href="./src/arcade_engine/types/health_schema.py">HealthSchema</a></code>

# Tools

Types:

```python
from arcade_engine.types import Definition, ToolResponse
from arcade_engine.types import Definition, Response
```

Methods:

- <code title="get /v1/tools/definition">client.tools.<a href="./src/arcade_engine/resources/tools.py">retrieve</a>(\*\*<a href="src/arcade_engine/types/tool_retrieve_params.py">params</a>) -> <a href="./src/arcade_engine/types/definition.py">Definition</a></code>
- <code title="post /v1/tools/authorize">client.tools.<a href="./src/arcade_engine/resources/tools.py">authorize</a>(\*\*<a href="src/arcade_engine/types/tool_authorize_params.py">params</a>) -> <a href="./src/arcade_engine/types/shared/authorization_response.py">AuthorizationResponse</a></code>
- <code title="get /v1/tools/definition">client.tools.<a href="./src/arcade_engine/resources/tools.py">definition</a>(\*\*<a href="src/arcade_engine/types/tool_definition_params.py">params</a>) -> <a href="./src/arcade_engine/types/definition.py">Definition</a></code>
- <code title="post /v1/tools/execute">client.tools.<a href="./src/arcade_engine/resources/tools.py">execute</a>(\*\*<a href="src/arcade_engine/types/tool_execute_params.py">params</a>) -> <a href="./src/arcade_engine/types/tool_response.py">ToolResponse</a></code>
- <code title="post /v1/tools/execute">client.tools.<a href="./src/arcade_engine/resources/tools.py">execute</a>(\*\*<a href="src/arcade_engine/types/tool_execute_params.py">params</a>) -> <a href="./src/arcade_engine/types/response.py">Response</a></code>
96 changes: 48 additions & 48 deletions src/arcade_engine/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)


Expand Down
Loading