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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:


steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Rye
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow is triggered when a GitHub release is created.
# It can also be run manually to re-publish to PyPI in case it failed for some reason.
# You can run this workflow by navigating to https://www.github.com/clibrain/python-sdk/actions/workflows/publish-pypi.yml
# You can run this workflow by navigating to https://www.github.com/maisaai/python-sdk/actions/workflows/publish-pypi.yml
name: Publish PyPI
on:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
release_doctor:
name: release doctor
runs-on: ubuntu-latest
if: github.repository == 'clibrain/python-sdk' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')
if: github.repository == 'maisaai/python-sdk' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 14
configured_endpoints: 15
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```bash
pip install git+ssh://git@github.com:clibrain/python-sdk.git
pip install git+ssh://git@github.com/maisaai/python-sdk.git
```

Alternatively, you can build from source and install the wheel file:
Expand All @@ -82,7 +82,7 @@ pip install ./path-to-wheel-file.whl

## Running tests

Most tests will require you to [setup a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```bash
# you will need npm installed
Expand Down Expand Up @@ -117,7 +117,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/clibrain/python-sdk/actions/workflows/publish-pypi.yml). This will require a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/maisaai/python-sdk/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ and offers both synchronous and asynchronous clients powered by [httpx](https://

## Documentation

The REST API documentation can be found [on maisa.ai](https://maisa.ai/). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found [on docs.maisa.ai](https://docs.maisa.ai/). The full API of this library can be found in [api.md](api.md).

## Installation

```sh
# install from PyPI
pip install --pre maisa
```

Expand All @@ -29,10 +30,10 @@ client = Maisa(
api_key=os.environ.get("MAISA_API_KEY"),
)

embeddings = client.models.embeddings.create(
texts=["string"],
text_summary = client.capabilities.summarize(
text="Example long text...",
)
print(embeddings.embeddings)
print(text_summary.summary)
```

While you can provide an `api_key` keyword argument,
Expand All @@ -56,10 +57,10 @@ client = AsyncMaisa(


async def main() -> None:
embeddings = await client.models.embeddings.create(
texts=["string"],
text_summary = await client.capabilities.summarize(
text="Example long text...",
)
print(embeddings.embeddings)
print(text_summary.summary)


asyncio.run(main())
Expand Down Expand Up @@ -92,8 +93,8 @@ from maisa import Maisa
client = Maisa()

try:
client.models.embeddings.create(
texts=["string"],
client.capabilities.summarize(
text="Example long text...",
)
except maisa.APIConnectionError as e:
print("The server could not be reached")
Expand Down Expand Up @@ -121,7 +122,7 @@ Error codes are as followed:

### Retries

Certain errors are automatically retried 3 times by default, with a short exponential backoff.
Certain errors are automatically retried 2 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
429 Rate Limit, and >=500 Internal errors are all retried by default.

Expand All @@ -137,8 +138,8 @@ client = Maisa(
)

# Or, configure per-request:
client.with_options(max_retries=5).models.embeddings.create(
texts=["string"],
client.with_options(max_retries=5).capabilities.summarize(
text="Example long text...",
)
```

Expand All @@ -162,8 +163,8 @@ client = Maisa(
)

# Override per-request:
client.with_options(timeout=5 * 1000).models.embeddings.create(
texts=["string"],
client.with_options(timeout=5 * 1000).capabilities.summarize(
text="Example long text...",
)
```

Expand Down Expand Up @@ -203,18 +204,18 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
from maisa import Maisa

client = Maisa()
response = client.models.embeddings.with_raw_response.create(
texts=["string"],
response = client.capabilities.with_raw_response.summarize(
text="Example long text...",
)
print(response.headers.get('X-My-Header'))

embedding = response.parse() # get the object that `models.embeddings.create()` would have returned
print(embedding.embeddings)
capability = response.parse() # get the object that `capabilities.summarize()` would have returned
print(capability.summary)
```

These methods return an [`APIResponse`](https://github.com/clibrain/python-sdk/tree/main/src/maisa/_response.py) object.
These methods return an [`APIResponse`](https://github.com/maisaai/python-sdk/tree/main/src/maisa/_response.py) object.

The async client returns an [`AsyncAPIResponse`](https://github.com/clibrain/python-sdk/tree/main/src/maisa/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
The async client returns an [`AsyncAPIResponse`](https://github.com/maisaai/python-sdk/tree/main/src/maisa/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.

#### `.with_streaming_response`

Expand All @@ -223,8 +224,8 @@ 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.models.embeddings.with_streaming_response.create(
texts=["string"],
with client.capabilities.with_streaming_response.summarize(
text="Example long text...",
) as response:
print(response.headers.get("X-My-Header"))

Expand Down Expand Up @@ -270,7 +271,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/clibrain/python-sdk/issues) with questions, bugs, or suggestions.
We are keen for your feedback; please open an [issue](https://www.github.com/maisaai/python-sdk/issues) with questions, bugs, or suggestions.

## Requirements

Expand Down
12 changes: 12 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ Methods:

- <code title="post /v1/models/rerank">client.models.rerank.<a href="./src/maisa/resources/models/rerank.py">create</a>(\*\*<a href="src/maisa/types/models/rerank_create_params.py">params</a>) -> <a href="./src/maisa/types/models/rerank.py">Rerank</a></code>

# Kpu

Types:

```python
from maisa.types import KpuRunResponse
```

Methods:

- <code title="post /v1/kpu/run">client.kpu.<a href="./src/maisa/resources/kpu.py">run</a>(\*\*<a href="src/maisa/types/kpu_run_params.py">params</a>) -> <a href="./src/maisa/types/kpu_run_response.py">KpuRunResponse</a></code>

# FileInterpreter

## FromPdf
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ classifiers = [


[project.urls]
Homepage = "https://github.com/clibrain/python-sdk"
Repository = "https://github.com/clibrain/python-sdk"
Homepage = "https://github.com/maisaai/python-sdk"
Repository = "https://github.com/maisaai/python-sdk"



Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pydantic==2.4.2
# via maisa
pydantic-core==2.10.1
# via pydantic
pyright==1.1.332
pyright==1.1.351
pytest==7.1.1
# via pytest-asyncio
pytest-asyncio==0.21.1
Expand Down
15 changes: 14 additions & 1 deletion src/maisa/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
RAW_RESPONSE_HEADER,
OVERRIDE_CAST_TO_HEADER,
)
from ._streaming import Stream, AsyncStream
from ._streaming import Stream, SSEDecoder, AsyncStream, SSEBytesDecoder
from ._exceptions import (
APIStatusError,
APITimeoutError,
Expand Down Expand Up @@ -430,6 +430,9 @@ def _prepare_url(self, url: str) -> URL:

return merge_url

def _make_sse_decoder(self) -> SSEDecoder | SSEBytesDecoder:
return SSEDecoder()

def _build_request(
self,
options: FinalRequestOptions,
Expand Down Expand Up @@ -776,6 +779,11 @@ def __init__(
else:
timeout = DEFAULT_TIMEOUT

if http_client is not None and not isinstance(http_client, httpx.Client): # pyright: ignore[reportUnnecessaryIsInstance]
raise TypeError(
f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got {type(http_client)}"
)

super().__init__(
version=version,
limits=limits,
Expand Down Expand Up @@ -1305,6 +1313,11 @@ def __init__(
else:
timeout = DEFAULT_TIMEOUT

if http_client is not None and not isinstance(http_client, httpx.AsyncClient): # pyright: ignore[reportUnnecessaryIsInstance]
raise TypeError(
f"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got {type(http_client)}"
)

super().__init__(
version=version,
base_url=base_url,
Expand Down
8 changes: 8 additions & 0 deletions src/maisa/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
class Maisa(SyncAPIClient):
capabilities: resources.Capabilities
models: resources.Models
kpu: resources.Kpu
file_interpreter: resources.FileInterpreter
mainet: resources.Mainet
with_raw_response: MaisaWithRawResponse
Expand Down Expand Up @@ -107,6 +108,7 @@ def __init__(

self.capabilities = resources.Capabilities(self)
self.models = resources.Models(self)
self.kpu = resources.Kpu(self)
self.file_interpreter = resources.FileInterpreter(self)
self.mainet = resources.Mainet(self)
self.with_raw_response = MaisaWithRawResponse(self)
Expand Down Expand Up @@ -220,6 +222,7 @@ def _make_status_error(
class AsyncMaisa(AsyncAPIClient):
capabilities: resources.AsyncCapabilities
models: resources.AsyncModels
kpu: resources.AsyncKpu
file_interpreter: resources.AsyncFileInterpreter
mainet: resources.AsyncMainet
with_raw_response: AsyncMaisaWithRawResponse
Expand Down Expand Up @@ -279,6 +282,7 @@ def __init__(

self.capabilities = resources.AsyncCapabilities(self)
self.models = resources.AsyncModels(self)
self.kpu = resources.AsyncKpu(self)
self.file_interpreter = resources.AsyncFileInterpreter(self)
self.mainet = resources.AsyncMainet(self)
self.with_raw_response = AsyncMaisaWithRawResponse(self)
Expand Down Expand Up @@ -393,6 +397,7 @@ class MaisaWithRawResponse:
def __init__(self, client: Maisa) -> None:
self.capabilities = resources.CapabilitiesWithRawResponse(client.capabilities)
self.models = resources.ModelsWithRawResponse(client.models)
self.kpu = resources.KpuWithRawResponse(client.kpu)
self.file_interpreter = resources.FileInterpreterWithRawResponse(client.file_interpreter)
self.mainet = resources.MainetWithRawResponse(client.mainet)

Expand All @@ -401,6 +406,7 @@ class AsyncMaisaWithRawResponse:
def __init__(self, client: AsyncMaisa) -> None:
self.capabilities = resources.AsyncCapabilitiesWithRawResponse(client.capabilities)
self.models = resources.AsyncModelsWithRawResponse(client.models)
self.kpu = resources.AsyncKpuWithRawResponse(client.kpu)
self.file_interpreter = resources.AsyncFileInterpreterWithRawResponse(client.file_interpreter)
self.mainet = resources.AsyncMainetWithRawResponse(client.mainet)

Expand All @@ -409,6 +415,7 @@ class MaisaWithStreamedResponse:
def __init__(self, client: Maisa) -> None:
self.capabilities = resources.CapabilitiesWithStreamingResponse(client.capabilities)
self.models = resources.ModelsWithStreamingResponse(client.models)
self.kpu = resources.KpuWithStreamingResponse(client.kpu)
self.file_interpreter = resources.FileInterpreterWithStreamingResponse(client.file_interpreter)
self.mainet = resources.MainetWithStreamingResponse(client.mainet)

Expand All @@ -417,6 +424,7 @@ class AsyncMaisaWithStreamedResponse:
def __init__(self, client: AsyncMaisa) -> None:
self.capabilities = resources.AsyncCapabilitiesWithStreamingResponse(client.capabilities)
self.models = resources.AsyncModelsWithStreamingResponse(client.models)
self.kpu = resources.AsyncKpuWithStreamingResponse(client.kpu)
self.file_interpreter = resources.AsyncFileInterpreterWithStreamingResponse(client.file_interpreter)
self.mainet = resources.AsyncMainetWithStreamingResponse(client.mainet)

Expand Down
2 changes: 1 addition & 1 deletion src/maisa/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# default timeout is 1 minute
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
DEFAULT_MAX_RETRIES = 3
DEFAULT_MAX_RETRIES = 2
DEFAULT_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)

INITIAL_RETRY_DELAY = 0.5
Expand Down
5 changes: 5 additions & 0 deletions src/maisa/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
FileContent,
RequestFiles,
HttpxFileTypes,
Base64FileInput,
HttpxFileContent,
HttpxRequestFiles,
)
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t


def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
return isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)


def is_file_content(obj: object) -> TypeGuard[FileContent]:
return (
isinstance(obj, bytes) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
Expand Down
2 changes: 1 addition & 1 deletion src/maisa/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def construct_type(*, value: object, type_: type) -> object:

if is_union(origin):
try:
return validate_type(type_=type_, value=value)
return validate_type(type_=cast("type[object]", type_), value=value)
except Exception:
pass

Expand Down
5 changes: 3 additions & 2 deletions src/maisa/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from __future__ import annotations

import time
import asyncio
from typing import TYPE_CHECKING

import anyio

if TYPE_CHECKING:
from ._client import Maisa, AsyncMaisa

Expand Down Expand Up @@ -39,4 +40,4 @@ def __init__(self, client: AsyncMaisa) -> None:
self._get_api_list = client.get_api_list

async def _sleep(self, seconds: float) -> None:
await asyncio.sleep(seconds)
await anyio.sleep(seconds)
Loading