Files
wehub-resource-sync 0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

137 lines
3.9 KiB
JavaScript

#!/usr/bin/env node
/**
* Test script for the SageMaker provider.
* Shows how to use the provider with both Llama and Mistral models.
*/
const { ArgumentParser } = require('argparse');
const {
SageMakerCompletionProvider,
SageMakerEmbeddingProvider,
} = require('../../dist/providers/sagemaker');
// Process command line arguments
function parseArgs() {
const parser = new ArgumentParser({
description: 'Test SageMaker provider',
});
parser.add_argument('--endpoint', {
help: 'SageMaker endpoint name',
default: 'your-endpoint-name',
});
parser.add_argument('--region', { help: 'AWS region', default: 'us-west-2' });
parser.add_argument('--model-type', {
help: 'Model type',
choices: ['openai', 'anthropic', 'llama', 'huggingface', 'jumpstart', 'custom'],
default: 'custom',
dest: 'modelType',
});
parser.add_argument('--embedding', {
help: 'Test embedding endpoint',
action: 'store_true',
});
parser.add_argument('--transform', {
help: 'Test transform functionality',
action: 'store_true',
});
parser.add_argument('--transform-file', {
help: 'Path to transform file',
default: 'transform.js',
dest: 'transformFile',
});
parser.add_argument('--response-path', {
help: 'Response path expression',
default: 'json.generated_text',
dest: 'responsePath',
});
const args = parser.parse_args();
return args;
}
async function testSageMaker() {
const args = parseArgs();
console.log(`Testing SageMaker provider with endpoint: ${args.endpoint}`);
console.log(`Region: ${args.region}`);
console.log(`Model type: ${args.modelType}`);
// Test prompt
const prompt = 'Generate a creative name for a coffee shop that specializes in caramel coffee.';
try {
if (args.embedding) {
// Test embedding functionality
console.log('Testing embedding endpoint...');
const provider = new SageMakerEmbeddingProvider(args.endpoint, {
config: {
region: args.region,
modelType: args.modelType,
responseFormat: {
path: args.responsePath,
},
},
transform: args.transform
? args.transformFile.startsWith('file://')
? args.transformFile
: `file://${args.transformFile}`
: undefined,
});
const result = await provider.callEmbeddingApi(prompt);
console.log('Embedding result:');
console.log(`Success: ${!result.error}`);
if (result.error) {
console.error(`Error: ${result.error}`);
} else {
console.log(`Embedding length: ${result.embedding.length}`);
console.log(`First few values: ${result.embedding.slice(0, 5).join(', ')}`);
}
} else {
// Test completion functionality
console.log('Testing completion endpoint...');
const provider = new SageMakerCompletionProvider(args.endpoint, {
config: {
region: args.region,
modelType: args.modelType,
responseFormat: {
path: args.responsePath,
},
},
transform: args.transform
? args.transformFile.startsWith('file://')
? args.transformFile
: `file://${args.transformFile}`
: undefined,
});
const result = await provider.callApi(prompt);
console.log('Completion result:');
console.log(`Success: ${!result.error}`);
if (result.error) {
console.error(`Error: ${result.error}`);
} else {
console.log('Output:');
console.log(result.output);
// Show additional metadata
console.log('\nMetadata:');
console.log(JSON.stringify(result.metadata, null, 2));
// Show token usage
console.log('\nToken usage:');
console.log(JSON.stringify(result.tokenUsage, null, 2));
}
}
} catch (error) {
console.error('Error testing SageMaker provider:');
console.error(error);
}
}
// Run the test
testSageMaker().catch(console.error);