You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> 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!
This package provides LangChain integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `initChat` method:
const response =awaitchat.invoke('What is the capital of France?');
54
+
console.log(response.message.content);
55
+
}
56
+
```
57
+
58
+
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).
59
+
60
+
## Advanced Usage
61
+
62
+
For more control, you can use the LangChain provider package directly with LaunchDarkly configurations:
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.
89
+
90
+
## About LaunchDarkly
91
+
92
+
- 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:
93
+
- 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.
94
+
- 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?).
95
+
- 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.
96
+
- 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).
97
+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
98
+
- 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.
99
+
- Explore LaunchDarkly
100
+
-[launchdarkly.com](https://www.launchdarkly.com/'LaunchDarkly Main Website') for more information
101
+
-[docs.launchdarkly.com](https://docs.launchdarkly.com/'LaunchDarkly Documentation') for our documentation and SDK reference guides
102
+
-[apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/'LaunchDarkly API Documentation') for our API documentation
103
+
-[blog.launchdarkly.com](https://blog.launchdarkly.com/'LaunchDarkly Blog Documentation') for the latest product updates
When retrieving AI configurations, you need to provide default values that will be used if the configuration is not available from LaunchDarkly:
44
+
45
+
### Fully Configured Default
46
+
47
+
```typescript
48
+
const defaultConfig = {
49
+
enabled: true,
50
+
model: {
51
+
name: 'gpt-4',
52
+
parameters: { temperature: 0.7, maxTokens: 1000 }
53
+
},
54
+
messages: [
55
+
{ role: 'system', content: 'You are a helpful assistant.' }
56
+
]
57
+
};
58
+
```
59
+
60
+
### Disabled Default
61
+
62
+
```typescript
63
+
const defaultConfig = {
64
+
enabled: false
65
+
};
66
+
```
67
+
68
+
## Retrieving AI Configurations
69
+
70
+
The `config` method retrieves AI configurations from LaunchDarkly with support for dynamic variables and fallback values:
71
+
72
+
```typescript
73
+
const aiConfig =awaitaiClient.config(
74
+
aiConfigKey,
75
+
context,
76
+
defaultConfig,
77
+
{ myVariable: 'My User Defined Variable' } // Variables for template interpolation
78
+
);
79
+
80
+
// Ensure configuration is enabled
81
+
if (aiConfig.enabled) {
82
+
const { messages, model, tracker } =aiConfig;
83
+
// Use with your AI provider
84
+
}
85
+
```
86
+
87
+
## TrackedChat for Conversational AI
88
+
89
+
`TrackedChat` provides a high-level interface for conversational AI with automatic conversation management and metrics tracking:
90
+
91
+
- Automatically configures models based on AI configuration
92
+
- Maintains conversation history across multiple interactions
93
+
- Automatically tracks token usage, latency, and success rates
94
+
- Works with any supported AI provider (see [AI Providers](https://github.com/launchdarkly/js-core#ai-providers) for available packages)
95
+
96
+
### Using TrackedChat
40
97
41
98
```typescript
42
-
const config =awaitaiClient.config(
43
-
aiConfigKey!,
99
+
// Use the same defaultConfig from the retrieval section above
100
+
const chat =awaitaiClient.initChat(
101
+
'customer-support-chat',
44
102
context,
45
-
{ enabled: false },
46
-
{ myVariable: 'My User Defined Variable' },
103
+
defaultConfig,
104
+
{ customerName: 'John' }
47
105
);
106
+
107
+
if (chat) {
108
+
// Simple conversation flow - metrics are automatically tracked by invoke()
109
+
const response1 =awaitchat.invoke('I need help with my order');
110
+
console.log(response1.message.content);
111
+
112
+
const response2 =awaitchat.invoke("What's the status?");
113
+
console.log(response2.message.content);
114
+
115
+
// Access conversation history
116
+
const messages =chat.getMessages();
117
+
console.log(`Conversation has ${messages.length} messages`);
118
+
}
48
119
```
49
120
50
-
For an example of how to use the config please refer to the examples folder.
121
+
## Advanced Usage with Providers
122
+
123
+
For more control, you can use the configuration directly with AI providers. We recommend using [LaunchDarkly AI Provider packages](https://github.com/launchdarkly/js-core#ai-providers) when available:
0 commit comments