Skip to main content

OpenAI adapter of rag-control

Project description

OpenAI Adapter for RAG Control

A high-performance OpenAI adapter for RAG (Retrieval-Augmented Generation) systems, providing seamless integration with rag-control framework for LLM and embedding operations.

Features

  • 🚀 High-Performance LLM Generation - Support for chat completions with streaming
  • 🔍 Query Embeddings - Generate embeddings for text queries using OpenAI's embedding models
  • 📊 Comprehensive Metadata - Track latency, token usage, and request IDs
  • ⚙️ Flexible Configuration - Full OpenAI client configuration support
  • 🛡️ Error Handling - Robust exception handling with custom adapter errors
  • 📝 Type-Safe - Full type annotations for Python static analysis

Installation

Install the package from PyPI:

pip install openai-adapter

Or with uv:

uv pip install openai-adapter

For development installation from source:

git clone <repo-url>
cd openai-adapter
uv sync

Version Compatibility

  • Current Stable Version: v0.1.0
  • Compatible with: rag-control v0.1.3

Quick Start

Integration with rag-control

The OpenAI Adapter is designed to integrate seamlessly with the rag-control framework:

from rag_control import RAGControl
from openai_adapter import OpenAILLMAdapter, OpenAIQueryEmbeddingAdapter

# Initialize adapters
llm_adapter = OpenAILLMAdapter(api_key="sk-...")
embedding_adapter = OpenAIQueryEmbeddingAdapter(api_key="sk-...")

# Create RAG system with OpenAI adapters
rag = RAGControl(
  llm_adapter=llm_adapter,
  embedding_adapter=embedding_adapter
)

# Use for RAG operations
response = rag.query("What is machine learning?")
print(response.answer)

API Reference

OpenAILLMAdapter

__init__(api_key: str, model: str = "gpt-3.5-turbo", **kwargs)

Initialize the LLM adapter.

Parameters:

  • api_key (str): OpenAI API key for authentication
  • model (str): Language model to use (default: gpt-3.5-turbo)
  • **kwargs: Additional OpenAI client configuration
    • organization (str): Organization ID
    • project (str): Project ID
    • base_url (str): Custom API endpoint
    • timeout (float): Request timeout in seconds

Raises:

  • LLMAdapterError: If client initialization fails

OpenAIQueryEmbeddingAdapter

__init__(api_key: str, model: str = "text-embedding-3-small", **kwargs)

Initialize the embedding adapter.

Parameters:

  • api_key (str): OpenAI API key
  • model (str): Embedding model (default: text-embedding-3-small)
  • **kwargs: Additional OpenAI client configuration

Raises:

  • QueryEmbeddingAdapterError: If client initialization fails

Development & Contributing

For information on setting up a development environment, code style guidelines, and contribution guidelines, see:

License

Licensed under the Apache License 2.0. See LICENSE file for details.

Support

For issues and questions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review error messages for guidance

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

openai_adapter-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

openai_adapter-0.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file openai_adapter-0.1.0.tar.gz.

File metadata

  • Download URL: openai_adapter-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for openai_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a014cbfbd68044b03c018abaf1b9cdac68003ba8e128d6bc31641eebc456fd90
MD5 f6aaa1100b9a86b4c820d7fd8b6078c1
BLAKE2b-256 d52ac0d54d9334b2853eb74d4110bab27fb48ba17440eb6ff23fa5cef7a16fa7

See more details on using hashes here.

File details

Details for the file openai_adapter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openai_adapter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for openai_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fb6efc744d4f8872090b01f9f61016f79fe8a5930f43a252198a6ae41bc3b04
MD5 f213f4148f1793d3cd8a9c44d4c8f0fe
BLAKE2b-256 6eff479fd15f0ad156e70dab78f2c1d1093b646201f39f3cc0e5046f82b17153

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