Skip to content

Commit 95fa2bc

Browse files
committed
Build updates.
1 parent 59d0c27 commit 95fa2bc

File tree

10 files changed

+146
-112
lines changed

10 files changed

+146
-112
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"packages/sdk/browser",
2727
"packages/sdk/browser/contract-tests/entity",
2828
"packages/sdk/browser/contract-tests/adapter",
29-
"packages/sdk/ai"
29+
"packages/sdk/ai",
30+
"packages/sdk/ai/examples/bedrock",
31+
"packages/sdk/ai/examples/openai"
3032
],
3133
"private": true,
3234
"scripts": {

packages/sdk/ai/examples/bedrock/index.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/sdk/ai/examples/bedrock/package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "LaunchDarkly AI SDK for Node.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"type": "commonjs",
78
"scripts": {
89
"build": "tsc",
910
"test": "jest",
@@ -18,10 +19,26 @@
1819
"license": "Apache-2.0",
1920
"dependencies": {
2021
"@aws-sdk/client-bedrock-runtime": "^3.679.0",
21-
"@launchdarkly/ai": "0.1.0"
22+
"@launchdarkly/ai": "0.1.0",
23+
"@launchdarkly/node-server-sdk": "9.7.0"
2224
},
2325
"devDependencies": {
24-
"eslint": "^8.45.0"
26+
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
27+
"@tsconfig/node20": "20.1.4",
28+
"@typescript-eslint/eslint-plugin": "^6.20.0",
29+
"@typescript-eslint/parser": "^6.20.0",
30+
"eslint": "^8.45.0",
31+
"eslint-config-airbnb-base": "^15.0.0",
32+
"eslint-config-airbnb-typescript": "^17.1.0",
33+
"eslint-config-prettier": "^8.8.0",
34+
"eslint-plugin-import": "^2.27.5",
35+
"eslint-plugin-jest": "^27.6.3",
36+
"eslint-plugin-prettier": "^5.0.0",
37+
"jest": "^29.7.0",
38+
"prettier": "^3.0.0",
39+
"rimraf": "^5.0.5",
40+
"typedoc": "0.25.0",
41+
"typescript": "^5.5.3"
2542
},
2643
"directories": {
2744
"example": "example"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-disable no-console */
2+
import {
3+
BedrockRuntimeClient,
4+
ConversationRole,
5+
ConverseCommand,
6+
Message,
7+
} from '@aws-sdk/client-bedrock-runtime';
8+
9+
import { initAi, LDAIConfig } from '@launchdarkly/ai';
10+
import { init } from '@launchdarkly/node-server-sdk';
11+
12+
const sdkKey = process.env.LAUNCHDARKLY_SDK_KEY;
13+
const aiConfigKey = process.env.LAUNCHDARKLY_AI_CONFIG_KEY || 'sample-ai-config';
14+
const awsClient = new BedrockRuntimeClient({ region: 'us-east-1' });
15+
16+
if (!sdkKey) {
17+
console.error('*** Please set the LAUNCHDARKLY_SDK_KEY env first');
18+
process.exit(1);
19+
}
20+
21+
const ldClient = init(sdkKey);
22+
23+
// Set up the context properties
24+
const context = {
25+
kind: 'user',
26+
key: 'example-user-key',
27+
name: 'Sandy',
28+
};
29+
30+
console.log('*** SDK successfully initialized');
31+
32+
function mapPromptToConversation(prompt: { role: ConversationRole; content: string }[]): Message[] {
33+
return prompt.map((item) => ({
34+
role: item.role,
35+
content: [{ text: item.content }],
36+
}));
37+
}
38+
39+
async function main() {
40+
let tracker;
41+
let configValue: LDAIConfig | false;
42+
43+
try {
44+
await ldClient.waitForInitialization({ timeout: 10 });
45+
const aiClient = initAi(ldClient);
46+
47+
configValue = await aiClient.modelConfig(aiConfigKey, context, false, {
48+
myVariable: 'My User Defined Variable',
49+
});
50+
tracker = configValue.tracker;
51+
} catch (error) {
52+
console.log(`*** SDK failed to initialize: ${error}`);
53+
process.exit(1);
54+
}
55+
56+
const completion = await tracker.trackBedrockConverse(
57+
await awsClient.send(
58+
new ConverseCommand({
59+
modelId: configValue.config.config.modelId,
60+
messages: mapPromptToConversation(configValue.config.prompt),
61+
}),
62+
),
63+
);
64+
65+
console.log('AI Response:', completion.output.message.content[0].text);
66+
console.log('Success.');
67+
}
68+
69+
main();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["/**/*.ts", "/**/*.tsx"],
4+
"exclude": ["node_modules"]
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": "@tsconfig/node20/tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"outDir": "dist",
6+
"baseUrl": ".",
7+
"allowUnusedLabels": false,
8+
"allowUnreachableCode": false,
9+
"noFallthroughCasesInSwitch": true,
10+
"noUncheckedIndexedAccess": true,
11+
"noUnusedLocals": true,
12+
"noUnusedParameters": true,
13+
"forceConsistentCasingInFileNames": true,
14+
"declaration": true,
15+
"sourceMap": true,
16+
"resolveJsonModule": true,
17+
"module": "CommonJS",
18+
"moduleResolution": "Node"
19+
},
20+
"include": ["src", "test"],
21+
"exclude": ["dist", "node_modules"]
22+
}

packages/sdk/ai/examples/openai/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc",
9-
"test": "jest",
10-
"lint": "eslint . --ext .ts"
8+
"build": "tsc",
9+
"test": "jest",
10+
"lint": "eslint . --ext .ts"
1111
},
1212
"keywords": [
13-
"launchdarkly",
14-
"ai",
15-
"llm"
13+
"launchdarkly",
14+
"ai",
15+
"llm"
1616
],
1717
"author": "LaunchDarkly",
1818
"license": "Apache-2.0",
1919
"dependencies": {
20-
"@launchdarkly/ai": "0.1.0",
21-
"openai": "^4.58.1"
20+
"@launchdarkly/ai": "0.1.0",
21+
"openai": "^4.58.1"
2222
},
2323
"devDependencies": {
24-
"eslint": "^8.45.0"
24+
"eslint": "^8.45.0"
2525
},
2626
"directories": {
27-
"example": "example"
27+
"example": "example"
2828
},
2929
"repository": {
30-
"type": "git",
31-
"url": "github.com/launchdarkly/js-core"
30+
"type": "git",
31+
"url": "github.com/launchdarkly/js-core"
3232
}
33-
}
33+
}

