LaunchDarkly AI SDK OpenAI Provider
Project description
LaunchDarkly AI SDK OpenAI Provider
[!CAUTION] This package is in pre-release and not subject to backwards compatibility guarantees. The API may change based on feedback.
Pin to a specific minor version and review the changelog before upgrading.
This package provides an OpenAI integration for the LaunchDarkly AI SDK.
Installation
pip install launchdarkly-server-sdk-ai-openai
Quick Start
import asyncio
from ldai import AIClient
from ldai_openai import OpenAIProvider
async def main():
# Initialize the AI client
ai_client = AIClient(ld_client)
# Get AI config. Pass a default for improved resiliency when the flag is unavailable or
# LaunchDarkly is unreachable; omit for a disabled default. Example:
# from ldai.models import AICompletionConfigDefault, LDMessage, ModelConfig, ProviderConfig
# default = AICompletionConfigDefault(
# enabled=True,
# model=ModelConfig("gpt-4"),
# provider=ProviderConfig("openai"),
# messages=[LDMessage(role="system", content="You are a helpful assistant.")]
# )
# ai_config = ai_client.config("my-ai-config-key", context, default)
ai_config = ai_client.config("my-ai-config-key", context)
# Create an OpenAI provider from the config
provider = await OpenAIProvider.create(ai_config)
# Invoke the model
response = await provider.invoke_model(ai_config.messages)
print(response.message.content)
asyncio.run(main())
Features
- Full integration with OpenAI's chat completions API
- Automatic token usage tracking
- Support for structured output (JSON schema)
- Static utility methods for custom integrations
API Reference
OpenAIProvider
Constructor
OpenAIProvider(client: OpenAI, model_name: str, parameters: Dict[str, Any], logger: Optional[Any] = None)
Static Methods
create(ai_config: AIConfigKind, logger: Optional[Any] = None) -> OpenAIProvider- Factory method to create a provider from an AI configget_ai_metrics_from_response(response: Any) -> LDAIMetrics- Extract metrics from an OpenAI response
Instance Methods
invoke_model(messages: List[LDMessage]) -> ChatResponse- Invoke the model with messagesinvoke_structured_model(messages: List[LDMessage], response_structure: Dict[str, Any]) -> StructuredResponse- Invoke the model with structured outputget_client() -> OpenAI- Get the underlying OpenAI client
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file launchdarkly_server_sdk_ai_openai-0.4.0.tar.gz.
File metadata
- Download URL: launchdarkly_server_sdk_ai_openai-0.4.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f25a875ced5eda580819e7a6a7ab848d4d57f01277c2d7ccaad9e0a4001156e4
|
|
| MD5 |
a44fe7bff1be222cd1f187d7da466fee
|
|
| BLAKE2b-256 |
4c6674c079b642f2cf3258fccdc3bd29ce157f5d4aae96e41b5470df58719dfe
|
File details
Details for the file launchdarkly_server_sdk_ai_openai-0.4.0-py3-none-any.whl.
File metadata
- Download URL: launchdarkly_server_sdk_ai_openai-0.4.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc76fbc0de198e8a504d356924e2d5ce5ee17d8fee3914990c2ccdadb1fc32a8
|
|
| MD5 |
26433a08d583c11044a28d2a5f937f2b
|
|
| BLAKE2b-256 |
b5bdd3cd1119b52cd2005139fcba249013688accfd35d54f151eb8bb319eb218
|