-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add OpenAI provider package #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
01c87a5
feat: Add OpenAI and Vercel provider packages
edwinokonkwo 8cfabc3
fix lint
edwinokonkwo 2ea03ac
fixes
edwinokonkwo 820b202
remove vercel package
jsonbailey a7af08b
remove unnecessary method
jsonbailey 0ffaea0
improve logging
jsonbailey b6b2c96
update to final name
jsonbailey 8fe67a3
use log provided by ldai
jsonbailey 0fd05e1
Merge branch 'main' into REL-10774
jsonbailey dc76be2
fixing tests
jsonbailey 07bb215
Remove unnecessary comments
jsonbailey a426119
Merge branch 'main' into REL-10774
jsonbailey 81fe0a8
set correct version
jsonbailey c9fdaaf
fix component name
jsonbailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ on: | |
| options: | ||
| - packages/sdk/server-ai | ||
| - packages/ai-providers/server-ai-langchain | ||
| - packages/ai-providers/server-ai-openai | ||
| dry_run: | ||
| description: 'Is this a dry run. If so no package will be published.' | ||
| type: boolean | ||
|
|
@@ -43,6 +44,8 @@ jobs: | |
| package-server-ai-tag-name: ${{ steps.release.outputs['packages/sdk/server-ai--tag_name'] }} | ||
| package-server-ai-langchain-released: ${{ steps.release.outputs['packages/ai-providers/server-ai-langchain--release_created'] }} | ||
| package-server-ai-langchain-tag-name: ${{ steps.release.outputs['packages/ai-providers/server-ai-langchain--tag_name'] }} | ||
| package-server-ai-openai-released: ${{ steps.release.outputs['packages/ai-providers/server-ai-openai--release_created'] }} | ||
| package-server-ai-openai-tag-name: ${{ steps.release.outputs['packages/ai-providers/server-ai-openai--tag_name'] }} | ||
| steps: | ||
| - uses: googleapis/release-please-action@v4 | ||
| id: release | ||
|
|
@@ -193,3 +196,57 @@ jobs: | |
| base64-subjects: "${{ needs.release-server-ai-langchain.outputs.package-hashes }}" | ||
| upload-assets: true | ||
| upload-tag-name: ${{ needs.release-please.outputs.package-server-ai-langchain-tag-name }} | ||
|
|
||
| release-server-ai-openai: | ||
| runs-on: ubuntu-latest | ||
| needs: ['release-please'] | ||
| permissions: | ||
| id-token: write # Needed for OIDC to get release secrets from AWS. | ||
| if: ${{ needs.release-please.outputs.package-server-ai-openai-released == 'true' }} | ||
| outputs: | ||
| package-hashes: ${{ steps.build.outputs.package-hashes }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install poetry | ||
| uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439 | ||
|
|
||
| - uses: ./.github/actions/ci | ||
| with: | ||
| workspace_path: packages/ai-providers/server-ai-openai | ||
|
|
||
| - uses: ./.github/actions/build | ||
| id: build | ||
| with: | ||
| workspace_path: packages/ai-providers/server-ai-openai | ||
|
|
||
| - uses: launchdarkly/gh-actions/actions/[email protected] | ||
| name: 'Get PyPI token' | ||
| with: | ||
| aws_assume_role: ${{ vars.AWS_ROLE_ARN }} | ||
| ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN' | ||
|
|
||
| - name: Publish to PyPI | ||
| uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 | ||
| with: | ||
| password: ${{ env.PYPI_AUTH_TOKEN }} | ||
| packages-dir: packages/ai-providers/server-ai-openai/dist/ | ||
|
|
||
| release-server-ai-openai-provenance: | ||
| needs: ['release-please', 'release-server-ai-openai'] | ||
| if: ${{ needs.release-please.outputs.package-server-ai-openai-released == 'true' }} | ||
| permissions: | ||
| actions: read # Needed for detecting the GitHub Actions environment. | ||
| id-token: write # Needed for provenance signing. | ||
| contents: write # Needed for uploading assets to the release. | ||
| uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | ||
| with: | ||
| base64-subjects: "${{ needs.release-server-ai-openai.outputs.package-hashes }}" | ||
| upload-assets: true | ||
| upload-tag-name: ${{ needs.release-please.outputs.package-server-ai-openai-tag-name }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| { | ||
| "packages/sdk/server-ai": "0.12.0", | ||
| "packages/ai-providers/server-ai-langchain": "0.3.0" | ||
| "packages/ai-providers/server-ai-langchain": "0.3.0", | ||
| "packages/ai-providers/server-ai-openai": "0.0.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| PYTEST_FLAGS=-W error::SyntaxWarning | ||
|
|
||
| .PHONY: help | ||
| help: #! Show this help message | ||
| @echo 'Usage: make [target] ... ' | ||
| @echo '' | ||
| @echo 'Targets:' | ||
| @grep -h -F '#!' $(MAKEFILE_LIST) | grep -v grep | sed 's/:.*#!/:/' | column -t -s":" | ||
|
|
||
| .PHONY: install | ||
| install: #! Install package dependencies | ||
| poetry install | ||
|
|
||
| .PHONY: test | ||
| test: #! Run unit tests | ||
| test: install | ||
| poetry run pytest $(PYTEST_FLAGS) | ||
|
|
||
| .PHONY: lint | ||
| lint: #! Run type analysis and linting checks | ||
| lint: install | ||
| poetry run mypy src/ldai_openai | ||
| poetry run isort --check --atomic src/ldai_openai | ||
| poetry run pycodestyle src/ldai_openai | ||
|
|
||
| .PHONY: build | ||
| build: #! Build distribution files | ||
| build: install | ||
| poetry build | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # LaunchDarkly AI SDK OpenAI Provider | ||
|
|
||
| [](https://pypi.org/project/launchdarkly-server-sdk-ai-openai-dev/) | ||
|
|
||
| This package provides an OpenAI integration for the LaunchDarkly AI SDK. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install launchdarkly-server-sdk-ai-openai-dev | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```python | ||
| 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 | ||
| ai_config = ai_client.config( | ||
| "my-ai-config-key", | ||
| context, | ||
| default_value | ||
| ) | ||
|
|
||
| # 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 | ||
|
|
||
| ```python | ||
| 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 config | ||
| - `get_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 messages | ||
| - `invoke_structured_model(messages: List[LDMessage], response_structure: Dict[str, Any]) -> StructuredResponse` - Invoke the model with structured output | ||
| - `get_client() -> OpenAI` - Get the underlying OpenAI client | ||
|
|
||
| ## License | ||
|
|
||
| Apache-2.0 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| [tool.poetry] | ||
| name = "launchdarkly-server-sdk-ai-openai" | ||
| version = "0.0.0" | ||
| description = "LaunchDarkly AI SDK OpenAI Provider" | ||
| authors = ["LaunchDarkly <[email protected]>"] | ||
| license = "Apache-2.0" | ||
| readme = "README.md" | ||
| homepage = "https://docs.launchdarkly.com/sdk/ai/python" | ||
| repository = "https://github.com/launchdarkly/python-server-sdk-ai" | ||
| classifiers = [ | ||
| "Intended Audience :: Developers", | ||
| "License :: OSI Approved :: Apache Software License", | ||
| "Operating System :: OS Independent", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.9", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Topic :: Software Development", | ||
| "Topic :: Software Development :: Libraries", | ||
| ] | ||
| packages = [{ include = "ldai_openai", from = "src" }] | ||
|
|
||
| [tool.poetry.dependencies] | ||
| python = ">=3.9,<4" | ||
| launchdarkly-server-sdk-ai = ">=0.12.0" | ||
| openai = ">=1.0.0" | ||
|
|
||
| [tool.poetry.group.dev.dependencies] | ||
| pytest = ">=2.8" | ||
| pytest-cov = ">=2.4.0" | ||
| pytest-asyncio = ">=0.21.0,<1.0.0" | ||
| mypy = "==1.18.2" | ||
| pycodestyle = ">=2.11.0" | ||
| isort = ">=5.12.0" | ||
|
|
||
| [tool.mypy] | ||
| python_version = "3.9" | ||
| ignore_missing_imports = true | ||
| install_types = true | ||
| non_interactive = true | ||
|
|
||
| [tool.isort] | ||
| profile = "black" | ||
| known_third_party = ["openai", "ldai"] | ||
| sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] | ||
|
|
||
|
|
||
| [tool.pytest.ini_options] | ||
| addopts = ["-ra"] | ||
| testpaths = ["tests"] | ||
| asyncio_mode = "auto" | ||
|
|
||
|
|
||
| [build-system] | ||
| requires = ["poetry-core"] | ||
| build-backend = "poetry.core.masonry.api" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pycodestyle] | ||
| max-line-length = 120 |
5 changes: 5 additions & 0 deletions
5
packages/ai-providers/server-ai-openai/src/ldai_openai/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """LaunchDarkly AI SDK OpenAI Provider.""" | ||
|
|
||
| from ldai_openai.openai_provider import OpenAIProvider | ||
|
|
||
| __all__ = ['OpenAIProvider'] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a separate PR, you could work on dropping 3.9 from this repo given our recent conversations.