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.3.0.tar.gz (15.6 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.3.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for codeaira_python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3d41a45d0e0402c978b59b4aaea54d8fb208458e7db4fccc6e5d8d22f49ad7b1
MD5 9d0a82275654dcd7d61fc380bcca9946
BLAKE2b-256 7481a4e7ebbadcf3a7104f46be5562d9e1072f16428a43443b0a6af0bb3024ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for codeaira_python-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3239726bc19dedafea349a7d2776a3eb1561fae338ab7d887f07f2f26a5f077
MD5 22b1fbcb5c5b549768cf732e54d30ecf
BLAKE2b-256 4639b9e2d47ccdaafb0c6c6c23b4c08601ffaff1a984885ed021c9ef11b65e00

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