Skip to content

Commit 3c5780c

Browse files
committed
Readme improvements. Example improvements.
1 parent e78a10d commit 3c5780c

File tree

3 files changed

+111
-56
lines changed

3 files changed

+111
-56
lines changed

packages/sdk/server-ai/README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,62 @@
22

33
This package provides the LaunchDarkly AI SDK for Node.js.
44

5-
## Installation
5+
## LaunchDarkly overview
6+
7+
[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!
8+
9+
[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
10+
11+
## Quick Setup
12+
13+
This assumes that you have already installed the LaunchDarkly Node.js SDK, or a compatible edge
14+
SDK.
15+
16+
1. Install this package with `npm` or `yarn`:
17+
18+
```shell
19+
npm install @launchdarkly/server-sdk-ai --save
20+
```
21+
22+
2. Create an AI SDK instance:
23+
24+
```typescript
25+
// The ldClient instance should be created based on the instructions in the relevant SDK.
26+
const aiClient = initAi(ldClient);
27+
```
28+
29+
3. Evaluate a model configuration:
30+
```
31+
const config = await aiClient.modelConfig(
32+
aiConfigKey!,
33+
context,
34+
{ enabled: false },
35+
{ myVariable: 'My User Defined Variable' },
36+
);
37+
```
38+
39+
For an example of how to use the config please refer to the examples folder.
40+
41+
## Contributing
42+
43+
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.
44+
45+
## About LaunchDarkly
46+
47+
- 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:
48+
- 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.
49+
- 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?).
50+
- 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.
51+
- 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).
52+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
53+
- 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.
54+
- Explore LaunchDarkly
55+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
56+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
57+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
58+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
59+
60+
[node-otel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml/badge.svg
61+
[node-otel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml
62+
[node-otel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-otel.svg?style=flat-square
63+
[node-otel-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-otel

packages/sdk/server-ai/examples/bedrock/src/index.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { BedrockRuntimeClient, ConverseCommand, Message } from '@aws-sdk/client-bedrock-runtime';
33

44
import { init } from '@launchdarkly/node-server-sdk';
5-
import { initAi, LDAIConfig } from '@launchdarkly/server-sdk-ai';
5+
import { initAi } from '@launchdarkly/server-sdk-ai';
66

77
const sdkKey = process.env.LAUNCHDARKLY_SDK_KEY;
88
const aiConfigKey = process.env.LAUNCHDARKLY_AI_CONFIG_KEY || 'sample-ai-config';
@@ -38,45 +38,41 @@ function mapPromptToConversation(
3838
}
3939

4040
async function main() {
41-
let tracker;
42-
let configValue: LDAIConfig;
43-
4441
try {
4542
await ldClient.waitForInitialization({ timeout: 10 });
4643
console.log('*** SDK successfully initialized');
47-
const aiClient = initAi(ldClient);
48-
49-
configValue = await aiClient.modelConfig(
50-
aiConfigKey!,
51-
context,
52-
{
53-
model: {
54-
modelId: 'my-default-model',
55-
},
56-
enabled: true,
57-
},
58-
{
59-
myVariable: 'My User Defined Variable',
60-
},
61-
);
62-
tracker = configValue.tracker;
6344
} catch (error) {
6445
console.log(`*** SDK failed to initialize: ${error}`);
6546
process.exit(1);
6647
}
6748

68-
if (tracker) {
69-
const completion = tracker.trackBedrockConverse(
70-
await awsClient.send(
71-
new ConverseCommand({
72-
modelId: configValue.config.model?.modelId ?? 'no-model',
73-
messages: mapPromptToConversation(configValue.config.prompt ?? []),
74-
}),
75-
),
76-
);
77-
console.log('AI Response:', completion.output?.message?.content?.[0]?.text ?? 'no-response');
78-
console.log('Success.');
79-
}
49+
const aiClient = initAi(ldClient);
50+
51+
const aiConfig = await aiClient.modelConfig(
52+
aiConfigKey!,
53+
context,
54+
{
55+
model: {
56+
modelId: 'my-default-model',
57+
},
58+
enabled: true,
59+
},
60+
{
61+
myVariable: 'My User Defined Variable',
62+
},
63+
);
64+
const { tracker } = aiConfig;
65+
66+
const completion = tracker.trackBedrockConverse(
67+
await awsClient.send(
68+
new ConverseCommand({
69+
modelId: aiConfig.config.model?.modelId ?? 'no-model',
70+
messages: mapPromptToConversation(aiConfig.config.prompt ?? []),
71+
}),
72+
),
73+
);
74+
console.log('AI Response:', completion.output?.message?.content?.[0]?.text ?? 'no-response');
75+
console.log('Success.');
8076
}
8177

8278
main();

packages/sdk/server-ai/examples/openai/src/index.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,34 @@ async function main(): Promise<void> {
3939
try {
4040
await ldClient.waitForInitialization({ timeout: 10 });
4141
console.log('*** SDK successfully initialized');
42-
const aiClient = initAi(ldClient);
43-
44-
const configValue = await aiClient.modelConfig(
45-
aiConfigKey,
46-
context,
47-
{
48-
model: {
49-
modelId: 'gpt-4',
50-
},
51-
},
52-
{ myVariable: 'My User Defined Variable' },
53-
);
54-
55-
const { tracker } = configValue;
56-
const completion = await tracker.trackOpenAI(async () =>
57-
client.chat.completions.create({
58-
messages: configValue.config.prompt || [],
59-
model: configValue.config.model?.modelId || 'gpt-4',
60-
}),
61-
);
62-
63-
console.log('AI Response:', completion.choices[0]?.message.content);
64-
console.log('Success.');
6542
} catch (error) {
6643
console.log(`*** SDK failed to initialize: ${error}`);
6744
process.exit(1);
6845
}
46+
47+
const aiClient = initAi(ldClient);
48+
49+
const aiConfig = await aiClient.modelConfig(
50+
aiConfigKey,
51+
context,
52+
{
53+
model: {
54+
modelId: 'gpt-4',
55+
},
56+
},
57+
{ myVariable: 'My User Defined Variable' },
58+
);
59+
60+
const { tracker } = aiConfig;
61+
const completion = await tracker.trackOpenAI(async () =>
62+
client.chat.completions.create({
63+
messages: aiConfig.config.prompt || [],
64+
model: aiConfig.config.model?.modelId || 'gpt-4',
65+
}),
66+
);
67+
68+
console.log('AI Response:', completion.choices[0]?.message.content);
69+
console.log('Success.');
6970
}
7071

7172
main();

0 commit comments

Comments
 (0)