promptfoo 0.72.1 → 0.73.0
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 +5 -5
- package/dist/package.json +14 -8
- package/dist/src/accounts.d.ts.map +1 -1
- package/dist/src/accounts.js +2 -1
- package/dist/src/accounts.js.map +1 -1
- package/dist/src/assertions/validateAssertions.d.ts +1 -1
- package/dist/src/assertions/validateAssertions.d.ts.map +1 -1
- package/dist/src/assertions/validateAssertions.js +7 -7
- package/dist/src/assertions/validateAssertions.js.map +1 -1
- package/dist/src/assertions.d.ts.map +1 -1
- package/dist/src/assertions.js +2 -1
- package/dist/src/assertions.js.map +1 -1
- package/dist/src/cache.js +2 -2
- package/dist/src/cache.js.map +1 -1
- package/dist/src/commands/eval.d.ts.map +1 -1
- package/dist/src/commands/eval.js +10 -0
- package/dist/src/commands/eval.js.map +1 -1
- package/dist/src/commands/export.d.ts.map +1 -1
- package/dist/src/commands/export.js +15 -14
- package/dist/src/commands/export.js.map +1 -1
- package/dist/src/commands/generate/redteam.d.ts +1 -46
- package/dist/src/commands/generate/redteam.d.ts.map +1 -1
- package/dist/src/commands/generate/redteam.js +70 -26
- package/dist/src/commands/generate/redteam.js.map +1 -1
- package/dist/src/commands/import.d.ts.map +1 -1
- package/dist/src/commands/import.js +2 -1
- package/dist/src/commands/import.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +12 -0
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/redteam.d.ts.map +1 -1
- package/dist/src/commands/redteam.js +72 -18
- package/dist/src/commands/redteam.js.map +1 -1
- package/dist/src/commands/view.d.ts.map +1 -1
- package/dist/src/commands/view.js +2 -1
- package/dist/src/commands/view.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +2 -20
- package/dist/src/config.js.map +1 -1
- package/dist/src/configTypes.d.ts +7 -0
- package/dist/src/configTypes.d.ts.map +1 -0
- package/dist/src/configTypes.js +3 -0
- package/dist/src/configTypes.js.map +1 -0
- package/dist/src/database/index.d.ts +4 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/index.js +50 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/{database.d.ts → database/operations.d.ts} +173 -115
- package/dist/src/{database.d.ts.map → database/operations.d.ts.map} +1 -1
- package/dist/src/{database.js → database/operations.js} +1 -25
- package/dist/src/database/operations.js.map +1 -0
- package/dist/src/evaluator.js +2 -2
- package/dist/src/evaluator.js.map +1 -1
- package/dist/src/globalConfig.d.ts +1 -7
- package/dist/src/globalConfig.d.ts.map +1 -1
- package/dist/src/globalConfig.js +3 -3
- package/dist/src/globalConfig.js.map +1 -1
- package/dist/src/matchers.d.ts.map +1 -1
- package/dist/src/matchers.js +6 -2
- package/dist/src/matchers.js.map +1 -1
- package/dist/src/prompts/grading.js +2 -2
- package/dist/src/prompts/processors/python.js +4 -4
- package/dist/src/prompts/processors/python.js.map +1 -1
- package/dist/src/providers/anthropic.d.ts +1 -1
- package/dist/src/providers/anthropic.d.ts.map +1 -1
- package/dist/src/providers/bam.d.ts +1 -1
- package/dist/src/providers/bam.d.ts.map +1 -1
- package/dist/src/providers/bedrock.d.ts +1 -1
- package/dist/src/providers/bedrock.d.ts.map +1 -1
- package/dist/src/providers/cohere.d.ts.map +1 -1
- package/dist/src/providers/cohere.js +4 -1
- package/dist/src/providers/cohere.js.map +1 -1
- package/dist/src/providers/http.d.ts +1 -1
- package/dist/src/providers/http.d.ts.map +1 -1
- package/dist/src/providers/http.js +3 -3
- package/dist/src/providers/http.js.map +1 -1
- package/dist/src/providers/llama.d.ts +1 -1
- package/dist/src/providers/llama.d.ts.map +1 -1
- package/dist/src/providers/localai.d.ts +1 -1
- package/dist/src/providers/localai.d.ts.map +1 -1
- package/dist/src/providers/ollama.d.ts +1 -1
- package/dist/src/providers/ollama.d.ts.map +1 -1
- package/dist/src/providers/openai.d.ts +1 -1
- package/dist/src/providers/openai.d.ts.map +1 -1
- package/dist/src/providers/openai.js +48 -50
- package/dist/src/providers/openai.js.map +1 -1
- package/dist/src/providers/palm.d.ts +1 -1
- package/dist/src/providers/palm.d.ts.map +1 -1
- package/dist/src/providers/pythonCompletion.d.ts.map +1 -1
- package/dist/src/providers/pythonCompletion.js +6 -5
- package/dist/src/providers/pythonCompletion.js.map +1 -1
- package/dist/src/providers/replicate.js +2 -2
- package/dist/src/providers/replicate.js.map +1 -1
- package/dist/src/providers/scriptCompletion.js +3 -3
- package/dist/src/providers/scriptCompletion.js.map +1 -1
- package/dist/src/providers/vertex.d.ts +1 -1
- package/dist/src/providers/vertex.d.ts.map +1 -1
- package/dist/src/providers/vertex.js +23 -10
- package/dist/src/providers/vertex.js.map +1 -1
- package/dist/src/providers/vertexUtil.d.ts +2 -1
- package/dist/src/providers/vertexUtil.d.ts.map +1 -1
- package/dist/src/providers/vertexUtil.js.map +1 -1
- package/dist/src/providers/webhook.d.ts +1 -1
- package/dist/src/providers/webhook.d.ts.map +1 -1
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +5 -2
- package/dist/src/providers.js.map +1 -1
- package/dist/src/python/pythonUtils.d.ts +4 -0
- package/dist/src/python/pythonUtils.d.ts.map +1 -0
- package/dist/src/python/pythonUtils.js +51 -0
- package/dist/src/python/pythonUtils.js.map +1 -0
- package/dist/src/python/wrapper.d.ts +0 -10
- package/dist/src/python/wrapper.d.ts.map +1 -1
- package/dist/src/python/wrapper.js +2 -49
- package/dist/src/python/wrapper.js.map +1 -1
- package/dist/src/redteam/constants.d.ts +60 -3
- package/dist/src/redteam/constants.d.ts.map +1 -1
- package/dist/src/redteam/constants.js +71 -10
- package/dist/src/redteam/constants.js.map +1 -1
- package/dist/src/redteam/index.d.ts +15 -4
- package/dist/src/redteam/index.d.ts.map +1 -1
- package/dist/src/redteam/index.js +110 -33
- package/dist/src/redteam/index.js.map +1 -1
- package/dist/src/redteam/plugins/base.d.ts +10 -13
- package/dist/src/redteam/plugins/base.d.ts.map +1 -1
- package/dist/src/redteam/plugins/base.js +36 -20
- package/dist/src/redteam/plugins/base.js.map +1 -1
- package/dist/src/redteam/plugins/debugInterface.d.ts +7 -0
- package/dist/src/redteam/plugins/debugInterface.d.ts.map +1 -0
- package/dist/src/redteam/plugins/debugInterface.js +49 -0
- package/dist/src/redteam/plugins/debugInterface.js.map +1 -0
- package/dist/src/redteam/plugins/harmful.d.ts +1 -54
- package/dist/src/redteam/plugins/harmful.d.ts.map +1 -1
- package/dist/src/redteam/plugins/harmful.js +8 -51
- package/dist/src/redteam/plugins/harmful.js.map +1 -1
- package/dist/src/redteam/plugins/pii.d.ts +9 -10
- package/dist/src/redteam/plugins/pii.d.ts.map +1 -1
- package/dist/src/redteam/plugins/pii.js +33 -53
- package/dist/src/redteam/plugins/pii.js.map +1 -1
- package/dist/src/redteam/plugins/rbac.d.ts +7 -0
- package/dist/src/redteam/plugins/rbac.d.ts.map +1 -0
- package/dist/src/redteam/plugins/rbac.js +49 -0
- package/dist/src/redteam/plugins/rbac.js.map +1 -0
- package/dist/src/redteam/plugins/shellInjection.d.ts +7 -0
- package/dist/src/redteam/plugins/shellInjection.d.ts.map +1 -0
- package/dist/src/redteam/plugins/shellInjection.js +54 -0
- package/dist/src/redteam/plugins/shellInjection.js.map +1 -0
- package/dist/src/redteam/plugins/sqlInjection.d.ts +7 -0
- package/dist/src/redteam/plugins/sqlInjection.d.ts.map +1 -0
- package/dist/src/redteam/plugins/sqlInjection.js +44 -0
- package/dist/src/redteam/plugins/sqlInjection.js.map +1 -0
- package/dist/src/redteam/providers/iterative.d.ts.map +1 -1
- package/dist/src/redteam/providers/iterative.js +2 -1
- package/dist/src/redteam/providers/iterative.js.map +1 -1
- package/dist/src/redteam/strategies/injections.d.ts.map +1 -0
- package/dist/src/redteam/{methods → strategies}/injections.js +0 -12
- package/dist/src/redteam/strategies/injections.js.map +1 -0
- package/dist/src/redteam/strategies/iterative.d.ts.map +1 -0
- package/dist/src/redteam/strategies/iterative.js.map +1 -0
- package/dist/src/redteam/types.d.ts +196 -0
- package/dist/src/redteam/types.d.ts.map +1 -0
- package/dist/src/redteam/types.js +124 -0
- package/dist/src/redteam/types.js.map +1 -0
- package/dist/src/redteam/util.d.ts +22 -0
- package/dist/src/redteam/util.d.ts.map +1 -0
- package/dist/src/redteam/util.js +56 -0
- package/dist/src/redteam/util.js.map +1 -0
- package/dist/src/testCases.d.ts +1 -2
- package/dist/src/testCases.d.ts.map +1 -1
- package/dist/src/testCases.js.map +1 -1
- package/dist/src/types/databaseTypes.d.ts +17 -0
- package/dist/src/types/databaseTypes.d.ts.map +1 -0
- package/dist/src/types/databaseTypes.js +3 -0
- package/dist/src/types/databaseTypes.js.map +1 -0
- package/dist/src/{types.d.ts → types/index.d.ts} +4296 -1425
- package/dist/src/{types.d.ts.map → types/index.d.ts.map} +1 -1
- package/dist/src/{types.js → types/index.js} +38 -9
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/util/config.d.ts +3 -0
- package/dist/src/util/config.d.ts.map +1 -0
- package/dist/src/util/config.js +42 -0
- package/dist/src/util/config.js.map +1 -0
- package/dist/src/util/index.d.ts +41 -25
- package/dist/src/util/index.d.ts.map +1 -1
- package/dist/src/util/index.js +81 -119
- package/dist/src/util/index.js.map +1 -1
- package/dist/src/util/json.d.ts +3 -0
- package/dist/src/util/json.d.ts.map +1 -0
- package/dist/src/util/json.js +27 -0
- package/dist/src/util/json.js.map +1 -0
- package/dist/src/web/nextui/404/index.html +1 -1
- package/dist/src/web/nextui/404.html +1 -1
- package/dist/src/web/nextui/_next/static/chunks/155-4e319e68476266ee.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/163-93bab94bc04ae71b.js +6 -0
- package/dist/src/web/nextui/_next/static/chunks/{258-4acb452fe85cff6f.js → 258-b6257e5de9d0e2c7.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/281-64d9f1415a301ee5.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/304-cf667fe8f06238b4.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/322-b47b6cc3f5b5fdb8.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/325-0d36870ade5e5263.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/339-79124d204fa988a3.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/378-c135e497df1864cb.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/476-0afb5eb266c57b7f.js +17 -0
- package/dist/src/web/nextui/_next/static/chunks/493-ebd12f00541c4969.js +2 -0
- package/dist/src/web/nextui/_next/static/chunks/497-e280a5610a3d7d42.js +32 -0
- package/dist/src/web/nextui/_next/static/chunks/515-e06d044f12d8a1bd.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/69-5e4d5e60859a86d2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/737-32d5472455807d7a.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/903-7cc440d9f9e9f95d.js +97 -0
- package/dist/src/web/nextui/_next/static/chunks/905-78cd666f27891ee6.js +28 -0
- package/dist/src/web/nextui/_next/static/chunks/916-b92fea2ab6136411.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/969-6ab6c8f4158da970.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-7247b17e8f179a46.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-8560afaf494f9882.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-6e6ec3c778ccd110.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-fe10d5df88bc44ef.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/{page-0a39d3450aa09dda.js → page-057e5eb83e0f614b.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/page-88fa70fc5bf755bc.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/layout-15abf0d1049cb47c.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/{page-5650318e57510b6c.js → page-122e9cfa52eb218a.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/app/progress/page-a62ca531a4bb4149.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-10bb2e571670139c.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/report/page-a8b83960f08e2bb2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6ea3e180c3116fb2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/{main-app-929a26b3c8cd3f7a.js → main-app-7a1376166cb8b72e.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/{webpack-c9f728822666f852.js → webpack-ee33d95b3e219985.js} +1 -1
- package/dist/src/web/nextui/_next/static/css/13f881e4290b6d59.css +1 -0
- package/dist/src/web/nextui/_next/static/css/87b5e6e04efd27e5.css +1 -0
- package/dist/src/web/nextui/_next/static/css/e17fdafd8599f69b.css +1 -0
- package/dist/src/web/nextui/_next/static/css/eb523daddb89dfc1.css +1 -0
- package/dist/src/web/nextui/auth/login/index.html +1 -1
- package/dist/src/web/nextui/auth/login/index.txt +6 -6
- package/dist/src/web/nextui/auth/signup/index.html +1 -1
- package/dist/src/web/nextui/auth/signup/index.txt +6 -6
- package/dist/src/web/nextui/datasets/index.html +1 -1
- package/dist/src/web/nextui/datasets/index.txt +6 -6
- package/dist/src/web/nextui/eval/index.html +1 -1
- package/dist/src/web/nextui/eval/index.txt +8 -8
- package/dist/src/web/nextui/index.html +1 -1
- package/dist/src/web/nextui/index.txt +5 -5
- package/dist/src/web/nextui/logo-panda.svg +91 -0
- package/dist/src/web/nextui/progress/index.html +1 -1
- package/dist/src/web/nextui/progress/index.txt +6 -6
- package/dist/src/web/nextui/prompts/index.html +1 -1
- package/dist/src/web/nextui/prompts/index.txt +6 -6
- package/dist/src/web/nextui/report/index.html +1 -1
- package/dist/src/web/nextui/report/index.txt +8 -8
- package/dist/src/web/nextui/setup/index.html +1 -1
- package/dist/src/web/nextui/setup/index.txt +7 -7
- package/dist/test/__mocks__/tempCustomModule.d.ts +13 -0
- package/dist/test/__mocks__/tempCustomModule.d.ts.map +1 -0
- package/dist/test/__mocks__/tempCustomModule.js +15 -0
- package/dist/test/__mocks__/tempCustomModule.js.map +1 -0
- package/dist/test/account.test.d.ts +2 -0
- package/dist/test/account.test.d.ts.map +1 -0
- package/dist/test/account.test.js +46 -0
- package/dist/test/account.test.js.map +1 -0
- package/dist/test/assertions/AssertionResult.test.d.ts +2 -0
- package/dist/test/assertions/AssertionResult.test.d.ts.map +1 -0
- package/dist/test/assertions/AssertionResult.test.js +184 -0
- package/dist/test/assertions/AssertionResult.test.js.map +1 -0
- package/dist/test/assertions/validateAssertions.test.d.ts +2 -0
- package/dist/test/assertions/validateAssertions.test.d.ts.map +1 -0
- package/dist/test/assertions/validateAssertions.test.js +40 -0
- package/dist/test/assertions/validateAssertions.test.js.map +1 -0
- package/dist/test/assertions.test.d.ts +2 -0
- package/dist/test/assertions.test.d.ts.map +1 -0
- package/dist/test/assertions.test.js +3162 -0
- package/dist/test/assertions.test.js.map +1 -0
- package/dist/test/cache.test.d.ts +2 -0
- package/dist/test/cache.test.d.ts.map +1 -0
- package/dist/test/cache.test.js +90 -0
- package/dist/test/cache.test.js.map +1 -0
- package/dist/test/checkNodeVersion.test.d.ts +2 -0
- package/dist/test/checkNodeVersion.test.d.ts.map +1 -0
- package/dist/test/checkNodeVersion.test.js +85 -0
- package/dist/test/checkNodeVersion.test.js.map +1 -0
- package/dist/test/commands/eval/filterFailingTests.test.d.ts +2 -0
- package/dist/test/commands/eval/filterFailingTests.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterFailingTests.test.js +84 -0
- package/dist/test/commands/eval/filterFailingTests.test.js.map +1 -0
- package/dist/test/commands/eval/filterProviders.test.d.ts +2 -0
- package/dist/test/commands/eval/filterProviders.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterProviders.test.js +50 -0
- package/dist/test/commands/eval/filterProviders.test.js.map +1 -0
- package/dist/test/commands/eval/filterTests.test.d.ts +2 -0
- package/dist/test/commands/eval/filterTests.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterTests.test.js +51 -0
- package/dist/test/commands/eval/filterTests.test.js.map +1 -0
- package/dist/test/config.test.d.ts +2 -0
- package/dist/test/config.test.d.ts.map +1 -0
- package/dist/test/config.test.js +404 -0
- package/dist/test/config.test.js.map +1 -0
- package/dist/test/csv.test.d.ts +2 -0
- package/dist/test/csv.test.d.ts.map +1 -0
- package/dist/test/csv.test.js +239 -0
- package/dist/test/csv.test.js.map +1 -0
- package/dist/test/evaluator.test.d.ts +2 -0
- package/dist/test/evaluator.test.d.ts.map +1 -0
- package/dist/test/evaluator.test.js +922 -0
- package/dist/test/evaluator.test.js.map +1 -0
- package/dist/test/globalConfig.test.d.ts +2 -0
- package/dist/test/globalConfig.test.d.ts.map +1 -0
- package/dist/test/globalConfig.test.js +91 -0
- package/dist/test/globalConfig.test.js.map +1 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.d.ts +2 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.d.ts.map +1 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.js +179 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.js.map +1 -0
- package/dist/test/matchers.test.d.ts +2 -0
- package/dist/test/matchers.test.d.ts.map +1 -0
- package/dist/test/matchers.test.js +807 -0
- package/dist/test/matchers.test.js.map +1 -0
- package/dist/test/prompts.processors.javascript.test.d.ts +2 -0
- package/dist/test/prompts.processors.javascript.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.javascript.test.js +93 -0
- package/dist/test/prompts.processors.javascript.test.js.map +1 -0
- package/dist/test/prompts.processors.json.test.d.ts +2 -0
- package/dist/test/prompts.processors.json.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.json.test.js +67 -0
- package/dist/test/prompts.processors.json.test.js.map +1 -0
- package/dist/test/prompts.processors.jsonl.test.d.ts +2 -0
- package/dist/test/prompts.processors.jsonl.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.jsonl.test.js +99 -0
- package/dist/test/prompts.processors.jsonl.test.js.map +1 -0
- package/dist/test/prompts.processors.python.test.d.ts +2 -0
- package/dist/test/prompts.processors.python.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.python.test.js +100 -0
- package/dist/test/prompts.processors.python.test.js.map +1 -0
- package/dist/test/prompts.processors.python.utils.test.d.ts +2 -0
- package/dist/test/prompts.processors.python.utils.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.python.utils.test.js +68 -0
- package/dist/test/prompts.processors.python.utils.test.js.map +1 -0
- package/dist/test/prompts.processors.string.test.d.ts +2 -0
- package/dist/test/prompts.processors.string.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.string.test.js +24 -0
- package/dist/test/prompts.processors.string.test.js.map +1 -0
- package/dist/test/prompts.processors.text.test.d.ts +2 -0
- package/dist/test/prompts.processors.text.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.text.test.js +109 -0
- package/dist/test/prompts.processors.text.test.js.map +1 -0
- package/dist/test/prompts.processors.yaml.test.d.ts +2 -0
- package/dist/test/prompts.processors.yaml.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.yaml.test.js +76 -0
- package/dist/test/prompts.processors.yaml.test.js.map +1 -0
- package/dist/test/prompts.test.d.ts +2 -0
- package/dist/test/prompts.test.d.ts.map +1 -0
- package/dist/test/prompts.test.js +562 -0
- package/dist/test/prompts.test.js.map +1 -0
- package/dist/test/prompts.utils.test.d.ts +2 -0
- package/dist/test/prompts.utils.test.d.ts.map +1 -0
- package/dist/test/prompts.utils.test.js +123 -0
- package/dist/test/prompts.utils.test.js.map +1 -0
- package/dist/test/providers.anthropic.test.d.ts +2 -0
- package/dist/test/providers.anthropic.test.d.ts.map +1 -0
- package/dist/test/providers.anthropic.test.js +520 -0
- package/dist/test/providers.anthropic.test.js.map +1 -0
- package/dist/test/providers.azure.test.d.ts +2 -0
- package/dist/test/providers.azure.test.d.ts.map +1 -0
- package/dist/test/providers.azure.test.js +96 -0
- package/dist/test/providers.azure.test.js.map +1 -0
- package/dist/test/providers.bedrock.test.d.ts +2 -0
- package/dist/test/providers.bedrock.test.d.ts.map +1 -0
- package/dist/test/providers.bedrock.test.js +349 -0
- package/dist/test/providers.bedrock.test.js.map +1 -0
- package/dist/test/providers.http.test.d.ts +2 -0
- package/dist/test/providers.http.test.d.ts.map +1 -0
- package/dist/test/providers.http.test.js +130 -0
- package/dist/test/providers.http.test.js.map +1 -0
- package/dist/test/providers.llama.test.d.ts +2 -0
- package/dist/test/providers.llama.test.d.ts.map +1 -0
- package/dist/test/providers.llama.test.js +101 -0
- package/dist/test/providers.llama.test.js.map +1 -0
- package/dist/test/providers.pythonCompletion.test.d.ts +2 -0
- package/dist/test/providers.pythonCompletion.test.d.ts.map +1 -0
- package/dist/test/providers.pythonCompletion.test.js +149 -0
- package/dist/test/providers.pythonCompletion.test.js.map +1 -0
- package/dist/test/providers.test.d.ts +2 -0
- package/dist/test/providers.test.d.ts.map +1 -0
- package/dist/test/providers.test.js +883 -0
- package/dist/test/providers.test.js.map +1 -0
- package/dist/test/providers.vertex.test.d.ts +2 -0
- package/dist/test/providers.vertex.test.d.ts.map +1 -0
- package/dist/test/providers.vertex.test.js +153 -0
- package/dist/test/providers.vertex.test.js.map +1 -0
- package/dist/test/pythonWrapper.test.d.ts +2 -0
- package/dist/test/pythonWrapper.test.d.ts.map +1 -0
- package/dist/test/pythonWrapper.test.js +65 -0
- package/dist/test/pythonWrapper.test.js.map +1 -0
- package/dist/test/redteam/plugins/base.test.d.ts +2 -0
- package/dist/test/redteam/plugins/base.test.d.ts.map +1 -0
- package/dist/test/redteam/plugins/base.test.js +149 -0
- package/dist/test/redteam/plugins/base.test.js.map +1 -0
- package/dist/test/redteam/purpose.test.d.ts +2 -0
- package/dist/test/redteam/purpose.test.d.ts.map +1 -0
- package/dist/test/redteam/purpose.test.js +37 -0
- package/dist/test/redteam/purpose.test.js.map +1 -0
- package/dist/test/redteam/types.test.d.ts +2 -0
- package/dist/test/redteam/types.test.d.ts.map +1 -0
- package/dist/test/redteam/types.test.js +325 -0
- package/dist/test/redteam/types.test.js.map +1 -0
- package/dist/test/redteam/util.test.d.ts +2 -0
- package/dist/test/redteam/util.test.d.ts.map +1 -0
- package/dist/test/redteam/util.test.js +99 -0
- package/dist/test/redteam/util.test.js.map +1 -0
- package/dist/test/telemetry.test.d.ts +2 -0
- package/dist/test/telemetry.test.d.ts.map +1 -0
- package/dist/test/telemetry.test.js +68 -0
- package/dist/test/telemetry.test.js.map +1 -0
- package/dist/test/testCases.test.d.ts +2 -0
- package/dist/test/testCases.test.d.ts.map +1 -0
- package/dist/test/testCases.test.js +362 -0
- package/dist/test/testCases.test.js.map +1 -0
- package/dist/test/updates.test.d.ts +2 -0
- package/dist/test/updates.test.d.ts.map +1 -0
- package/dist/test/updates.test.js +63 -0
- package/dist/test/updates.test.js.map +1 -0
- package/dist/test/util.templates.test.d.ts +2 -0
- package/dist/test/util.templates.test.d.ts.map +1 -0
- package/dist/test/util.templates.test.js +75 -0
- package/dist/test/util.templates.test.js.map +1 -0
- package/dist/test/util.test.d.ts +2 -0
- package/dist/test/util.test.d.ts.map +1 -0
- package/dist/test/util.test.js +661 -0
- package/dist/test/util.test.js.map +1 -0
- package/dist/test/utils.d.ts +6 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +16 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +14 -8
- package/dist/src/database.js.map +0 -1
- package/dist/src/redteam/methods/injections.d.ts.map +0 -1
- package/dist/src/redteam/methods/injections.js.map +0 -1
- package/dist/src/redteam/methods/iterative.d.ts.map +0 -1
- package/dist/src/redteam/methods/iterative.js.map +0 -1
- package/dist/src/types.js.map +0 -1
- package/dist/src/web/nextui/_next/static/chunks/163-e65e0f7f442a0c72.js +0 -6
- package/dist/src/web/nextui/_next/static/chunks/180-46db19289d856800.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/304-9d57a2251034b801.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/322-4a0fc9b0508f47e8.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/339-db5bd05e24dde905.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/374-d40afe599198abd3.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/378-e22c8aeb8e031fad.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/448-4da3bf74eae4996a.js +0 -97
- package/dist/src/web/nextui/_next/static/chunks/53-fae6e50ace6c83a1.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/578-8efe57f906f7573c.js +0 -44
- package/dist/src/web/nextui/_next/static/chunks/620-7a5a7bf6e1fe49e5.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/737-538f50dc31cc8c49.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/905-0da344cee75690e7.js +0 -32
- package/dist/src/web/nextui/_next/static/chunks/932-75585b3be8ce494d.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/973-ffe3726c956d08ef.js +0 -2
- package/dist/src/web/nextui/_next/static/chunks/995-803c74b81e7bf6cd.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-2e2c0c725127ea2d.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-ccdb1f6890601666.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-642db4f4a8e8ba40.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-ce320e6d1e6d1d23.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/page-32eaa14d2384c5b0.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/layout-4282b1d33566e258.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/progress/page-462526776efd6fd6.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-0ae78bc0bf7c56bc.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/report/page-e4f7851d41eb0f92.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6cde750ec428cd75.js +0 -1
- package/dist/src/web/nextui/_next/static/css/35ab7ce8025438b0.css +0 -1
- package/dist/src/web/nextui/_next/static/css/5bd2f45de1f3ba83.css +0 -1
- package/dist/src/web/nextui/_next/static/css/94b771e23fc5d5f5.css +0 -1
- package/dist/src/web/nextui/_next/static/css/dab5d695b3657d59.css +0 -1
- /package/dist/src/redteam/{methods → strategies}/injections.d.ts +0 -0
- /package/dist/src/redteam/{methods → strategies}/iterative.d.ts +0 -0
- /package/dist/src/redteam/{methods → strategies}/iterative.js +0 -0
- /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_buildManifest.js +0 -0
- /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../src/prompts/utils");
|
|
4
|
+
jest.mock('fs', () => ({
|
|
5
|
+
statSync: jest.fn(jest.requireActual('fs').statSync),
|
|
6
|
+
}));
|
|
7
|
+
jest.mock('glob', () => ({
|
|
8
|
+
globSync: jest.fn(jest.requireActual('glob').globSync),
|
|
9
|
+
}));
|
|
10
|
+
describe('maybeFilePath', () => {
|
|
11
|
+
it('should return true for valid file paths', () => {
|
|
12
|
+
expect((0, utils_1.maybeFilePath)('C:\\path\\to\\file.txt')).toBe(true);
|
|
13
|
+
expect((0, utils_1.maybeFilePath)('file.*')).toBe(true);
|
|
14
|
+
expect((0, utils_1.maybeFilePath)('filename.ext')).toBe(true);
|
|
15
|
+
expect((0, utils_1.maybeFilePath)('path/to/file.txt')).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it('should return false for strings with new lines', () => {
|
|
18
|
+
expect((0, utils_1.maybeFilePath)('path/to\nfile.txt')).toBe(false);
|
|
19
|
+
expect((0, utils_1.maybeFilePath)('file\nname.ext')).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
it('should return false for strings with "portkey://"', () => {
|
|
22
|
+
expect((0, utils_1.maybeFilePath)('portkey://path/to/file')).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('should return false for strings with "langfuse://"', () => {
|
|
25
|
+
expect((0, utils_1.maybeFilePath)('langfuse://path/to/file')).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
it('should return false for strings without file path indicators', () => {
|
|
28
|
+
expect((0, utils_1.maybeFilePath)('anotherstring')).toBe(false);
|
|
29
|
+
expect((0, utils_1.maybeFilePath)('justastring')).toBe(false);
|
|
30
|
+
expect((0, utils_1.maybeFilePath)('stringwith.dotbutnotfile')).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
it('should return true for strings with file:// prefix', () => {
|
|
33
|
+
expect((0, utils_1.maybeFilePath)('file://path/to/file.txt')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('should return true for strings with wildcard character', () => {
|
|
36
|
+
expect((0, utils_1.maybeFilePath)('*.txt')).toBe(true);
|
|
37
|
+
expect((0, utils_1.maybeFilePath)('path/to/*.txt')).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
it('should return true for strings with file extension at the third or fourth last position', () => {
|
|
40
|
+
expect((0, utils_1.maybeFilePath)('file.ext')).toBe(true);
|
|
41
|
+
expect((0, utils_1.maybeFilePath)('file.name.ext')).toBe(true);
|
|
42
|
+
expect((0, utils_1.maybeFilePath)('filename.e')).toBe(false);
|
|
43
|
+
expect((0, utils_1.maybeFilePath)('filename.ex')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
it('should work for files that end with specific allowed extensions', () => {
|
|
46
|
+
expect((0, utils_1.maybeFilePath)('filename.cjs')).toBe(true);
|
|
47
|
+
expect((0, utils_1.maybeFilePath)('filename.js')).toBe(true);
|
|
48
|
+
expect((0, utils_1.maybeFilePath)('filename.js:functionName')).toBe(true);
|
|
49
|
+
expect((0, utils_1.maybeFilePath)('filename.json')).toBe(true);
|
|
50
|
+
expect((0, utils_1.maybeFilePath)('filename.jsonl')).toBe(true);
|
|
51
|
+
expect((0, utils_1.maybeFilePath)('filename.mjs')).toBe(true);
|
|
52
|
+
expect((0, utils_1.maybeFilePath)('filename.py')).toBe(true);
|
|
53
|
+
expect((0, utils_1.maybeFilePath)('filename.py:functionName')).toBe(true);
|
|
54
|
+
expect((0, utils_1.maybeFilePath)('filename.txt')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
// Additional tests
|
|
57
|
+
it('should return false for empty strings', () => {
|
|
58
|
+
expect((0, utils_1.maybeFilePath)('')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
it('should return false for whitespace strings', () => {
|
|
61
|
+
expect((0, utils_1.maybeFilePath)(' ')).toBe(false);
|
|
62
|
+
expect((0, utils_1.maybeFilePath)('\t')).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
it('should return false for non-string inputs', () => {
|
|
65
|
+
expect(() => (0, utils_1.maybeFilePath)(123)).toThrow('Invalid input: 123');
|
|
66
|
+
expect(() => (0, utils_1.maybeFilePath)({})).toThrow('Invalid input: {}');
|
|
67
|
+
expect(() => (0, utils_1.maybeFilePath)([])).toThrow('Invalid input: []');
|
|
68
|
+
});
|
|
69
|
+
it('should return false for strings with invalid and valid indicators mixed', () => {
|
|
70
|
+
expect((0, utils_1.maybeFilePath)('file://path/to\nfile.txt')).toBe(false);
|
|
71
|
+
expect((0, utils_1.maybeFilePath)('path/to/file.txtportkey://')).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
it('should return true for very long valid file paths', () => {
|
|
74
|
+
const longPath = 'a/'.repeat(100) + 'file.txt';
|
|
75
|
+
expect((0, utils_1.maybeFilePath)(longPath)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('should return false for very long invalid file paths', () => {
|
|
78
|
+
const longInvalidPath = 'a/'.repeat(100) + 'file\n.txt';
|
|
79
|
+
expect((0, utils_1.maybeFilePath)(longInvalidPath)).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
it('should return false for strings ending with a dot', () => {
|
|
82
|
+
expect((0, utils_1.maybeFilePath)('Write a tweet about {{topic}}.')).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('normalizeInput', () => {
|
|
86
|
+
it('rejects invalid input types', () => {
|
|
87
|
+
expect(() => (0, utils_1.normalizeInput)(null)).toThrow('Invalid input prompt: null');
|
|
88
|
+
expect(() => (0, utils_1.normalizeInput)(undefined)).toThrow('Invalid input prompt: undefined');
|
|
89
|
+
expect(() => (0, utils_1.normalizeInput)(1)).toThrow('Invalid input prompt: 1');
|
|
90
|
+
expect(() => (0, utils_1.normalizeInput)(true)).toThrow('Invalid input prompt: true');
|
|
91
|
+
expect(() => (0, utils_1.normalizeInput)(false)).toThrow('Invalid input prompt: false');
|
|
92
|
+
});
|
|
93
|
+
it('rejects empty inputs', () => {
|
|
94
|
+
expect(() => (0, utils_1.normalizeInput)([])).toThrow('Invalid input prompt: []');
|
|
95
|
+
expect(() => (0, utils_1.normalizeInput)({})).toThrow('Invalid input prompt: {}');
|
|
96
|
+
expect(() => (0, utils_1.normalizeInput)('')).toThrow('Invalid input prompt: ""');
|
|
97
|
+
});
|
|
98
|
+
it('returns array with single string when input is a non-empty string', () => {
|
|
99
|
+
expect((0, utils_1.normalizeInput)('valid string')).toEqual([{ raw: 'valid string' }]);
|
|
100
|
+
});
|
|
101
|
+
it('returns input array when input is a non-empty array', () => {
|
|
102
|
+
const inputArray = ['prompt1', { raw: 'prompt2' }];
|
|
103
|
+
expect((0, utils_1.normalizeInput)(inputArray)).toEqual([{ raw: 'prompt1' }, { raw: 'prompt2' }]);
|
|
104
|
+
});
|
|
105
|
+
// NOTE: Legacy mode. This is deprecated and will be removed in a future version.
|
|
106
|
+
it('returns array of prompts when input is an object', () => {
|
|
107
|
+
const inputObject = {
|
|
108
|
+
'prompts1.txt': 'label A',
|
|
109
|
+
'prompts2.txt': 'label B',
|
|
110
|
+
};
|
|
111
|
+
expect((0, utils_1.normalizeInput)(inputObject)).toEqual([
|
|
112
|
+
{
|
|
113
|
+
label: 'label A',
|
|
114
|
+
raw: 'prompts1.txt',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
label: 'label B',
|
|
118
|
+
raw: 'prompts2.txt',
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=prompts.utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.utils.test.js","sourceRoot":"","sources":["../../test/prompts.utils.test.ts"],"names":[],"mappings":";;AAAA,gDAAqE;AAErE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;CACvD,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,IAAA,qBAAa,EAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAA,qBAAa,EAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,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iFAAiF;IACjF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,WAAW,GAAG;YAClB,cAAc,EAAE,SAAS;YACzB,cAAc,EAAE,SAAS;SAC1B,CAAC;QACF,MAAM,CAAC,IAAA,sBAAc,EAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;YAC1C;gBACE,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,cAAc;aACpB;YACD;gBACE,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,cAAc;aACpB;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.anthropic.test.d.ts","sourceRoot":"","sources":["../../test/providers.anthropic.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dedent_1 = __importDefault(require("dedent"));
|
|
7
|
+
const cache_1 = require("../src/cache");
|
|
8
|
+
const anthropic_1 = require("../src/providers/anthropic");
|
|
9
|
+
jest.mock('proxy-agent', () => ({
|
|
10
|
+
ProxyAgent: jest.fn().mockImplementation(() => ({})),
|
|
11
|
+
}));
|
|
12
|
+
describe('Anthropic', () => {
|
|
13
|
+
afterEach(async () => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
await (0, cache_1.clearCache)();
|
|
16
|
+
});
|
|
17
|
+
describe('AnthropicMessagesProvider callApi', () => {
|
|
18
|
+
const tools = [
|
|
19
|
+
{
|
|
20
|
+
name: 'get_weather',
|
|
21
|
+
description: 'Get the current weather in a given location',
|
|
22
|
+
input_schema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
location: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The city and state, e.g. San Francisco, CA',
|
|
28
|
+
},
|
|
29
|
+
unit: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
enum: ['celsius', 'fahrenheit'],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ['location'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229', {
|
|
39
|
+
config: { tools },
|
|
40
|
+
});
|
|
41
|
+
it('should use cache by default for ToolUse requests', async () => {
|
|
42
|
+
jest
|
|
43
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
44
|
+
.mockImplementation()
|
|
45
|
+
.mockResolvedValue({
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'tool_use',
|
|
53
|
+
id: 'toolu_01A09q90qw90lq917835lq9',
|
|
54
|
+
name: 'get_weather',
|
|
55
|
+
input: { location: 'San Francisco, CA', unit: 'celsius' },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
60
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
|
|
61
|
+
expect(provider.anthropic.messages.create).toHaveBeenNthCalledWith(1, {
|
|
62
|
+
model: 'claude-3-opus-20240229',
|
|
63
|
+
max_tokens: 1024,
|
|
64
|
+
messages: [
|
|
65
|
+
{
|
|
66
|
+
role: 'user',
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
text: 'What is the forecast in San Francisco?',
|
|
70
|
+
type: 'text',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
tools,
|
|
76
|
+
temperature: 0,
|
|
77
|
+
stream: false,
|
|
78
|
+
});
|
|
79
|
+
expect(result).toMatchObject({
|
|
80
|
+
cost: undefined,
|
|
81
|
+
output: (0, dedent_1.default) `<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>
|
|
82
|
+
|
|
83
|
+
{"type":"tool_use","id":"toolu_01A09q90qw90lq917835lq9","name":"get_weather","input":{"location":"San Francisco, CA","unit":"celsius"}}`,
|
|
84
|
+
tokenUsage: {},
|
|
85
|
+
});
|
|
86
|
+
const resultFromCache = await provider.callApi('What is the forecast in San Francisco?');
|
|
87
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(result).toMatchObject(resultFromCache);
|
|
89
|
+
});
|
|
90
|
+
it('should pass the tool choice if specified', async () => {
|
|
91
|
+
const toolChoice = {
|
|
92
|
+
name: 'get_weather',
|
|
93
|
+
type: 'tool',
|
|
94
|
+
};
|
|
95
|
+
provider.config.tool_choice = toolChoice;
|
|
96
|
+
jest
|
|
97
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
98
|
+
.mockImplementation()
|
|
99
|
+
.mockResolvedValue({
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
type: 'tool_use',
|
|
107
|
+
id: 'toolu_01A09q90qw90lq917835lq9',
|
|
108
|
+
name: 'get_weather',
|
|
109
|
+
input: { location: 'San Francisco, CA', unit: 'celsius' },
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
114
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
|
|
115
|
+
expect(provider.anthropic.messages.create).toHaveBeenNthCalledWith(1, {
|
|
116
|
+
model: 'claude-3-opus-20240229',
|
|
117
|
+
max_tokens: 1024,
|
|
118
|
+
messages: [
|
|
119
|
+
{
|
|
120
|
+
role: 'user',
|
|
121
|
+
content: [
|
|
122
|
+
{
|
|
123
|
+
text: 'What is the forecast in San Francisco?',
|
|
124
|
+
type: 'text',
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
tools,
|
|
130
|
+
tool_choice: toolChoice,
|
|
131
|
+
temperature: 0,
|
|
132
|
+
stream: false,
|
|
133
|
+
});
|
|
134
|
+
provider.config.tool_choice = undefined;
|
|
135
|
+
});
|
|
136
|
+
it('should not use cache if caching is disabled for ToolUse requests', async () => {
|
|
137
|
+
jest
|
|
138
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
139
|
+
.mockImplementation()
|
|
140
|
+
.mockResolvedValue({
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: 'text',
|
|
144
|
+
text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: 'tool_use',
|
|
148
|
+
id: 'toolu_01A09q90qw90lq917835lq9',
|
|
149
|
+
name: 'get_weather',
|
|
150
|
+
input: { location: 'San Francisco, CA', unit: 'celsius' },
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
(0, cache_1.disableCache)();
|
|
155
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
156
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(result).toMatchObject({
|
|
158
|
+
output: (0, dedent_1.default) `<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>
|
|
159
|
+
|
|
160
|
+
{"type":"tool_use","id":"toolu_01A09q90qw90lq917835lq9","name":"get_weather","input":{"location":"San Francisco, CA","unit":"celsius"}}`,
|
|
161
|
+
tokenUsage: {},
|
|
162
|
+
});
|
|
163
|
+
await provider.callApi('What is the forecast in San Francisco?');
|
|
164
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(2);
|
|
165
|
+
(0, cache_1.enableCache)();
|
|
166
|
+
});
|
|
167
|
+
it('should return cached response for legacy caching behavior', async () => {
|
|
168
|
+
jest
|
|
169
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
170
|
+
.mockImplementation()
|
|
171
|
+
.mockResolvedValue({
|
|
172
|
+
content: [],
|
|
173
|
+
});
|
|
174
|
+
(0, cache_1.getCache)().set('anthropic:{"model":"claude-3-opus-20240229","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"text","text":"What is the forecast in San Francisco?"}]}],"stream":false,"temperature":0,"tools":[{"name":"get_weather","description":"Get the current weather in a given location","input_schema":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}]}', 'Test output');
|
|
175
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
176
|
+
expect(result).toMatchObject({
|
|
177
|
+
output: 'Test output',
|
|
178
|
+
tokenUsage: {},
|
|
179
|
+
});
|
|
180
|
+
expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(0);
|
|
181
|
+
});
|
|
182
|
+
it('should handle API call error', async () => {
|
|
183
|
+
const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229');
|
|
184
|
+
jest
|
|
185
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
186
|
+
.mockImplementation()
|
|
187
|
+
.mockRejectedValue(new Error('API call failed'));
|
|
188
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
189
|
+
expect(result).toMatchObject({
|
|
190
|
+
error: 'API call error: Error: API call failed',
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
it('should return token usage and cost', async () => {
|
|
194
|
+
const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229', {
|
|
195
|
+
config: { max_tokens: 100, temperature: 0.5, cost: 0.015 },
|
|
196
|
+
});
|
|
197
|
+
jest
|
|
198
|
+
.spyOn(provider.anthropic.messages, 'create')
|
|
199
|
+
.mockImplementation()
|
|
200
|
+
.mockResolvedValue({
|
|
201
|
+
content: [{ type: 'text', text: 'Test output' }],
|
|
202
|
+
usage: { input_tokens: 50, output_tokens: 50 },
|
|
203
|
+
});
|
|
204
|
+
const result = await provider.callApi('What is the forecast in San Francisco?');
|
|
205
|
+
expect(result).toMatchObject({
|
|
206
|
+
output: 'Test output',
|
|
207
|
+
tokenUsage: { total: 100, prompt: 50, completion: 50 },
|
|
208
|
+
cost: 1.5,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('AnthropicLlmRubricProvider', () => {
|
|
213
|
+
let provider;
|
|
214
|
+
beforeEach(() => {
|
|
215
|
+
provider = new anthropic_1.AnthropicLlmRubricProvider('claude-3-5-sonnet-20240620');
|
|
216
|
+
});
|
|
217
|
+
it('should initialize with forced tool configuration', () => {
|
|
218
|
+
expect(provider.modelName).toBe('claude-3-5-sonnet-20240620');
|
|
219
|
+
expect(provider.config.tool_choice).toEqual({ type: 'tool', name: 'grade_output' });
|
|
220
|
+
});
|
|
221
|
+
it('should call API and parse the result correctly', async () => {
|
|
222
|
+
const mockApiResponse = {
|
|
223
|
+
output: JSON.stringify({
|
|
224
|
+
type: 'tool_use',
|
|
225
|
+
id: 'test-id',
|
|
226
|
+
name: 'grade_output',
|
|
227
|
+
input: {
|
|
228
|
+
pass: true,
|
|
229
|
+
score: 0.85,
|
|
230
|
+
reason: 'The output meets the criteria.',
|
|
231
|
+
},
|
|
232
|
+
}),
|
|
233
|
+
};
|
|
234
|
+
jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
|
|
235
|
+
const result = await provider.callApi('Test prompt');
|
|
236
|
+
expect(result).toEqual({
|
|
237
|
+
output: {
|
|
238
|
+
pass: true,
|
|
239
|
+
score: 0.85,
|
|
240
|
+
reason: 'The output meets the criteria.',
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
it('should handle non-string API response', async () => {
|
|
245
|
+
const mockApiResponse = {
|
|
246
|
+
output: { confession: 'I am not a string' },
|
|
247
|
+
};
|
|
248
|
+
jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
|
|
249
|
+
const result = await provider.callApi('Test prompt');
|
|
250
|
+
expect(result.error).toContain('Anthropic LLM rubric grader - malformed non-string output');
|
|
251
|
+
});
|
|
252
|
+
it('should handle malformed API response', async () => {
|
|
253
|
+
const mockApiResponse = {
|
|
254
|
+
output: 'Invalid JSON',
|
|
255
|
+
};
|
|
256
|
+
jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
|
|
257
|
+
const result = await provider.callApi('Test prompt');
|
|
258
|
+
expect(result.error).toContain('Anthropic LLM rubric grader - invalid JSON');
|
|
259
|
+
});
|
|
260
|
+
it('should handle API errors', async () => {
|
|
261
|
+
const mockError = new Error('API Error');
|
|
262
|
+
jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockRejectedValue(mockError);
|
|
263
|
+
await expect(provider.callApi('Test prompt')).rejects.toThrow('API Error');
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
describe('AnthropicCompletionProvider callApi', () => {
|
|
267
|
+
it('should return output for default behavior', async () => {
|
|
268
|
+
const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
|
|
269
|
+
jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
|
|
270
|
+
id: 'test-id',
|
|
271
|
+
model: 'claude-1',
|
|
272
|
+
stop_reason: 'stop_sequence',
|
|
273
|
+
type: 'completion',
|
|
274
|
+
completion: 'Test output',
|
|
275
|
+
});
|
|
276
|
+
const result = await provider.callApi('Test prompt');
|
|
277
|
+
expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
|
|
278
|
+
expect(result).toMatchObject({
|
|
279
|
+
output: 'Test output',
|
|
280
|
+
tokenUsage: {},
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
it('should return cached output with caching enabled', async () => {
|
|
284
|
+
const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
|
|
285
|
+
jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
|
|
286
|
+
id: 'test-id',
|
|
287
|
+
model: 'claude-1',
|
|
288
|
+
stop_reason: 'stop_sequence',
|
|
289
|
+
type: 'completion',
|
|
290
|
+
completion: 'Test output',
|
|
291
|
+
});
|
|
292
|
+
const result = await provider.callApi('Test prompt');
|
|
293
|
+
expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
|
|
294
|
+
expect(result).toMatchObject({
|
|
295
|
+
output: 'Test output',
|
|
296
|
+
tokenUsage: {},
|
|
297
|
+
});
|
|
298
|
+
jest.mocked(provider.anthropic.completions.create).mockClear();
|
|
299
|
+
const cachedResult = await provider.callApi('Test prompt');
|
|
300
|
+
expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(0);
|
|
301
|
+
expect(cachedResult).toMatchObject({
|
|
302
|
+
output: 'Test output',
|
|
303
|
+
tokenUsage: {},
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
it('should return fresh output with caching disabled', async () => {
|
|
307
|
+
const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
|
|
308
|
+
jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
|
|
309
|
+
id: 'test-id',
|
|
310
|
+
model: 'claude-1',
|
|
311
|
+
stop_reason: 'stop_sequence',
|
|
312
|
+
type: 'completion',
|
|
313
|
+
completion: 'Test output',
|
|
314
|
+
});
|
|
315
|
+
const result = await provider.callApi('Test prompt');
|
|
316
|
+
expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
|
|
317
|
+
expect(result).toMatchObject({
|
|
318
|
+
output: 'Test output',
|
|
319
|
+
tokenUsage: {},
|
|
320
|
+
});
|
|
321
|
+
jest.mocked(provider.anthropic.completions.create).mockClear();
|
|
322
|
+
(0, cache_1.disableCache)();
|
|
323
|
+
const freshResult = await provider.callApi('Test prompt');
|
|
324
|
+
expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
|
|
325
|
+
expect(freshResult).toMatchObject({
|
|
326
|
+
output: 'Test output',
|
|
327
|
+
tokenUsage: {},
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
it('should handle API call error', async () => {
|
|
331
|
+
const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
|
|
332
|
+
jest
|
|
333
|
+
.spyOn(provider.anthropic.completions, 'create')
|
|
334
|
+
.mockImplementation()
|
|
335
|
+
.mockRejectedValue(new Error('API call failed'));
|
|
336
|
+
const result = await provider.callApi('Test prompt');
|
|
337
|
+
expect(result).toMatchObject({
|
|
338
|
+
error: 'API call error: Error: API call failed',
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
describe('calculateCost', () => {
|
|
343
|
+
it('should calculate cost for valid input and output tokens', () => {
|
|
344
|
+
const cost = (0, anthropic_1.calculateCost)('claude-3-opus-20240229', { cost: 0.015 }, 100, 200);
|
|
345
|
+
expect(cost).toBe(4.5); // (0.015 * 100) + (0.075 * 200)
|
|
346
|
+
});
|
|
347
|
+
it('should return undefined for missing model', () => {
|
|
348
|
+
const cost = (0, anthropic_1.calculateCost)('non-existent-model', { cost: 0.015 });
|
|
349
|
+
expect(cost).toBeUndefined();
|
|
350
|
+
});
|
|
351
|
+
it('should return undefined for missing tokens', () => {
|
|
352
|
+
const cost = (0, anthropic_1.calculateCost)('claude-3-opus-20240229', { cost: 0.015 });
|
|
353
|
+
expect(cost).toBeUndefined();
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
describe('outputFromMessage', () => {
|
|
357
|
+
it('should return an empty string for empty content array', () => {
|
|
358
|
+
const message = {
|
|
359
|
+
content: [],
|
|
360
|
+
id: '',
|
|
361
|
+
model: '',
|
|
362
|
+
role: 'assistant',
|
|
363
|
+
stop_reason: null,
|
|
364
|
+
stop_sequence: null,
|
|
365
|
+
type: 'message',
|
|
366
|
+
usage: {
|
|
367
|
+
input_tokens: 0,
|
|
368
|
+
output_tokens: 0,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
const result = (0, anthropic_1.outputFromMessage)(message);
|
|
372
|
+
expect(result).toBe('');
|
|
373
|
+
});
|
|
374
|
+
it('should return text from a single text block', () => {
|
|
375
|
+
const message = {
|
|
376
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
377
|
+
id: '',
|
|
378
|
+
model: '',
|
|
379
|
+
role: 'assistant',
|
|
380
|
+
stop_reason: null,
|
|
381
|
+
stop_sequence: null,
|
|
382
|
+
type: 'message',
|
|
383
|
+
usage: {
|
|
384
|
+
input_tokens: 0,
|
|
385
|
+
output_tokens: 0,
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
const result = (0, anthropic_1.outputFromMessage)(message);
|
|
389
|
+
expect(result).toBe('Hello');
|
|
390
|
+
});
|
|
391
|
+
it('should concatenate text blocks without tool_use blocks', () => {
|
|
392
|
+
const message = {
|
|
393
|
+
content: [
|
|
394
|
+
{ type: 'text', text: 'Hello' },
|
|
395
|
+
{ type: 'text', text: 'World' },
|
|
396
|
+
],
|
|
397
|
+
id: '',
|
|
398
|
+
model: '',
|
|
399
|
+
role: 'assistant',
|
|
400
|
+
stop_reason: null,
|
|
401
|
+
stop_sequence: null,
|
|
402
|
+
type: 'message',
|
|
403
|
+
usage: {
|
|
404
|
+
input_tokens: 0,
|
|
405
|
+
output_tokens: 0,
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
const result = (0, anthropic_1.outputFromMessage)(message);
|
|
409
|
+
expect(result).toBe('Hello\n\nWorld');
|
|
410
|
+
});
|
|
411
|
+
it('should handle content with tool_use blocks', () => {
|
|
412
|
+
const message = {
|
|
413
|
+
content: [
|
|
414
|
+
{
|
|
415
|
+
type: 'tool_use',
|
|
416
|
+
id: 'tool1',
|
|
417
|
+
name: 'get_weather',
|
|
418
|
+
input: { location: 'San Francisco, CA' },
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
type: 'tool_use',
|
|
422
|
+
id: 'tool2',
|
|
423
|
+
name: 'get_time',
|
|
424
|
+
input: { location: 'New York, NY' },
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
id: '',
|
|
428
|
+
model: '',
|
|
429
|
+
role: 'assistant',
|
|
430
|
+
stop_reason: null,
|
|
431
|
+
stop_sequence: null,
|
|
432
|
+
type: 'message',
|
|
433
|
+
usage: {
|
|
434
|
+
input_tokens: 0,
|
|
435
|
+
output_tokens: 0,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
const result = (0, anthropic_1.outputFromMessage)(message);
|
|
439
|
+
expect(result).toBe('{"type":"tool_use","id":"tool1","name":"get_weather","input":{"location":"San Francisco, CA"}}\n\n{"type":"tool_use","id":"tool2","name":"get_time","input":{"location":"New York, NY"}}');
|
|
440
|
+
});
|
|
441
|
+
it('should concatenate text and tool_use blocks as JSON strings', () => {
|
|
442
|
+
const message = {
|
|
443
|
+
content: [
|
|
444
|
+
{ type: 'text', text: 'Hello' },
|
|
445
|
+
{
|
|
446
|
+
type: 'tool_use',
|
|
447
|
+
id: 'tool1',
|
|
448
|
+
name: 'get_weather',
|
|
449
|
+
input: { location: 'San Francisco, CA' },
|
|
450
|
+
},
|
|
451
|
+
{ type: 'text', text: 'World' },
|
|
452
|
+
],
|
|
453
|
+
id: '',
|
|
454
|
+
model: '',
|
|
455
|
+
role: 'assistant',
|
|
456
|
+
stop_reason: null,
|
|
457
|
+
stop_sequence: null,
|
|
458
|
+
type: 'message',
|
|
459
|
+
usage: {
|
|
460
|
+
input_tokens: 0,
|
|
461
|
+
output_tokens: 0,
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
const result = (0, anthropic_1.outputFromMessage)(message);
|
|
465
|
+
expect(result).toBe('Hello\n\n{"type":"tool_use","id":"tool1","name":"get_weather","input":{"location":"San Francisco, CA"}}\n\nWorld');
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
describe('parseMessages', () => {
|
|
469
|
+
it('should parse messages with user and assistant roles', () => {
|
|
470
|
+
const inputMessages = (0, dedent_1.default) `user: What is the weather?
|
|
471
|
+
assistant: The weather is sunny.`;
|
|
472
|
+
const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
|
|
473
|
+
expect(system).toBeUndefined();
|
|
474
|
+
expect(extractedMessages).toMatchObject([
|
|
475
|
+
{
|
|
476
|
+
role: 'user',
|
|
477
|
+
content: [
|
|
478
|
+
{
|
|
479
|
+
type: 'text',
|
|
480
|
+
text: (0, dedent_1.default) `user: What is the weather?
|
|
481
|
+
assistant: The weather is sunny.`,
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
},
|
|
485
|
+
]);
|
|
486
|
+
});
|
|
487
|
+
it('should handle system messages', () => {
|
|
488
|
+
const inputMessages = (0, dedent_1.default) `system: This is a system message.
|
|
489
|
+
user: What is the weather?
|
|
490
|
+
assistant: The weather is sunny.`;
|
|
491
|
+
const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
|
|
492
|
+
expect(system).toBeUndefined();
|
|
493
|
+
expect(extractedMessages).toMatchObject([
|
|
494
|
+
{
|
|
495
|
+
role: 'user',
|
|
496
|
+
content: [
|
|
497
|
+
{
|
|
498
|
+
type: 'text',
|
|
499
|
+
text: (0, dedent_1.default) `system: This is a system message.
|
|
500
|
+
user: What is the weather?
|
|
501
|
+
assistant: The weather is sunny.`,
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
]);
|
|
506
|
+
});
|
|
507
|
+
it('should handle empty input', () => {
|
|
508
|
+
const inputMessages = '';
|
|
509
|
+
const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
|
|
510
|
+
expect(system).toBeUndefined();
|
|
511
|
+
expect(extractedMessages).toMatchObject([
|
|
512
|
+
{
|
|
513
|
+
role: 'user',
|
|
514
|
+
content: [{ type: 'text', text: '' }],
|
|
515
|
+
},
|
|
516
|
+
]);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
//# sourceMappingURL=providers.anthropic.test.js.map
|