@bedrockio/ai 0.2.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +11 -0
- package/CHANGELOG.md +34 -0
- package/README.md +59 -17
- package/__mocks__/@anthropic-ai/sdk.js +16 -22
- package/__mocks__/@google/generative-ai.js +1 -1
- package/__mocks__/openai.js +33 -28
- package/dist/cjs/BaseClient.js +242 -126
- package/dist/cjs/anthropic.js +115 -93
- package/dist/cjs/google.js +74 -86
- package/dist/cjs/index.js +24 -25
- package/dist/cjs/openai.js +114 -69
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/utils/code.js +11 -0
- package/dist/cjs/utils/json.js +53 -0
- package/dist/cjs/utils/templates.js +83 -0
- package/dist/cjs/xai.js +14 -0
- package/dist/esm/BaseClient.js +243 -0
- package/dist/esm/anthropic.js +116 -0
- package/dist/esm/google.js +75 -0
- package/dist/esm/index.js +25 -0
- package/dist/esm/openai.js +113 -0
- package/dist/esm/utils/code.js +8 -0
- package/dist/esm/utils/json.js +50 -0
- package/dist/esm/utils/templates.js +76 -0
- package/dist/esm/xai.js +10 -0
- package/eslint.config.js +2 -0
- package/package.json +18 -17
- package/src/BaseClient.js +239 -89
- package/src/anthropic.js +96 -56
- package/src/google.js +6 -12
- package/src/index.js +20 -16
- package/src/openai.js +97 -31
- package/src/utils/code.js +9 -0
- package/src/utils/json.js +58 -0
- package/src/utils/templates.js +87 -0
- package/src/xai.js +12 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
- package/tsconfig.types.json +9 -0
- package/types/BaseClient.d.ts +68 -26
- package/types/BaseClient.d.ts.map +1 -1
- package/types/anthropic.d.ts +26 -2
- package/types/anthropic.d.ts.map +1 -1
- package/types/google.d.ts.map +1 -1
- package/types/index.d.ts +4 -3
- package/types/index.d.ts.map +1 -1
- package/types/openai.d.ts +45 -2
- package/types/openai.d.ts.map +1 -1
- package/types/util.d.ts +1 -1
- package/types/util.d.ts.map +1 -1
- package/types/utils/code.d.ts +2 -0
- package/types/utils/code.d.ts.map +1 -0
- package/types/utils/json.d.ts +2 -0
- package/types/utils/json.d.ts.map +1 -0
- package/types/utils/templates.d.ts +3 -0
- package/types/utils/templates.d.ts.map +1 -0
- package/types/utils.d.ts +4 -0
- package/types/utils.d.ts.map +1 -0
- package/types/xai.d.ts +4 -0
- package/types/xai.d.ts.map +1 -0
- package/vitest.config.js +10 -0
- package/dist/cjs/util.js +0 -47
- package/src/util.js +0 -42
package/types/openai.d.ts
CHANGED
|
@@ -1,14 +1,57 @@
|
|
|
1
1
|
export class OpenAiClient extends BaseClient {
|
|
2
|
+
static DEFAULT_MODEL: string;
|
|
2
3
|
client: OpenAI;
|
|
3
4
|
/**
|
|
4
5
|
* Lists available models.
|
|
5
6
|
* {@link https://platform.openai.com/docs/models Documentation}
|
|
6
7
|
*/
|
|
7
8
|
models(): Promise<string[]>;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
runPrompt(options: any): Promise<OpenAI.Responses.Response & {
|
|
10
|
+
_request_id?: string | null;
|
|
11
|
+
} & import("openai/core/streaming.js").Stream<OpenAI.Responses.ResponseStreamEvent>>;
|
|
12
|
+
runStream(options: any): Promise<OpenAI.Responses.Response & {
|
|
13
|
+
_request_id?: string | null;
|
|
14
|
+
} & import("openai/core/streaming.js").Stream<OpenAI.Responses.ResponseStreamEvent>>;
|
|
15
|
+
getTextResponse(response: any): any;
|
|
16
|
+
getMessagesResponse(input: any, response: any): {
|
|
17
|
+
messages: any[];
|
|
18
|
+
prevResponseId: any;
|
|
19
|
+
};
|
|
20
|
+
getOutputFormat(options: any): {
|
|
21
|
+
type: string;
|
|
22
|
+
name?: undefined;
|
|
23
|
+
strict?: undefined;
|
|
24
|
+
schema?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
type: string;
|
|
27
|
+
name: string;
|
|
28
|
+
strict: boolean;
|
|
29
|
+
schema: any;
|
|
30
|
+
};
|
|
31
|
+
normalizeStreamEvent(event: any): {
|
|
32
|
+
type: string;
|
|
33
|
+
id: any;
|
|
34
|
+
usage?: undefined;
|
|
35
|
+
delta?: undefined;
|
|
36
|
+
text?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
type: string;
|
|
39
|
+
id: any;
|
|
40
|
+
usage: any;
|
|
41
|
+
delta?: undefined;
|
|
42
|
+
text?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
type: string;
|
|
45
|
+
delta: any;
|
|
46
|
+
id?: undefined;
|
|
47
|
+
usage?: undefined;
|
|
48
|
+
text?: undefined;
|
|
49
|
+
} | {
|
|
10
50
|
type: string;
|
|
11
51
|
text: any;
|
|
52
|
+
id?: undefined;
|
|
53
|
+
usage?: undefined;
|
|
54
|
+
delta?: undefined;
|
|
12
55
|
};
|
|
13
56
|
}
|
|
14
57
|
import BaseClient from './BaseClient.js';
|
package/types/openai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.js"],"names":[],"mappings":"AAIA;IACE,6BAAoC;IAIlC,eAAiC;IAGnC;;;OAGG;IACH,4BAGC;IAED;;yFA+BC;IAED;;yFAKC;IAED,oCAEC;IAMD;;;MAaC;IAID;;;;;;;;;;MAmBC;IAED;;;;;;;;;;;;;;;;;;;;;;;;MAyBC;CACF;uBAnIsB,iBAAiB;mBAFrB,QAAQ"}
|
package/types/util.d.ts
CHANGED
package/types/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.js"],"names":[],"mappings":"AASA,qDAcC;AAED,yDAEC;AAED,qDAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/utils/code.js"],"names":[],"mappings":"AAEA,6CAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.js"],"names":[],"mappings":"AAEA,oDAKU,UAAK,SAUd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/utils/templates.js"],"names":[],"mappings":"AAMA,qDAcC;AAED,iEASC"}
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAQA,qDAcC;AAED,6CAMC;AAED,iEASC"}
|
package/types/xai.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../src/xai.js"],"names":[],"mappings":"AAEA;CASC;6BAX4B,aAAa"}
|
package/vitest.config.js
ADDED
package/dist/cjs/util.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadTemplates = loadTemplates;
|
|
7
|
-
exports.parse = parse;
|
|
8
|
-
exports.transformResponse = transformResponse;
|
|
9
|
-
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
var _glob = require("glob");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
const JSON_REG = /([{[].+[}\]])/s;
|
|
14
|
-
async function loadTemplates(dir) {
|
|
15
|
-
const result = {};
|
|
16
|
-
const files = await (0, _glob.glob)(_path.default.join(dir, '*.md'));
|
|
17
|
-
for (let file of files) {
|
|
18
|
-
const base = _path.default.basename(file, '.md');
|
|
19
|
-
result[base] = await _promises.default.readFile(file, 'utf-8');
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
function parse(content) {
|
|
24
|
-
try {
|
|
25
|
-
const match = content.match(JSON_REG);
|
|
26
|
-
return JSON.parse(match[1]);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error('Unable to derive JSON object in response.');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function transformResponse(options) {
|
|
32
|
-
const {
|
|
33
|
-
output = 'text',
|
|
34
|
-
messages,
|
|
35
|
-
message
|
|
36
|
-
} = options;
|
|
37
|
-
const content = message.content || message.text;
|
|
38
|
-
if (output === 'text') {
|
|
39
|
-
return content;
|
|
40
|
-
} else if (output === 'messages') {
|
|
41
|
-
return [...messages, message];
|
|
42
|
-
} else if (output === 'json') {
|
|
43
|
-
return parse(content);
|
|
44
|
-
} else {
|
|
45
|
-
throw new Error(`Unknown output type "${output}".`);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/util.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import { glob } from 'glob';
|
|
6
|
-
|
|
7
|
-
const JSON_REG = /([{[].+[}\]])/s;
|
|
8
|
-
|
|
9
|
-
export async function loadTemplates(dir) {
|
|
10
|
-
const result = {};
|
|
11
|
-
const files = await glob(path.join(dir, '*.md'));
|
|
12
|
-
|
|
13
|
-
for (let file of files) {
|
|
14
|
-
const base = path.basename(file, '.md');
|
|
15
|
-
result[base] = await fs.readFile(file, 'utf-8');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function parse(content) {
|
|
22
|
-
try {
|
|
23
|
-
const match = content.match(JSON_REG);
|
|
24
|
-
return JSON.parse(match[1]);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error('Unable to derive JSON object in response.');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function transformResponse(options) {
|
|
31
|
-
const { output = 'text', messages, message } = options;
|
|
32
|
-
const content = message.content || message.text;
|
|
33
|
-
if (output === 'text') {
|
|
34
|
-
return content;
|
|
35
|
-
} else if (output === 'messages') {
|
|
36
|
-
return [...messages, message];
|
|
37
|
-
} else if (output === 'json') {
|
|
38
|
-
return parse(content);
|
|
39
|
-
} else {
|
|
40
|
-
throw new Error(`Unknown output type "${output}".`);
|
|
41
|
-
}
|
|
42
|
-
}
|