Skip to main content

No project description provided

Project description

Octo AI Python Library

fern shield

The Octo AI Python Library provides convenient access to the Octo AI API from applications written in Python.

Documentation

API reference documentation is available here.

Whisper is not currently available. If you're interested in using speech-to-text models, please contact us at customer-success@octo.ai

Installation

Add this dependency to your project's build file:

pip install octoai
# or
poetry add octoai

Usage

Simply import OctoAI and start making calls to our API.

from octoai.client import OctoAI
from octoai.text_gen import ChatMessage

client = OctoAI(
    api_key="YOUR_API_KEY"  # Defaults to your OCTOAI_TOKEN environment variable
)
client.text_gen.create_chat_completion(
    messages=[
        ChatMessage(
            role="role",
        )
    ],
    model="model",
)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

from octoai.client import AsyncOctoAI
from octoai.text_gen import ChatMessage

client = AsyncOctoAI(
  api_key="YOUR_API_KEY" # Defaults to your OCTOAI_TOKEN environment variable
)

async def main() -> None:
    await client.text_gen.create_chat_completion(
        messages=[
            ChatMessage(
                role="role",
            )
        ],
        model="model",
    )

asyncio.run(main())

OctoAI Services

The client nests key services within the provisioned client:

from octoai.client import OctoAI

client = OctoAI(...)

# The image generation service
client.image_gen.generate_sd(...)

# The text generation service
client.text_gen.create_chat_completion(...)

# The asset library service
client.asset_library.create(...)

# The fine-tuning service
client.fine_tuning.create(...)

Exception Handling

All errors thrown by the SDK will be subclasses of ApiError.

import octoai

try:
  client.text_gen.create_chat_completion(...)
except octoai.core.ApiError as e: # Handle all errors
  print(e.status_code)
  print(e.body)

Advanced

Retries

The OctoAI SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit.

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 409 (Conflict)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

from octoai.client import OctoAI

client = OctoAI(...)

# Override retries for a specific method
client.text_gen.create_chat_completion(..., {
    max_retries=5
})

Timeouts

By default, requests time out after 60 seconds. You can configure this with a timeout option at the client or request level.

from octoai.client import OctoAI

client = OctoAI(
    # All timeouts are 20 seconds
    timeout=20.0,
)

# Override timeout for a specific method
client.text_gen.create_chat_completion(..., {
    timeout_in_seconds=20.0
})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx

from octoai.client import OctoAI

client = OctoAI(
    http_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Beta Status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version. This way, you can install the same version each time without breaking changes.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

octoai-1.11.0.tar.gz (51.9 kB view details)

Uploaded Source

Built Distribution

octoai-1.11.0-py3-none-any.whl (113.7 kB view details)

Uploaded Python 3

File details

Details for the file octoai-1.11.0.tar.gz.

File metadata

  • Download URL: octoai-1.11.0.tar.gz
  • Upload date:
  • Size: 51.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1071-azure

File hashes

Hashes for octoai-1.11.0.tar.gz
Algorithm Hash digest
SHA256 aaea3b6a1d88dde526018560557aa2bcf183ccbd5563bcdf7e65a54efd58151e
MD5 4806234830a12ea1e948970db73b3ffa
BLAKE2b-256 03e392824a85c61ccd0ad62703cb1d3805335525cafdcc24e060b58540f55193

See more details on using hashes here.

File details

Details for the file octoai-1.11.0-py3-none-any.whl.

File metadata

  • Download URL: octoai-1.11.0-py3-none-any.whl
  • Upload date:
  • Size: 113.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1071-azure

File hashes

Hashes for octoai-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c6ef50dffe3beac20f16e8b949069ba9ea970fccbe2476ea7ea15302e670a15
MD5 0731dbb0e983c71d51be8af09c39ee88
BLAKE2b-256 c02851a9eec201e1ab45ca80845ef1dcc0efd56a1237f2d18344a55c7be36c49

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page