Skip to content

Commit 5722911

Browse files
authored
feat: Add OpenAI Provider for AI SDK (#947)
Release-as: 0.1.0
1 parent 1db731b commit 5722911

18 files changed

+635
-0
lines changed

.github/workflows/manual-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ on:
3535
- packages/tooling/jest
3636
- packages/sdk/browser
3737
- packages/sdk/server-ai
38+
- packages/ai-providers/server-ai-openai
3839
- packages/ai-providers/server-ai-vercel
3940
- packages/ai-providers/server-ai-langchain
4041
- packages/telemetry/browser-telemetry

.github/workflows/release-please.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
package-browser-released: ${{ steps.release.outputs['packages/sdk/browser--release_created'] }}
2929
package-server-ai-released: ${{ steps.release.outputs['packages/sdk/server-ai--release_created'] }}
3030
package-server-ai-langchain-released: ${{ steps.release.outputs['packages/ai-providers/server-ai-langchain--release_created'] }}
31+
package-server-ai-openai-released: ${{ steps.release.outputs['packages/ai-providers/server-ai-openai--release_created'] }}
3132
package-browser-telemetry-released: ${{ steps.release.outputs['packages/telemetry/browser-telemetry--release_created'] }}
3233
package-combined-browser-released: ${{ steps.release.outputs['packages/sdk/combined-browser--release_created'] }}
3334
steps:
@@ -481,3 +482,23 @@ jobs:
481482
with:
482483
workspace_path: packages/ai-providers/server-ai-langchain
483484
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
485+
486+
release-server-ai-openai:
487+
runs-on: ubuntu-latest
488+
needs: ['release-please', 'release-server-ai']
489+
permissions:
490+
id-token: write
491+
contents: write
492+
if: ${{ always() && !failure() && !cancelled() && needs.release-please.outputs.package-server-ai-openai-released == 'true'}}
493+
steps:
494+
- uses: actions/checkout@v4
495+
- uses: actions/setup-node@v4
496+
with:
497+
node-version: 22.x
498+
registry-url: 'https://registry.npmjs.org'
499+
- id: release-server-ai-openai
500+
name: Full release of packages/ai-providers/server-ai-openai
501+
uses: ./actions/full-release
502+
with:
503+
workspace_path: packages/ai-providers/server-ai-openai
504+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ai-providers/server-ai-openai
2+
3+
on:
4+
push:
5+
branches: [main, 'feat/**']
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main, 'feat/**']
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-openai-provider:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
19+
with:
20+
node-version: 22.x
21+
registry-url: 'https://registry.npmjs.org'
22+
- id: shared
23+
name: Shared CI Steps
24+
uses: ./actions/ci
25+
with:
26+
workspace_name: '@launchdarkly/server-sdk-ai-openai'
27+
workspace_path: packages/ai-providers/server-ai-openai

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"packages/ai-providers/server-ai-langchain": "0.1.0",
3+
"packages/ai-providers/server-ai-openai": "0.0.0",
34
"packages/ai-providers/server-ai-vercel": "0.0.0",
45
"packages/sdk/akamai-base": "3.0.10",
56
"packages/sdk/akamai-edgekv": "1.4.12",

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs.
3838
| AI Providers | npm | issues | tests |
3939
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------- |
4040
| [@launchdarkly/server-sdk-ai-langchain](packages/ai-providers/server-ai-langchain/README.md) | [![NPM][server-ai-langchain-npm-badge]][server-ai-langchain-npm-link] | [server-ai-langchain][package-ai-providers-server-ai-langchain-issues] | [![Actions Status][server-ai-langchain-ci-badge]][server-ai-langchain-ci] |
41+
| [@launchdarkly/server-sdk-ai-openai](packages/ai-providers/server-ai-openai/README.md) | [![NPM][server-ai-openai-npm-badge]][server-ai-openai-npm-link] | [server-ai-openai][package-ai-providers-server-ai-openai-issues] | [![Actions Status][server-ai-openai-ci-badge]][server-ai-openai-ci] |
4142
| [@launchdarkly/server-sdk-ai-vercel](packages/ai-providers/server-ai-vercel/README.md) | [![NPM][server-ai-vercel-npm-badge]][server-ai-vercel-npm-link] | [server-ai-vercel][package-ai-providers-server-ai-vercel-issues] | [![Actions Status][server-ai-vercel-ci-badge]][server-ai-vercel-ci] |
4243