packages/sdk/ai/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "LaunchDarkly AI SDK for Node.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"type": "commonjs",
78
"scripts": {
89
"build": "npx tsc",
910
"lint": "npx eslint . --ext .ts",

packages/sdk/ai/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class AIClientImpl implements AIClient {
109109
* @param ldClient The base LaunchDarkly client.
110110
* @returns A new AI client.
111111
*/
112-
export function init(ldClient: LDClient): AIClient {
112+
export function initAi(ldClient: LDClient): AIClient {
113113
return new AIClientImpl(ldClient);
114114
}
115115

packages/sdk/ai/tsconfig.json

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
11
{
22
"compilerOptions": {
3-
"allowSyntheticDefaultImports": true,
4-
"declaration": true,
5-
"declarationMap": true,
6-
"lib": ["ES2017", "dom"],
7-
"module": "ESNext",
8-
"moduleResolution": "node",
9-
"noImplicitOverride": true,
10-
"resolveJsonModule": true,
3+
// Uses "." so it can load package.json.
114
"rootDir": ".",
125
"outDir": "dist",
13-
"skipLibCheck": true,
14-
"sourceMap": false,
6+
"target": "es2017",
7+
"lib": ["es6"],
8+
"module": "commonjs",
159
"strict": true,
10+
"noImplicitOverride": true,
11+
// Needed for CommonJS modules: markdown-it, fs-extra
12+
"allowSyntheticDefaultImports": true,
13+
"sourceMap": true,
14+
"declaration": true,
15+
"declarationMap": true, // enables importers to jump to source
16+
"resolveJsonModule": true,
1617
"stripInternal": true,
17-
"target": "ES2017",
18-
"types": ["node", "jest"],
19-
"allowJs": true
18+
"moduleResolution": "node"
2019
},
2120
"include": ["src"],
22-
"exclude": [
23-
"vite.config.ts",
24-
"__tests__",
25-
"dist",
26-
"docs",
27-
"example",
28-
"node_modules",
29-
"babel.config.js",
30-
"setup-jest.js",
31-
"rollup.config.js",
32-
"**/*.test.ts*"
33-
]
21+
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
3422
}

0 commit comments

Comments
 (0)