Skip to content

Commit 422f885

Browse files
committed
add CI, docs, and missing build files
1 parent 562b3c6 commit 422f885

File tree

7 files changed

+162
-11
lines changed

7 files changed

+162
-11
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/telemetry/browser-telemetry
3940
- packages/sdk/combined-browser
4041
prerelease:
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
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
# ☝️☝️☝️☝️☝️☝️
15+
16+
## LaunchDarkly overview
17+
18+
[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!
19+
20+
[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
21+
22+
## Quick Setup
23+
24+
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:
25+
26+
1. Install the required packages:
27+
28+
```shell
29+
npm install @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-openai --save
30+
```
31+
32+
2. Create a chat session and use it:
33+
34+
```typescript
35+
import { init } from '@launchdarkly/node-server-sdk';
36+
import { initAi } from '@launchdarkly/server-sdk-ai';
37+
38+
// Initialize LaunchDarkly client
39+
const ldClient = init(sdkKey);
40+
const aiClient = initAi(ldClient);
41+
42+
// Create a chat session
43+
const defaultConfig = {
44+
enabled: true,
45+
model: { name: 'gpt-4' },
46+
provider: { name: 'openai' }
47+
};
48+
const chat = await aiClient.initChat('my-chat-config', context, defaultConfig);
49+
50+
if (chat) {
51+
const response = await chat.invoke("What is the capital of France?");
52+
console.log(response.message.content);
53+
}
54+
```
55+
56+
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).
57+
58+
## Advanced Usage
59+
60+
For more control, you can use the OpenAI provider package directly with LaunchDarkly configurations:
61+
62+
```typescript
63+
import { OpenAIProvider } from '@launchdarkly/server-sdk-ai-openai';
64+
import { OpenAI } from 'openai';
65+
66+
// Create an OpenAI client
67+
const client = new OpenAI({
68+
apiKey: process.env.OPENAI_API_KEY,
69+
});
70+
71+
// Combine LaunchDarkly AI Config messages with user message
72+
const configMessages = aiConfig.messages || [];
73+
const userMessage = { role: 'user', content: 'What is the capital of France?' };
74+
const allMessages = [...configMessages, userMessage];
75+
76+
// Track the model call with LaunchDarkly tracking
77+
const response = await aiConfig.tracker.trackMetricsOf(
78+
(result) => OpenAIProvider.createAIMetrics(result),
79+
() => client.chat.completions.create({
80+
model: 'gpt-4',
81+
messages: allMessages,
82+
temperature: 0.7,
83+
})
84+
);
85+
86+
console.log('AI Response:', response.choices[0].message.content);
87+
```
88+
89+
## Contributing
90+
91+
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.
92+
93+
## About LaunchDarkly
94+
95+
- 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:
96+
- 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.
97+
- 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?).
98+
- 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.
99+
- 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).
100+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
101+
- 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.
102+
- Explore LaunchDarkly
103+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
104+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
105+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
106+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
107+
108+
[server-ai-openai-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml/badge.svg
109+
[server-ai-openai-ci]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-openai.yml
110+
[server-ai-openai-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
111+
[server-ai-openai-npm-link]: https://www.npmjs.com/package/@launchdarkly/server-sdk-ai-openai
112+
[server-ai-openai-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
113+
[server-ai-openai-ghp-link]: https://launchdarkly.github.io/js-core/packages/ai-providers/server-ai-openai/docs/
114+
[server-ai-openai-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
115+
[server-ai-openai-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/server-sdk-ai-openai.svg?style=flat-square
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
module.exports = {
2-
preset: 'ts-jest',
2+
transform: { '^.+\\.ts?$': 'ts-jest' },
3+
testMatch: ['**/__tests__/**/*test.ts?(x)'],
34
testEnvironment: 'node',
4-
roots: ['<rootDir>'],
5-
testMatch: ['**/__tests__/**/*.test.ts'],
6-
collectCoverageFrom: [
7-
'src/**/*.ts',
8-
'!src/**/*.d.ts',
9-
'!src/**/*.test.ts',
10-
'!src/**/*.spec.ts',
11-
],
12-
coverageDirectory: 'coverage',
13-
coverageReporters: ['text', 'lcov', 'html'],
5+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
6+
collectCoverageFrom: ['src/**/*.ts'],
147
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*"],
4+
"compilerOptions": {
5+
"composite": true
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": ["../../../typedoc.base.json"],
3+
"entryPoints": ["src/index.ts"],
4+
"out": "docs"
5+
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
},
8282
{
8383
"path": "./packages/ai-providers/server-ai-langchain/tsconfig.ref.json"
84+
},
85+
{
86+
"path": "./packages/ai-providers/server-ai-openai/tsconfig.ref.json"
8487
}
8588
]
8689
}

0 commit comments

Comments
 (0)