@far-world-labs/verblets 0.2.0 → 0.3.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/README.md +86 -213
- package/dist/index.browser.js +74 -0
- package/dist/index.js +548 -0
- package/dist/shared-C6kPWghF.js +7806 -0
- package/package.json +32 -11
- package/.cursor/launch.json +0 -30
- package/.cursor/settings.json +0 -20
- package/.github/workflows/branch-protection.yml +0 -22
- package/.github/workflows/ci.yml +0 -165
- package/.husky/pre-commit +0 -4
- package/.prettierrc +0 -6
- package/.release-it.json +0 -12
- package/.vitest.config.examples.js +0 -12
- package/.vitest.config.js +0 -8
- package/.vscode/launch.json +0 -31
- package/AGENTS.md +0 -220
- package/DEVELOPING.md +0 -105
- package/docker-compose.yml +0 -7
- package/eslint.config.js +0 -80
- package/scripts/clear-redis.js +0 -74
- package/scripts/generate-chain/index.js +0 -111
- package/scripts/generate-lib/index.js +0 -68
- package/scripts/generate-test/index.js +0 -137
- package/scripts/generate-verblet/README.md +0 -17
- package/scripts/generate-verblet/index.js +0 -110
- package/scripts/run.sh +0 -15
- package/scripts/runner/index.js +0 -56
- package/scripts/simple-editor/README.md +0 -34
- package/scripts/simple-editor/index.js +0 -79
- package/scripts/summarize-files/index.js +0 -70
- package/src/chains/README.md +0 -30
- package/src/chains/anonymize/README.md +0 -21
- package/src/chains/anonymize/index.examples.js +0 -75
- package/src/chains/anonymize/index.js +0 -121
- package/src/chains/anonymize/index.spec.js +0 -78
- package/src/chains/bulk-central-tendency/index.examples.js +0 -138
- package/src/chains/bulk-central-tendency/index.js +0 -91
- package/src/chains/bulk-filter/README.md +0 -21
- package/src/chains/bulk-filter/index.examples.js +0 -22
- package/src/chains/bulk-filter/index.js +0 -58
- package/src/chains/bulk-filter/index.spec.js +0 -38
- package/src/chains/bulk-find/README.md +0 -16
- package/src/chains/bulk-find/index.examples.js +0 -20
- package/src/chains/bulk-find/index.js +0 -30
- package/src/chains/bulk-find/index.spec.js +0 -26
- package/src/chains/bulk-group/README.md +0 -23
- package/src/chains/bulk-group/index.examples.js +0 -18
- package/src/chains/bulk-group/index.js +0 -34
- package/src/chains/bulk-group/index.spec.js +0 -41
- package/src/chains/bulk-map/README.md +0 -43
- package/src/chains/bulk-map/index.examples.js +0 -17
- package/src/chains/bulk-map/index.js +0 -86
- package/src/chains/bulk-map/index.spec.js +0 -44
- package/src/chains/bulk-reduce/README.md +0 -12
- package/src/chains/bulk-reduce/index.examples.js +0 -15
- package/src/chains/bulk-reduce/index.js +0 -13
- package/src/chains/bulk-reduce/index.spec.js +0 -25
- package/src/chains/bulk-score/README.md +0 -16
- package/src/chains/bulk-score/bulk-score-result.json +0 -18
- package/src/chains/bulk-score/index.examples.js +0 -22
- package/src/chains/bulk-score/index.js +0 -133
- package/src/chains/bulk-score/index.spec.js +0 -30
- package/src/chains/category-samples/README.md +0 -61
- package/src/chains/category-samples/index.examples.js +0 -103
- package/src/chains/category-samples/index.js +0 -134
- package/src/chains/collect-terms/README.md +0 -12
- package/src/chains/collect-terms/index.examples.js +0 -16
- package/src/chains/collect-terms/index.js +0 -44
- package/src/chains/collect-terms/index.spec.js +0 -25
- package/src/chains/conversation/README.md +0 -26
- package/src/chains/conversation/index.examples.js +0 -398
- package/src/chains/conversation/index.js +0 -126
- package/src/chains/conversation/index.spec.js +0 -148
- package/src/chains/conversation/turn-policies.js +0 -93
- package/src/chains/conversation/turn-policies.md +0 -123
- package/src/chains/conversation/turn-policies.spec.js +0 -135
- package/src/chains/date/README.md +0 -12
- package/src/chains/date/index.examples.js +0 -47
- package/src/chains/date/index.js +0 -74
- package/src/chains/date/index.spec.js +0 -62
- package/src/chains/disambiguate/README.md +0 -22
- package/src/chains/disambiguate/disambiguate-meanings-result.json +0 -16
- package/src/chains/disambiguate/index.examples.js +0 -18
- package/src/chains/disambiguate/index.js +0 -92
- package/src/chains/disambiguate/index.spec.js +0 -25
- package/src/chains/dismantle/README.md +0 -67
- package/src/chains/dismantle/dismantle.examples.js +0 -27
- package/src/chains/dismantle/index.examples.js +0 -30
- package/src/chains/dismantle/index.js +0 -303
- package/src/chains/dismantle/index.spec.js +0 -32
- package/src/chains/expect/README.md +0 -171
- package/src/chains/expect/index.examples.js +0 -146
- package/src/chains/expect/index.js +0 -207
- package/src/chains/expect/index.spec.js +0 -324
- package/src/chains/filter-ambiguous/README.md +0 -11
- package/src/chains/filter-ambiguous/index.examples.js +0 -20
- package/src/chains/filter-ambiguous/index.js +0 -49
- package/src/chains/filter-ambiguous/index.spec.js +0 -31
- package/src/chains/glossary/README.md +0 -19
- package/src/chains/glossary/index.examples.js +0 -386
- package/src/chains/glossary/index.js +0 -75
- package/src/chains/glossary/index.spec.js +0 -19
- package/src/chains/intersections/README.md +0 -166
- package/src/chains/intersections/index.examples.js +0 -280
- package/src/chains/intersections/index.js +0 -218
- package/src/chains/intersections/intersection-result.json +0 -38
- package/src/chains/list/index.examples.js +0 -68
- package/src/chains/list/index.js +0 -214
- package/src/chains/list/index.spec.js +0 -67
- package/src/chains/list/list-result.json +0 -16
- package/src/chains/list/schema.json +0 -24
- package/src/chains/llm-logger/README.md +0 -366
- package/src/chains/llm-logger/index.js +0 -591
- package/src/chains/llm-logger/index.spec.js +0 -391
- package/src/chains/llm-logger/schema.json +0 -105
- package/src/chains/questions/index.examples.js +0 -69
- package/src/chains/questions/index.js +0 -135
- package/src/chains/questions/index.spec.js +0 -29
- package/src/chains/scan-js/index.js +0 -116
- package/src/chains/set-interval/README.md +0 -81
- package/src/chains/set-interval/index.examples.js +0 -64
- package/src/chains/set-interval/index.js +0 -152
- package/src/chains/set-interval/index.spec.js +0 -70
- package/src/chains/socratic/README.md +0 -17
- package/src/chains/socratic/index.js +0 -64
- package/src/chains/socratic/index.spec.js +0 -24
- package/src/chains/sort/index.examples.js +0 -36
- package/src/chains/sort/index.js +0 -163
- package/src/chains/sort/index.spec.js +0 -112
- package/src/chains/sort/sort-result.json +0 -16
- package/src/chains/summary-map/README.md +0 -41
- package/src/chains/summary-map/index.examples.js +0 -64
- package/src/chains/summary-map/index.js +0 -226
- package/src/chains/summary-map/index.spec.js +0 -153
- package/src/chains/test/index.js +0 -114
- package/src/chains/test-advice/index.js +0 -35
- package/src/chains/themes/README.md +0 -20
- package/src/chains/themes/index.examples.js +0 -17
- package/src/chains/themes/index.js +0 -28
- package/src/chains/themes/index.spec.js +0 -19
- package/src/chains/veiled-variants/index.examples.js +0 -18
- package/src/chains/veiled-variants/index.js +0 -107
- package/src/chains/veiled-variants/index.spec.js +0 -40
- package/src/constants/common.js +0 -13
- package/src/constants/messages.js +0 -3
- package/src/constants/models.js +0 -184
- package/src/index.js +0 -203
- package/src/json-schemas/README.md +0 -13
- package/src/json-schemas/cars-test.json +0 -11
- package/src/json-schemas/index.js +0 -12
- package/src/json-schemas/intent.json +0 -38
- package/src/json-schemas/schema-dot-org-photograph.json +0 -133
- package/src/json-schemas/schema-dot-org-place.json +0 -129
- package/src/lib/README.md +0 -26
- package/src/lib/any-signal/index.js +0 -28
- package/src/lib/assert/README.md +0 -84
- package/src/lib/assert/index.js +0 -50
- package/src/lib/bulk-filter/README.md +0 -22
- package/src/lib/bulk-filter/index.examples.js +0 -27
- package/src/lib/bulk-filter/index.js +0 -63
- package/src/lib/bulk-filter/index.spec.js +0 -38
- package/src/lib/bulk-find/README.md +0 -18
- package/src/lib/bulk-find/index.examples.js +0 -19
- package/src/lib/bulk-find/index.js +0 -30
- package/src/lib/bulk-find/index.spec.js +0 -41
- package/src/lib/chatgpt/index.js +0 -163
- package/src/lib/combinations/index.js +0 -30
- package/src/lib/combinations/index.spec.js +0 -23
- package/src/lib/editor/index.js +0 -31
- package/src/lib/functional/index.js +0 -28
- package/src/lib/logger-service/index.js +0 -32
- package/src/lib/parse-js-parts/index.js +0 -321
- package/src/lib/parse-js-parts/index.spec.js +0 -156
- package/src/lib/parse-llm-list/README.md +0 -39
- package/src/lib/parse-llm-list/index.js +0 -54
- package/src/lib/parse-llm-list/index.spec.js +0 -59
- package/src/lib/path-aliases/index.js +0 -37
- package/src/lib/path-aliases/index.spec.js +0 -64
- package/src/lib/pave/index.js +0 -34
- package/src/lib/pave/index.spec.js +0 -76
- package/src/lib/prompt-cache/index.js +0 -50
- package/src/lib/retry/index.js +0 -66
- package/src/lib/retry/index.spec.js +0 -86
- package/src/lib/ring-buffer/README.md +0 -82
- package/src/lib/ring-buffer/index.js +0 -235
- package/src/lib/ring-buffer/index.spec.js +0 -388
- package/src/lib/search-best-first/city-walk.spec.js +0 -37
- package/src/lib/search-best-first/index.js +0 -97
- package/src/lib/search-best-first/index.spec.js +0 -35
- package/src/lib/search-js-files/code-features-property-definitions.json +0 -123
- package/src/lib/search-js-files/index.examples.js +0 -22
- package/src/lib/search-js-files/index.js +0 -155
- package/src/lib/search-js-files/index.spec.js +0 -34
- package/src/lib/search-js-files/scan-file.js +0 -242
- package/src/lib/shorten-text/index.js +0 -25
- package/src/lib/shorten-text/index.spec.js +0 -68
- package/src/lib/strip-numeric/index.js +0 -5
- package/src/lib/strip-response/index.js +0 -30
- package/src/lib/template-replace/index.js +0 -23
- package/src/lib/template-replace/index.spec.js +0 -60
- package/src/lib/timed-abort-controller/index.js +0 -41
- package/src/lib/to-bool/index.js +0 -8
- package/src/lib/to-date/index.js +0 -11
- package/src/lib/to-enum/index.js +0 -14
- package/src/lib/to-number/index.js +0 -12
- package/src/lib/to-number-with-units/index.js +0 -51
- package/src/lib/transcribe/index.js +0 -78
- package/src/prompts/README.md +0 -17
- package/src/prompts/as-enum.js +0 -5
- package/src/prompts/as-json-schema.js +0 -9
- package/src/prompts/as-object-with-schema.js +0 -26
- package/src/prompts/as-schema-org-text.js +0 -25
- package/src/prompts/as-schema-org-type.js +0 -1
- package/src/prompts/blog-post.js +0 -7
- package/src/prompts/code-features.js +0 -24
- package/src/prompts/constants.js +0 -101
- package/src/prompts/features-json-schema.js +0 -27
- package/src/prompts/generate-collection.js +0 -26
- package/src/prompts/generate-list.js +0 -48
- package/src/prompts/generate-questions.js +0 -19
- package/src/prompts/index.js +0 -20
- package/src/prompts/intent.js +0 -60
- package/src/prompts/output-succinct-names.js +0 -3
- package/src/prompts/select-from-threshold.js +0 -17
- package/src/prompts/sort.js +0 -31
- package/src/prompts/style.js +0 -38
- package/src/prompts/summarize.js +0 -13
- package/src/prompts/token-budget.js +0 -3
- package/src/prompts/wrap-list.js +0 -11
- package/src/prompts/wrap-variable.js +0 -36
- package/src/services/llm-model/global-overrides.spec.js +0 -432
- package/src/services/llm-model/index.js +0 -308
- package/src/services/llm-model/model.js +0 -21
- package/src/services/llm-model/negotiate.spec.js +0 -447
- package/src/services/redis/index.js +0 -147
- package/src/test/setup.js +0 -20
- package/src/verblets/README.md +0 -26
- package/src/verblets/auto/index.examples.js +0 -31
- package/src/verblets/auto/index.js +0 -28
- package/src/verblets/auto/index.spec.js +0 -32
- package/src/verblets/bool/README.md +0 -36
- package/src/verblets/bool/index.examples.js +0 -80
- package/src/verblets/bool/index.js +0 -25
- package/src/verblets/bool/index.schema.json +0 -14
- package/src/verblets/bool/index.spec.js +0 -33
- package/src/verblets/central-tendency/README.md +0 -166
- package/src/verblets/central-tendency/central-tendency-result.json +0 -24
- package/src/verblets/central-tendency/index.examples.js +0 -196
- package/src/verblets/central-tendency/index.js +0 -171
- package/src/verblets/central-tendency/index.spec.js +0 -148
- package/src/verblets/conversation-turn/README.md +0 -33
- package/src/verblets/conversation-turn/index.examples.js +0 -218
- package/src/verblets/conversation-turn/index.js +0 -68
- package/src/verblets/conversation-turn/index.spec.js +0 -77
- package/src/verblets/conversation-turn-multi/README.md +0 -31
- package/src/verblets/conversation-turn-multi/index.examples.js +0 -160
- package/src/verblets/conversation-turn-multi/index.js +0 -104
- package/src/verblets/conversation-turn-multi/index.spec.js +0 -63
- package/src/verblets/enum/index.examples.js +0 -30
- package/src/verblets/enum/index.js +0 -18
- package/src/verblets/enum/index.spec.js +0 -35
- package/src/verblets/expect/README.md +0 -64
- package/src/verblets/expect/index.examples.js +0 -109
- package/src/verblets/expect/index.js +0 -75
- package/src/verblets/expect/index.spec.js +0 -127
- package/src/verblets/intent/index.examples.js +0 -139
- package/src/verblets/intent/index.js +0 -60
- package/src/verblets/intent/index.spec.js +0 -31
- package/src/verblets/intersection/README.md +0 -16
- package/src/verblets/intersection/index.examples.js +0 -89
- package/src/verblets/intersection/index.js +0 -125
- package/src/verblets/intersection/index.spec.js +0 -60
- package/src/verblets/intersection/intersection-result.json +0 -16
- package/src/verblets/list-expand/README.md +0 -10
- package/src/verblets/list-expand/index.examples.js +0 -14
- package/src/verblets/list-expand/index.js +0 -104
- package/src/verblets/list-expand/index.spec.js +0 -18
- package/src/verblets/list-expand/list-expand-result.json +0 -16
- package/src/verblets/list-filter/README.md +0 -22
- package/src/verblets/list-filter/index.examples.js +0 -26
- package/src/verblets/list-filter/index.js +0 -18
- package/src/verblets/list-filter/index.spec.js +0 -19
- package/src/verblets/list-find/README.md +0 -11
- package/src/verblets/list-find/index.examples.js +0 -15
- package/src/verblets/list-find/index.js +0 -17
- package/src/verblets/list-find/index.spec.js +0 -19
- package/src/verblets/list-group/README.md +0 -16
- package/src/verblets/list-group/index.examples.js +0 -16
- package/src/verblets/list-group/index.js +0 -112
- package/src/verblets/list-group/index.spec.js +0 -35
- package/src/verblets/list-group/list-group-result.json +0 -16
- package/src/verblets/list-map/README.md +0 -11
- package/src/verblets/list-map/index.examples.js +0 -15
- package/src/verblets/list-map/index.js +0 -26
- package/src/verblets/list-map/index.spec.js +0 -17
- package/src/verblets/list-reduce/README.md +0 -10
- package/src/verblets/list-reduce/index.examples.js +0 -14
- package/src/verblets/list-reduce/index.js +0 -21
- package/src/verblets/list-reduce/index.spec.js +0 -27
- package/src/verblets/list-reduce/index.spec.jsx +0 -27
- package/src/verblets/name/README.md +0 -15
- package/src/verblets/name/index.examples.js +0 -28
- package/src/verblets/name/index.js +0 -19
- package/src/verblets/name/index.spec.js +0 -33
- package/src/verblets/name-similar-to/README.md +0 -26
- package/src/verblets/name-similar-to/index.examples.js +0 -18
- package/src/verblets/name-similar-to/index.js +0 -20
- package/src/verblets/name-similar-to/index.spec.js +0 -13
- package/src/verblets/number/index.examples.js +0 -199
- package/src/verblets/number/index.js +0 -25
- package/src/verblets/number/index.spec.js +0 -33
- package/src/verblets/number-with-units/index.examples.js +0 -38
- package/src/verblets/number-with-units/index.js +0 -84
- package/src/verblets/number-with-units/index.spec.js +0 -46
- package/src/verblets/number-with-units/number-with-units-result.json +0 -23
- package/src/verblets/people-list/README.md +0 -28
- package/src/verblets/people-list/index.examples.js +0 -184
- package/src/verblets/people-list/index.js +0 -44
- package/src/verblets/people-list/index.spec.js +0 -49
- package/src/verblets/schema-org/index.examples.js +0 -51
- package/src/verblets/schema-org/index.js +0 -37
- package/src/verblets/schema-org/index.spec.js +0 -39
- package/src/verblets/sentiment/README.md +0 -10
- package/src/verblets/sentiment/index.examples.js +0 -20
- package/src/verblets/sentiment/index.js +0 -9
- package/src/verblets/sentiment/index.spec.js +0 -20
- package/src/verblets/to-object/README.md +0 -38
- package/src/verblets/to-object/index.examples.js +0 -29
- package/src/verblets/to-object/index.js +0 -131
- package/src/verblets/to-object/index.spec.js +0 -71
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
camelCase,
|
|
4
|
-
paramCase,
|
|
5
|
-
sentenceCase,
|
|
6
|
-
} from 'change-case';
|
|
7
|
-
|
|
8
|
-
const verbletName = process.argv[2];
|
|
9
|
-
|
|
10
|
-
if (!verbletName) {
|
|
11
|
-
console.error('Please specify a verblet name.');
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const verbletDir = `./src/verblets/${paramCase(verbletName)}`;
|
|
16
|
-
const indexFile = `${verbletDir}/index.js`;
|
|
17
|
-
const testFile = `${verbletDir}/index.spec.js`;
|
|
18
|
-
const exampleFile = `${verbletDir}/index.examples.js`;
|
|
19
|
-
|
|
20
|
-
const createFileIfNotExists = (filePath, fileContent, fileType) => {
|
|
21
|
-
if (!fs.existsSync(filePath)) {
|
|
22
|
-
fs.writeFileSync(filePath, fileContent);
|
|
23
|
-
console.error(`Created new ${fileType} file: ${filePath}`);
|
|
24
|
-
} else {
|
|
25
|
-
console.error(`Creating ${fileType} file [skipped]: '${filePath}' exists`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Check if the verblet directory already exists
|
|
30
|
-
if (!fs.existsSync(verbletDir)) {
|
|
31
|
-
// Create the verblet directory
|
|
32
|
-
fs.mkdirSync(verbletDir, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const indexContent = `
|
|
36
|
-
export default async (text) => {
|
|
37
|
-
// TODO: Implement ${paramCase(verbletName)} verblet
|
|
38
|
-
};
|
|
39
|
-
`;
|
|
40
|
-
createFileIfNotExists(indexFile, indexContent, 'module file');
|
|
41
|
-
|
|
42
|
-
const testContent = `import { describe, expect, it, vi } from 'vitest';
|
|
43
|
-
|
|
44
|
-
import ${camelCase(verbletName)} from './index.js';
|
|
45
|
-
|
|
46
|
-
vi.mock('../../lib/chatgpt/index.js', () => ({
|
|
47
|
-
default: vi.fn().mockImplementation((text) => {
|
|
48
|
-
if (/prompt text to match/.test(text)) {
|
|
49
|
-
return 'True';
|
|
50
|
-
} else {
|
|
51
|
-
return 'undefined';
|
|
52
|
-
}
|
|
53
|
-
}),
|
|
54
|
-
}));
|
|
55
|
-
|
|
56
|
-
const examples = [
|
|
57
|
-
{
|
|
58
|
-
name: 'Basic usage',
|
|
59
|
-
inputs: { text: 'test' },
|
|
60
|
-
want: { result: true }
|
|
61
|
-
}
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
describe('${sentenceCase(verbletName)} verblet', () => {
|
|
65
|
-
examples.forEach((example) => {
|
|
66
|
-
it(example.name, async () => {
|
|
67
|
-
const result = await ${camelCase(verbletName)}(example.inputs.text);
|
|
68
|
-
|
|
69
|
-
if (example.want.typeOfResult) {
|
|
70
|
-
expect(typeof result)
|
|
71
|
-
.toStrictEqual(example.want.typeOfResult);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
`;
|
|
77
|
-
createFileIfNotExists(testFile, testContent, 'test');
|
|
78
|
-
|
|
79
|
-
const exampleContent = `import { describe, expect, it, vi } from 'vitest';
|
|
80
|
-
|
|
81
|
-
import ${camelCase(verbletName)} from './index.js';
|
|
82
|
-
|
|
83
|
-
const examples = [
|
|
84
|
-
{
|
|
85
|
-
inputs: { text: 'test' },
|
|
86
|
-
want: { result: true }
|
|
87
|
-
}
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
describe('${sentenceCase(verbletName)} verblet', () => {
|
|
91
|
-
examples.forEach((example) => {
|
|
92
|
-
it(example.inputs.text, async () => {
|
|
93
|
-
const result = await ${camelCase(verbletName)}(example.inputs.text)
|
|
94
|
-
|
|
95
|
-
if (example.want.typeOfResult) {
|
|
96
|
-
expect(typeof result)
|
|
97
|
-
.toStrictEqual(example.want.typeOfResult);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (example.want.result) {
|
|
101
|
-
expect(result)
|
|
102
|
-
.toStrictEqual(example.want.result);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
`;
|
|
108
|
-
createFileIfNotExists(exampleFile, exampleContent, 'example');
|
|
109
|
-
|
|
110
|
-
console.error(`Created new verblet: ${verbletName}`);
|
package/scripts/run.sh
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
script_name="$1"
|
|
4
|
-
if [[ "$script_name" =~ ^[a-zA-Z0-9_-]+$ ]]; then
|
|
5
|
-
script_path="./scripts/$script_name/index.js"
|
|
6
|
-
if [[ -f "$script_path" ]]; then
|
|
7
|
-
node "$script_path" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10"
|
|
8
|
-
else
|
|
9
|
-
echo "Script not found: $script_path"
|
|
10
|
-
exit 1
|
|
11
|
-
fi
|
|
12
|
-
else
|
|
13
|
-
echo "Invalid script name: $script_name"
|
|
14
|
-
exit 1
|
|
15
|
-
fi
|
package/scripts/runner/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import chatGPT, {
|
|
3
|
-
getRedis,
|
|
4
|
-
list,
|
|
5
|
-
retry as run,
|
|
6
|
-
schemas,
|
|
7
|
-
} from '../../src/index.js';
|
|
8
|
-
import modelService from '../../src/services/llm-model/index.js';
|
|
9
|
-
import { Command } from 'commander';
|
|
10
|
-
|
|
11
|
-
const program = new Command();
|
|
12
|
-
program
|
|
13
|
-
.option('-p, --privacy', 'Use privacy model if configured')
|
|
14
|
-
.option('-m, --model <modelName>', 'Specify model name to use');
|
|
15
|
-
|
|
16
|
-
program.parse(process.argv);
|
|
17
|
-
|
|
18
|
-
const options = program.opts();
|
|
19
|
-
|
|
20
|
-
if (options.privacy) {
|
|
21
|
-
try {
|
|
22
|
-
modelService.setGlobalOverride('modelName', 'privacy');
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error(`Privacy model error: ${err.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (options.model) {
|
|
28
|
-
try {
|
|
29
|
-
modelService.setGlobalOverride('modelName', options.model);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.error(`Model override error: ${err.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await run(async () => {
|
|
36
|
-
const results = await chatGPT('make a list of nintendo games with a schema that includes a title, year, and maybe a couple others of your choice', {
|
|
37
|
-
forceQuery: true,
|
|
38
|
-
modelOptions: {
|
|
39
|
-
tools: schemas
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const functions = {
|
|
44
|
-
list: async (listName, options) => {
|
|
45
|
-
return await list(listName, options);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
if (typeof results === 'string') {
|
|
50
|
-
console.error(results);
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
console.error(await functions[results.name](results.arguments.name, results.arguments.options));
|
|
54
|
-
}, { maxRetries: 0 });
|
|
55
|
-
|
|
56
|
-
await (await getRedis()).disconnect();
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# Simple Prompt Editor
|
|
2
|
-
|
|
3
|
-
This is a simple command-line tool that allows you to interact with the ChatGPT library using your system's default text editor or nano if none is defined.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
To run the simple ChatGPT editor, use the following command:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm run script -- simple-editor
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
It will open your system's default text editor or nano if none is defined. The editor allows you to enter your input text, which is then processed by the ChatGPT library. The script performs intent detection to match your request with one of the supported library commands. By default, it does ordinary ChatGPT completion.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Adding Support for New Commands
|
|
17
|
-
|
|
18
|
-
To add support for new commands, you need to modify the operations array in the provided code. Each command should be an object with the following properties:
|
|
19
|
-
|
|
20
|
-
- name: A unique identifier for the command.
|
|
21
|
-
- parameters: An array of parameter names that the command accepts.
|
|
22
|
-
- operation: A function that takes an object with the parameters as keys and returns the result of the command.
|
|
23
|
-
|
|
24
|
-
To add a new command, simply append a new object to the operations array with the required properties. For example, to add a sum command that takes two numbers and returns their sum, you would add the following object:
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
{
|
|
28
|
-
name: 'sum',
|
|
29
|
-
parameters: ['number1', 'number2'],
|
|
30
|
-
operation: ({ number1, number2 }) => Number(number1) + Number(number2),
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
After adding the new command, the intent detection function will be able to match the user's input with the new command, and the script will execute the corresponding operation.
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv/config';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
|
|
4
|
-
import chatGPT, { getRedis, auto, bool } from '../../src/index.js';
|
|
5
|
-
import modelService from '../../src/services/llm-model/index.js';
|
|
6
|
-
import edit from '../../src/lib/editor/index.js';
|
|
7
|
-
import Transcriber from '../../src/lib/transcribe/index.js';
|
|
8
|
-
|
|
9
|
-
const program = new Command();
|
|
10
|
-
program
|
|
11
|
-
.option('-t, --transcribe', 'Enable audio transcription')
|
|
12
|
-
.option('--no-use-intent', 'Disable intent parsing')
|
|
13
|
-
.option('-p, --privacy', 'Use privacy model if configured')
|
|
14
|
-
.option('-m, --model <modelName>', 'Specify model name to use');
|
|
15
|
-
|
|
16
|
-
program.parse(process.argv);
|
|
17
|
-
|
|
18
|
-
const argv = program.opts();
|
|
19
|
-
|
|
20
|
-
if (argv.privacy) {
|
|
21
|
-
try {
|
|
22
|
-
modelService.setGlobalOverride('modelName', 'privacy');
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error(`Privacy model error: ${err.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (argv.model) {
|
|
28
|
-
try {
|
|
29
|
-
modelService.setGlobalOverride('modelName', argv.model);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.error(`Model override error: ${err.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const operations = [
|
|
36
|
-
{
|
|
37
|
-
name: 'bool',
|
|
38
|
-
fn: ({ text }) => {
|
|
39
|
-
return bool(text, { forceQuery: true });
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let userInput;
|
|
46
|
-
const useTranscribe = !!argv.transcribe;
|
|
47
|
-
if (useTranscribe) {
|
|
48
|
-
const transcriber = new Transcriber("stopword"); // Replace "stopword" with the word you want to trigger the stop
|
|
49
|
-
userInput = await transcriber.startRecording()
|
|
50
|
-
} else {
|
|
51
|
-
userInput = await edit();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const useIntent = argv.useIntent !== false;
|
|
55
|
-
|
|
56
|
-
const commandType = useIntent ? 'Tool selection' : 'Direct ChatGPT';
|
|
57
|
-
console.error(`Command: ${commandType}`);
|
|
58
|
-
const userInputDisplay = userInput.trim().split('\n')
|
|
59
|
-
.map(line => `| ${line}`)
|
|
60
|
-
.join('\n');
|
|
61
|
-
|
|
62
|
-
console.error(userInputDisplay);
|
|
63
|
-
|
|
64
|
-
let result;
|
|
65
|
-
if (!useIntent) {
|
|
66
|
-
result = await chatGPT(userInput);
|
|
67
|
-
} else {
|
|
68
|
-
const intentFound = await auto(userInput, { forceQuery: true });
|
|
69
|
-
|
|
70
|
-
const op = operations.find(option => {
|
|
71
|
-
return option.name === intentFound.name;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
result = await op.fn(...intentFound.functionArgsAsArray);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.error(result);
|
|
78
|
-
|
|
79
|
-
await (await getRedis()).disconnect();
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import glob from 'glob';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
|
-
import SummaryMap from '../../src/chains/summary-map/index.js';
|
|
4
|
-
import modelService from '../../src/services/llm-model/index.js';
|
|
5
|
-
import { Command } from 'commander';
|
|
6
|
-
|
|
7
|
-
const program = new Command();
|
|
8
|
-
program
|
|
9
|
-
.argument('[globPattern]', 'Glob pattern to summarize', './src/**/*.js')
|
|
10
|
-
.argument('[targetTokens]', 'Target token count', '4097')
|
|
11
|
-
.option('-p, --privacy', 'Use privacy model if configured')
|
|
12
|
-
.option('-m, --model <modelName>', 'Specify model name to use');
|
|
13
|
-
|
|
14
|
-
program.parse(process.argv);
|
|
15
|
-
|
|
16
|
-
const options = program.opts();
|
|
17
|
-
const [globPattern, targetTokensInput] = program.args;
|
|
18
|
-
const targetTokens = Number(targetTokensInput);
|
|
19
|
-
|
|
20
|
-
if (options.privacy) {
|
|
21
|
-
try {
|
|
22
|
-
modelService.setGlobalOverride('modelName', 'privacy');
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error(`Privacy model error: ${err.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (options.model) {
|
|
28
|
-
try {
|
|
29
|
-
modelService.setGlobalOverride('modelName', options.model);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.error(`Model override error: ${err.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Initialize the SummaryMap with the target tokens
|
|
36
|
-
const map = new SummaryMap({
|
|
37
|
-
targetTokens: targetTokens
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
glob(globPattern, async (err, files) => {
|
|
41
|
-
if (err) {
|
|
42
|
-
console.error(err);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const filePromises = files.map(async (file) => {
|
|
47
|
-
try {
|
|
48
|
-
const content = await readFile(file, 'utf8');
|
|
49
|
-
// Set each file content with its respective filepath as a key
|
|
50
|
-
map.set(file, {
|
|
51
|
-
key: file,
|
|
52
|
-
value: content,
|
|
53
|
-
weight: 1,
|
|
54
|
-
type: 'code'
|
|
55
|
-
});
|
|
56
|
-
} catch (err) {
|
|
57
|
-
console.error(`Error reading file ${file}:`, err);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// When all file read operations complete
|
|
62
|
-
await Promise.all(filePromises);
|
|
63
|
-
const entries = Array.from(await map.entries());
|
|
64
|
-
|
|
65
|
-
// Loop over each key/value and print it to stdout
|
|
66
|
-
for (const [key, value] of entries) {
|
|
67
|
-
console.log(`## ${key}\n`);
|
|
68
|
-
console.log(`\`\`\`js\n${value}\n\`\`\``);
|
|
69
|
-
}
|
|
70
|
-
});
|
package/src/chains/README.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Chains
|
|
2
|
-
|
|
3
|
-
Chains orchestrate multiple verblets or helper functions to perform more complex tasks. Each subdirectory exposes a specific workflow that can be imported as a single function.
|
|
4
|
-
|
|
5
|
-
Available chains:
|
|
6
|
-
|
|
7
|
-
- [anonymize](./anonymize)
|
|
8
|
-
- [bulk-map](./bulk-map)
|
|
9
|
-
- [bulk-reduce](./bulk-reduce)
|
|
10
|
-
- [bulk-filter](./bulk-filter)
|
|
11
|
-
- [bulk-group](./bulk-group)
|
|
12
|
-
- [dismantle](./dismantle)
|
|
13
|
-
- [disambiguate](./disambiguate)
|
|
14
|
-
- [intersections](./intersections)
|
|
15
|
-
- [list](./list)
|
|
16
|
-
- [questions](./questions)
|
|
17
|
-
- [socratic](./socratic)
|
|
18
|
-
- [glossary](./glossary)
|
|
19
|
-
- [scan-js](./scan-js)
|
|
20
|
-
- [sort](./sort)
|
|
21
|
-
- [summary-map](./summary-map)
|
|
22
|
-
- [themes](./themes)
|
|
23
|
-
- [set-interval](./set-interval)
|
|
24
|
-
- [test](./test)
|
|
25
|
-
- [test-advice](./test-advice)
|
|
26
|
-
- [veiled-variants](./veiled-variants)
|
|
27
|
-
- [collect-terms](./collect-terms) - gather complex vocabulary
|
|
28
|
-
|
|
29
|
-
Chains are free to use any utilities from [`../lib`](../lib/README.md) and often rely on one or more verblets from [`../verblets`](../verblets/README.md).
|
|
30
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# anonymize
|
|
2
|
-
|
|
3
|
-
Remove personal style, references, and formatting from text to conceal the original author. The chain runs through your configured LLM models, so it works with fully private or self‑hosted LLMs.
|
|
4
|
-
|
|
5
|
-
Supported methods: `STRICT`, `BALANCED`, and `LIGHT` to control how aggressively style is removed.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
```javascript
|
|
9
|
-
import anonymize, { anonymizeMethod } from './index.js';
|
|
10
|
-
|
|
11
|
-
const message = `As a software lead in Chicago, I've found our new UI framework helps junior devs ramp up fast.`;
|
|
12
|
-
|
|
13
|
-
const { text } = await anonymize({
|
|
14
|
-
text: message,
|
|
15
|
-
method: anonymizeMethod.STRICT,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
console.log(text);
|
|
19
|
-
// => "The new UI framework shortens the learning curve for new developers."
|
|
20
|
-
```
|
|
21
|
-
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { anonymize, anonymizeMethod } from './index.js';
|
|
4
|
-
|
|
5
|
-
const sampleText = `As a seasoned engineer from Silicon Valley, I've found that React's
|
|
6
|
-
component lifecycle is like a well-oiled machine - understanding the mounting
|
|
7
|
-
phase is crucial, especially with those pesky useEffect hooks. Trust me, after
|
|
8
|
-
10 years of experience, proper cleanup is key to avoiding memory leaks!`;
|
|
9
|
-
|
|
10
|
-
describe('anonymize examples', () => {
|
|
11
|
-
it.only('should anonymize text using strict method', { timeout: 60_000 }, async () => {
|
|
12
|
-
const input = {
|
|
13
|
-
text: sampleText,
|
|
14
|
-
method: anonymizeMethod.STRICT,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const result = await anonymize(input);
|
|
18
|
-
|
|
19
|
-
expect(result).to.have.property('text');
|
|
20
|
-
expect(result).to.have.property('stages');
|
|
21
|
-
expect(result.stages).to.have.property('distinctiveContentRemoved');
|
|
22
|
-
expect(result.stages).to.have.property('structureNormalized');
|
|
23
|
-
expect(result.stages).to.have.property('patternsSuppressed');
|
|
24
|
-
|
|
25
|
-
// Verify anonymization removed personal markers
|
|
26
|
-
expect(result.text).to.not.include('Silicon Valley');
|
|
27
|
-
expect(result.text).to.not.include('10 years of experience');
|
|
28
|
-
expect(result.text).to.not.include('Trust me');
|
|
29
|
-
|
|
30
|
-
// Verify metaphors and idioms are removed
|
|
31
|
-
expect(result.text).to.not.include('well-oiled machine');
|
|
32
|
-
expect(result.text).to.not.include('pesky');
|
|
33
|
-
|
|
34
|
-
// Verify the text has been transformed
|
|
35
|
-
expect(result.text).to.not.equal(sampleText);
|
|
36
|
-
expect(result.text.length).to.be.lessThan(sampleText.length);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should preserve more content with balanced method', { timeout: 60_000 }, async () => {
|
|
40
|
-
const input = {
|
|
41
|
-
text: sampleText,
|
|
42
|
-
method: anonymizeMethod.BALANCED,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const result = await anonymize(input);
|
|
46
|
-
|
|
47
|
-
// Verify some personal markers are still removed
|
|
48
|
-
expect(result.text).to.not.include('Silicon Valley');
|
|
49
|
-
expect(result.text).to.not.include('Trust me');
|
|
50
|
-
|
|
51
|
-
// But technical content is more preserved
|
|
52
|
-
expect(result.text.length).to.be.greaterThan(
|
|
53
|
-
(await anonymize({ text: sampleText, method: anonymizeMethod.STRICT })).text.length
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should minimally transform text with light method', { timeout: 60_000 }, async () => {
|
|
58
|
-
const input = {
|
|
59
|
-
text: sampleText,
|
|
60
|
-
method: anonymizeMethod.LIGHT,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const result = await anonymize(input);
|
|
64
|
-
|
|
65
|
-
// Verify minimal transformation
|
|
66
|
-
expect(result.text.length).to.be.greaterThan(
|
|
67
|
-
(await anonymize({ text: sampleText, method: anonymizeMethod.BALANCED })).text.length
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// Only the most obvious personal markers should be removed
|
|
71
|
-
expect(result.text).to.not.include('Trust me');
|
|
72
|
-
|
|
73
|
-
expect(result.text).to.not.include("I've found");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { run } from '../../lib/chatgpt/index.js';
|
|
2
|
-
|
|
3
|
-
export const anonymizeMethod = {
|
|
4
|
-
STRICT: 'strict',
|
|
5
|
-
BALANCED: 'balanced',
|
|
6
|
-
LIGHT: 'light',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const METHODS = Object.values(anonymizeMethod);
|
|
10
|
-
|
|
11
|
-
const validateInput = (input) => {
|
|
12
|
-
if (!input || typeof input !== 'object') {
|
|
13
|
-
throw new Error('Input must be an object');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const { text, method, context } = input;
|
|
17
|
-
|
|
18
|
-
if (!text || typeof text !== 'string') {
|
|
19
|
-
throw new Error('Input must include a text string');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!method || !METHODS.includes(method)) {
|
|
23
|
-
throw new Error(`Method must be one of: ${METHODS.join(', ')}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (context !== undefined && typeof context !== 'string') {
|
|
27
|
-
throw new Error('Context must be a string if provided');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { text, method, context };
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const stage1Prompt = (text, context) => `
|
|
34
|
-
Remove Distinctive Content and Markers
|
|
35
|
-
- Identify and replace every distinctive or uncommon word, phrase, or sentence structure with the most widely used, nondescript alternative.
|
|
36
|
-
- Remove all idioms, metaphors, analogies, cultural references, personal perspectives, and subjective tones.
|
|
37
|
-
- Eliminate any explicit or implicit references to the author's identity, background, education, expertise, region, or intent.
|
|
38
|
-
|
|
39
|
-
${context ? `Context: ${context}\n` : ''}
|
|
40
|
-
Text to process:
|
|
41
|
-
${text}
|
|
42
|
-
|
|
43
|
-
Return ONLY the processed text, with no explanations or additional content.`;
|
|
44
|
-
|
|
45
|
-
const stage2Prompt = (text, context) => `
|
|
46
|
-
Normalize Structure, Formatting, and Tone
|
|
47
|
-
- Restructure sentences and paragraphs to strictly follow standard, average patterns in length, order, and construction. Avoid any distinctive rhythm, complexity, or flow.
|
|
48
|
-
- Uniformly normalize punctuation, formatting, and paragraphing; avoid any variation or emphasis that could signal style.
|
|
49
|
-
- Strip out all emotional, evaluative, or expressive language, enforcing a neutral, impersonal, and objective tone.
|
|
50
|
-
|
|
51
|
-
${context ? `Context: ${context}\n` : ''}
|
|
52
|
-
Text to process:
|
|
53
|
-
${text}
|
|
54
|
-
|
|
55
|
-
Return ONLY the normalized text, with no explanations or additional content.`;
|
|
56
|
-
|
|
57
|
-
const stage3Prompt = (text, context) => `
|
|
58
|
-
Stage 3: Suppress Latent Stylistic Patterns
|
|
59
|
-
- Review for and suppress any recurring linguistic patterns, syntactic habits, or structural quirks—even if they appear common.
|
|
60
|
-
- For all possible ways to phrase content, always select the plainest, most generic, and least distinctive form.
|
|
61
|
-
- Ensure the final text reads as if generated by an automated system, with no evidence of personality, emotion, region, or any unique authorial traits.
|
|
62
|
-
|
|
63
|
-
${context ? `Context: ${context}\n` : ''}
|
|
64
|
-
Text to process:
|
|
65
|
-
${text}
|
|
66
|
-
|
|
67
|
-
Return ONLY the final anonymized text, with no explanations or additional content.`;
|
|
68
|
-
|
|
69
|
-
const anonymize = async (input, config = {}) => {
|
|
70
|
-
const { text, method, context } = validateInput(input);
|
|
71
|
-
const { llm, ...options } = config;
|
|
72
|
-
|
|
73
|
-
// Stage 1: Remove distinctive content
|
|
74
|
-
const stage1Result = await run(stage1Prompt(text, method, context), {
|
|
75
|
-
modelOptions: { modelName: 'privacy', ...llm },
|
|
76
|
-
...options,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (method === anonymizeMethod.LIGHT) {
|
|
80
|
-
return {
|
|
81
|
-
text: stage1Result,
|
|
82
|
-
stages: {
|
|
83
|
-
distinctiveContentRemoved: stage1Result,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Stage 2: Normalize structure and tone
|
|
89
|
-
const stage2Result = await run(stage2Prompt(stage1Result, method), {
|
|
90
|
-
modelOptions: { modelName: 'privacy', ...llm },
|
|
91
|
-
...options,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
if (method === anonymizeMethod.BALANCED) {
|
|
95
|
-
return {
|
|
96
|
-
text: stage2Result,
|
|
97
|
-
stages: {
|
|
98
|
-
distinctiveContentRemoved: stage1Result,
|
|
99
|
-
structureNormalized: stage2Result,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Stage 3: Suppress stylistic patterns
|
|
105
|
-
const stage3Result = await run(stage3Prompt(stage2Result, method), {
|
|
106
|
-
modelOptions: { modelName: 'privacy', ...llm },
|
|
107
|
-
...options,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
text: stage3Result,
|
|
112
|
-
stages: {
|
|
113
|
-
distinctiveContentRemoved: stage1Result,
|
|
114
|
-
structureNormalized: stage2Result,
|
|
115
|
-
patternsSuppressed: stage3Result,
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export { anonymize };
|
|
121
|
-
export default anonymize;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { anonymize, anonymizeMethod } from './index.js';
|
|
3
|
-
|
|
4
|
-
vi.mock('./index.js', () => {
|
|
5
|
-
return {
|
|
6
|
-
anonymize: vi.fn(async (input) => {
|
|
7
|
-
if (!input || typeof input.text !== 'string' || !input.text.trim()) {
|
|
8
|
-
throw new Error('Text is required');
|
|
9
|
-
}
|
|
10
|
-
if (!input.method) {
|
|
11
|
-
throw new Error('Method is required');
|
|
12
|
-
}
|
|
13
|
-
if (!['STRICT', 'BALANCED', 'LIGHT'].includes(input.method)) {
|
|
14
|
-
throw new Error('Invalid method');
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
text: 'anonymized',
|
|
18
|
-
stages: {
|
|
19
|
-
distinctiveContentRemoved: true,
|
|
20
|
-
structureNormalized: true,
|
|
21
|
-
patternsSuppressed: true,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}),
|
|
25
|
-
anonymizeMethod: { STRICT: 'STRICT', BALANCED: 'BALANCED', LIGHT: 'LIGHT' },
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('anonymize', () => {
|
|
30
|
-
it('should return an object with text and stages properties', async () => {
|
|
31
|
-
const input = {
|
|
32
|
-
text: 'Test input',
|
|
33
|
-
method: anonymizeMethod.LIGHT,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const result = await anonymize(input);
|
|
37
|
-
|
|
38
|
-
expect(result).to.have.property('text');
|
|
39
|
-
expect(result).to.have.property('stages');
|
|
40
|
-
expect(result.stages).to.have.property('distinctiveContentRemoved');
|
|
41
|
-
expect(result.stages).to.have.property('structureNormalized');
|
|
42
|
-
expect(result.stages).to.have.property('patternsSuppressed');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should throw an error if method is not provided', async () => {
|
|
46
|
-
const input = {
|
|
47
|
-
text: 'Test input',
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
await expect(anonymize(input)).rejects.toThrow('Method is required');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should throw an error if method is invalid', async () => {
|
|
54
|
-
const input = {
|
|
55
|
-
text: 'Test input',
|
|
56
|
-
method: 'INVALID',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
await expect(anonymize(input)).rejects.toThrow('Invalid method');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should throw an error if text is not provided', async () => {
|
|
63
|
-
const input = {
|
|
64
|
-
method: anonymizeMethod.LIGHT,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
await expect(anonymize(input)).rejects.toThrow('Text is required');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should throw an error if text is empty', async () => {
|
|
71
|
-
const input = {
|
|
72
|
-
text: '',
|
|
73
|
-
method: anonymizeMethod.LIGHT,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
await expect(anonymize(input)).rejects.toThrow('Text is required');
|
|
77
|
-
});
|
|
78
|
-
});
|