4344
## Organization
@@ -231,6 +232,12 @@ We encourage pull requests and other contributions from the community. Check out
231232
[server-ai-langchain-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/server-sdk-ai-langchain.svg?style=flat-square
232233
[server-ai-langchain-npm-link]: https://www.npmjs.com/package/@launchdarkly/server-sdk-ai-langchain
233234
[package-ai-providers-server-ai-langchain-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+ai-providers%2Fserver-ai-langchain%22+
235+
[//]: # 'ai-providers/server-ai-openai'
236+
[server-ai-openai-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml/badge.svg
237+
[server-ai-openai-ci]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml
238+
[server-ai-openai-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
239+
[server-ai-openai-npm-link]: https://www.npmjs.com/package/@launchdarkly/server-sdk-ai-openai
240+
[package-ai-providers-server-ai-openai-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+ai-providers%2Fserver-ai-openai%22+
234241
[//]: # 'ai-providers/server-ai-vercel'
235242
[server-ai-vercel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-vercel.yml/badge.svg
236243
[server-ai-vercel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-vercel.yml

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@launchdarkly/js-core",
33
"workspaces": [
44
"packages/ai-providers/server-ai-langchain",
5+
"packages/ai-providers/server-ai-openai",
56
"packages/ai-providers/server-ai-vercel",
67
"packages/shared/common",
78
"packages/shared/sdk-client",
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# LaunchDarkly AI SDK OpenAI Provider for Server-Side JavaScript
2+
3+
[![NPM][server-ai-openai-npm-badge]][server-ai-openai-npm-link]
4+
[![Actions Status][server-ai-openai-ci-badge]][server-ai-openai-ci]
5+
[![Documentation][server-ai-openai-ghp-badge]][server-ai-openai-ghp-link]
6+
[![NPM][server-ai-openai-dm-badge]][server-ai-openai-npm-link]
7+
[![NPM][server-ai-openai-dt-badge]][server-ai-openai-npm-link]
8+
9+
# ⛔️⛔️⛔️⛔️
10+
11+
> [!CAUTION]
12+
> This library is a alpha version and should not be considered ready for production use while this message is visible.
13+
14+
> [!NOTE]
15+
> This provider currently uses OpenAI's completion API. We plan to migrate to the responses API in a future release to take advantage of improved functionality and performance.
16+
17+
# ☝️☝️☝️☝️☝️☝️
18+
19+
## LaunchDarkly overview
20+
21+
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
22+
23+
[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
24+
25+
## Quick Setup
26+
27+
This package provides OpenAI integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `initChat` method:
28+
29+
1. Install the required packages:
30+
31+
```shell
32+
npm install @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-openai --save
33+
```
34+
35+
2. Create a chat session and use it:
36+
37+
```typescript
38+
import { init } from '@launchdarkly/node-server-sdk';
39+
import { initAi } from '@launchdarkly/server-sdk-ai';
40+
41+
// Initialize LaunchDarkly client
42+
const ldClient = init(sdkKey);
43+
const aiClient = initAi(ldClient);
44+
45+
// Create a chat session
46+
const defaultConfig = {
47+
enabled: true,
48+
model: { name: 'gpt-4' },
49+
provider: { name: 'openai' }
50+
};
51+
const chat = await aiClient.initChat('my-chat-config', context, defaultConfig);
52+
53+
if (chat) {
54+
const response = await chat.invoke("What is the capital of France?");
55+
console.log(response.message.content);
56+
}
57+
```
58+
59+
For more information about using the LaunchDarkly AI SDK, see the [LaunchDarkly AI SDK documentation](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/server-ai/README.md).
60+
61+
## Advanced Usage
62+
63+
For more control, you can use the OpenAI provider package directly with LaunchDarkly configurations:
64+
65+
```typescript
66+
import { OpenAIProvider } from '@launchdarkly/server-sdk-ai-openai';
67+
import { OpenAI } from 'openai';
68+
69+
// Create an OpenAI client
70+
const client = new OpenAI({
71+
apiKey: process.env.OPENAI_API_KEY,
72+
});
73+
74+
// Combine LaunchDarkly AI Config messages with user message
75+
const configMessages = aiConfig.messages || [];
76+
const userMessage = { role: 'user', content: 'What is the capital of France?' };
77+
const allMessages = [...configMessages, userMessage];
78+
79+
// Track the model call with LaunchDarkly tracking
80+
const response = await aiConfig.tracker.trackMetricsOf(
81+
(result) => OpenAIProvider.createAIMetrics(result),
82+
() => client.chat.completions.create({
83+
model: 'gpt-4',
84+
messages: allMessages,
85+
temperature: 0.7,
86+
})
87+
);
88+
89+
console.log('AI Response:', response.choices[0].message.content);
90+
```
91+
92+
## Contributing
93+
94+
We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.
95+
96+
## About LaunchDarkly
97+
98+
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
99+
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
100+
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
101+
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
102+
- Grant access to certain features based on user attributes, like payment plan (eg: users on the 'gold' plan get access to more features than users in the 'silver' plan).
103+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
104+
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
105+
- Explore LaunchDarkly
106+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
107+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
108+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
109+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
110+
111+
[server-ai-openai-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml/badge.svg
112+
[server-ai-openai-ci]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml
113+
[server-ai-openai-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
114+
[server-ai-openai-npm-link]: https://www.npmjs.com/package/@launchdarkly/server-sdk-ai-openai
115+
[server-ai-openai-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
116+
[server-ai-openai-ghp-link]: https://launchdarkly.github.io/js-core/packages/ai-providers/server-ai-openai/docs/
117+
[server-ai-openai-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
118+
[server-ai-openai-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square

0 commit comments

Comments
 (0)