Skip to main content

A Python client library for the CodeAira API

Project description

CodeAira Python Client

Introduction

CodeAira Python Client is a powerful and easy-to-use library for interacting with the CodeAira API for text completion tasks. This library simplifies the process of making requests to the CodeAira API, handling responses, and managing errors.

Installation

To install the CodeAira Python Client, use pip:

pip install codeaira-python

Configuration Before using the library, you need to set up your CodeAira API key as an environment variable:

set CODEAIRA_API_KEY=your_api_key_here

Alternatively, you can use a .env file in your project directory:

CODEAIRA_API_KEY=your_api_key_here

Usage

Here's a basic example of how to use the CodeAira Python Client:

from codeaira import CodeAiraClient

client = CodeAiraClient()

response = client.complete_text(
    model_name="gpt-3.5-turbo",
    prompt="Translate the following English text to French: 'Hello, world!'",
    context="This is a translation task."
)

print(response.choices[0].text)

API Reference

CodeAiraClient

The main class for interacting with the CodeAira API.

Methods

complete_text(model_name: str, prompt: str, context: str = None, app_id: str = None) -> CompletionResponse

Sends a text completion request to the CodeAira API.

model_name: The name of the model to use for completion.
prompt: The text prompt for completion.
context (optional): Additional context for the completion task.
app_id (optional): An identifier for the application making the request.
Returns a CompletionResponse object.

Data Models

  • CodeAiraRequest: Represents the structure of a request to the CodeAira API.
  • CompletionResponse: Represents the structure of a response from the CodeAira API.
  • CompletionChoice: Represents a single completion choice in the API response.

Error Handling

The library uses custom exceptions to handle various error scenarios:

  • ConfigurationError: Raised when there's an issue with the API key configuration.
  • APIError: Raised when the API returns an error response.
  • NetworkError: Raised when there's a network-related issue.
  • ValidationError: Raised when there's a data validation error. Example of error handling:
from codeaira import CodeAiraClient, APIError, NetworkError

client = CodeAiraClient()

try:
    response = client.complete_text(
        model_name="gpt-3.5-turbo",
        prompt="Generate a story about a robot."
    )
    print(response.choices[0].text)
except APIError as e:
    print(f"API Error: {e}")
except NetworkError as e:
    print(f"Network Error: {e}")

Logging

The library uses Python's built-in logging module to provide informative logs. You can configure the logging level and format as needed in your application.

Example of configuring logging:

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('codeaira')

Compatibility

CodeAira Python Client supports Python 3.9 and above.

Contributing

Contributions to the CodeAira Python Client are welcome! Please refer to the project's GitHub repository for guidelines on how to contribute.

License

This project is licensed under the MIT License. See the LICENSE file for details

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

codeaira_python-0.4.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeaira_python-0.4.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file codeaira_python-0.4.0.tar.gz.

File metadata

  • Download URL: codeaira_python-0.4.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.18

File hashes

Hashes for codeaira_python-0.4.0.tar.gz
Algorithm Hash digest
SHA256 92e82a53d39917b0e84e3a58dda9aa668d8b0046d71856ae36ecaf6da234d0c4
MD5 acbcd8921c49675b413dbe0a7aa82cad
BLAKE2b-256 054c2ccb3ba937041b3409eac2f440e69ae4c5c38784b514b0bd260e21b52540

See more details on using hashes here.

File details

Details for the file codeaira_python-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codeaira_python-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9ed9fae043ae985e8ffe7b19ff68d934e9fbdb94bef1b46da0e9ee2895e6592
MD5 f944bc84da428660ac6fdb55a4789a50
BLAKE2b-256 386f9739187dc76561f9a1e0964b137ae665943055bf21749685293a1765a9ea

See more details on using hashes here.

Supported by

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