|
| 1 | +# LaunchDarkly AI SDK Vercel Provider for Server-Side JavaScript |
| 2 | + |
| 3 | +[![NPM][server-ai-vercel-npm-badge]][server-ai-vercel-npm-link] |
| 4 | +[![Actions Status][server-ai-vercel-ci-badge]][server-ai-vercel-ci] |
| 5 | +[![Documentation][server-ai-vercel-ghp-badge]][server-ai-vercel-ghp-link] |
| 6 | +[![NPM][server-ai-vercel-dm-badge]][server-ai-vercel-npm-link] |
| 7 | +[![NPM][server-ai-vercel-dt-badge]][server-ai-vercel-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 | +[](https://twitter.com/intent/follow?screen_name=launchdarkly) |
| 21 | + |
| 22 | +## Quick Setup |
| 23 | + |
| 24 | +This package provides Vercel AI SDK 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-vercel --save |
| 30 | +# or |
| 31 | +yarn add @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-vercel |
| 32 | +``` |
| 33 | + |
| 34 | +2. Create a chat session and use it: |
| 35 | + |
| 36 | +```typescript |
| 37 | +import { init } from '@launchdarkly/node-server-sdk'; |
| 38 | +import { initAi } from '@launchdarkly/server-sdk-ai'; |
| 39 | + |
| 40 | +// Initialize LaunchDarkly client |
| 41 | +const ldClient = init(sdkKey); |
| 42 | +const aiClient = initAi(ldClient); |
| 43 | + |
| 44 | +// Create a chat session |
| 45 | +const defaultConfig = { |
| 46 | + enabled: true, |
| 47 | + model: { name: 'gpt-4' }, |
| 48 | + provider: { name: 'openai' } |
| 49 | +}; |
| 50 | +const chat = await aiClient.initChat('my-chat-config', context, defaultConfig); |
| 51 | + |
| 52 | +if (chat) { |
| 53 | + const response = await chat.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 Vercel AI provider package directly with LaunchDarkly configurations: |
| 63 | + |
| 64 | +```typescript |
| 65 | +import { VercelProvider } from '@launchdarkly/server-sdk-ai-vercel'; |
| 66 | +import { generateText } from 'ai'; |
| 67 | + |
| 68 | +// Create a Vercel AI model from LaunchDarkly configuration |
| 69 | +const model = await VercelProvider.createVercelModel(aiConfig); |
| 70 | + |
| 71 | +// Convert LaunchDarkly messages and add 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) => VercelProvider.createAIMetrics(result), |
| 79 | + () => generateText({ model, messages: allMessages }) |
| 80 | +); |
| 81 | + |
| 82 | +console.log('AI Response:', response.text); |
| 83 | +``` |
| 84 | + |
| 85 | +## Contributing |
| 86 | + |
| 87 | +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. |
| 88 | + |
| 89 | +## About LaunchDarkly |
| 90 | + |
| 91 | +- 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: |
| 92 | + - 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. |
| 93 | + - 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?). |
| 94 | + - 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. |
| 95 | + - 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). |
| 96 | + - Disable parts of your application to facilitate maintenance, without taking everything offline. |
| 97 | +- 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. |
| 98 | +- Explore LaunchDarkly |
| 99 | + - [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information |
| 100 | + - [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides |
| 101 | + - [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation |
| 102 | + - [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates |
| 103 | + |
| 104 | +[server-ai-vercel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-vercel.yml/badge.svg |
| 105 | +[server-ai-vercel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/server-ai-vercel.yml |
| 106 | +[server-ai-vercel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/server-sdk-ai-vercel.svg?style=flat-square |
| 107 | +[server-ai-vercel-npm-link]: https://www.npmjs.com/package/@launchdarkly/server-sdk-ai-vercel |
| 108 | +[server-ai-vercel-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 |
| 109 | +[server-ai-vercel-ghp-link]: https://launchdarkly.github.io/js-core/packages/ai-providers/server-ai-vercel/docs/ |
| 110 | +[server-ai-vercel-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/server-sdk-ai-vercel.svg?style=flat-square |
| 111 | +[server-ai-vercel-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/server-sdk-ai-vercel.svg?style=flat-square |
0 commit comments