0d3cb498a3
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
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
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) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
209 lines
6.6 KiB
TypeScript
209 lines
6.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { clearCache } from '../../src/cache';
|
|
import logger from '../../src/logger';
|
|
import {
|
|
AlibabaChatCompletionProvider,
|
|
AlibabaEmbeddingProvider,
|
|
} from '../../src/providers/alibaba';
|
|
import { OpenAiChatCompletionProvider } from '../../src/providers/openai/chat';
|
|
import { OpenAiEmbeddingProvider } from '../../src/providers/openai/embedding';
|
|
|
|
import type { ProviderOptions } from '../../src/types/index';
|
|
|
|
vi.mock('../../src/logger', () => ({
|
|
default: {
|
|
debug: vi.fn(),
|
|
error: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
},
|
|
}));
|
|
vi.mock('../../src/providers/openai/chat', async (importOriginal) => {
|
|
return {
|
|
...(await importOriginal()),
|
|
OpenAiChatCompletionProvider: vi.fn(),
|
|
};
|
|
});
|
|
vi.mock('../../src/providers/openai/completion', async (importOriginal) => {
|
|
return {
|
|
...(await importOriginal()),
|
|
OpenAiCompletionProvider: vi.fn(),
|
|
};
|
|
});
|
|
vi.mock('../../src/providers/openai/embedding', async (importOriginal) => {
|
|
return {
|
|
...(await importOriginal()),
|
|
OpenAiEmbeddingProvider: vi.fn(),
|
|
};
|
|
});
|
|
|
|
describe('Alibaba Cloud Provider', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await clearCache();
|
|
});
|
|
|
|
describe('AlibabaChatCompletionProvider', () => {
|
|
it('should create provider for flagship models', () => {
|
|
const provider = new AlibabaChatCompletionProvider('qwen-max', {});
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
|
|
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
|
|
'qwen-max',
|
|
expect.objectContaining({
|
|
config: expect.objectContaining({
|
|
apiBaseUrl: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
|
|
apiKeyEnvar: 'DASHSCOPE_API_KEY',
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('should create provider for visual language models', () => {
|
|
const provider = new AlibabaChatCompletionProvider('qwen-vl-max', {});
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
|
|
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
|
|
'qwen-vl-max',
|
|
expect.objectContaining({
|
|
config: expect.objectContaining({
|
|
apiBaseUrl: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
|
|
apiKeyEnvar: 'DASHSCOPE_API_KEY',
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it.each([
|
|
'qwen3.6-plus',
|
|
'qwen3.5-flash',
|
|
'qwen3-coder-next',
|
|
'deepseek-v3.2',
|
|
])('should recognize refreshed model id %s', (modelName) => {
|
|
new AlibabaChatCompletionProvider(modelName, {});
|
|
|
|
expect(logger.warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should throw error when no model specified', () => {
|
|
expect(() => new AlibabaChatCompletionProvider('')).toThrow('Alibaba modelName is required');
|
|
});
|
|
|
|
it('should warn but not throw for unknown model', () => {
|
|
// Unknown models now only warn, they don't throw errors
|
|
const provider = new AlibabaChatCompletionProvider('unknown-model', {});
|
|
expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
|
|
expect(logger.warn).toHaveBeenCalledWith(
|
|
expect.stringContaining('Unknown Alibaba Cloud model: unknown-model.'),
|
|
);
|
|
});
|
|
|
|
it('should pass through environment variables', () => {
|
|
const provider = new AlibabaChatCompletionProvider('qwen-max', {
|
|
env: {
|
|
DASHSCOPE_API_KEY: 'test-key',
|
|
},
|
|
} as ProviderOptions);
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
|
|
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
|
|
'qwen-max',
|
|
expect.objectContaining({
|
|
env: expect.objectContaining({
|
|
DASHSCOPE_API_KEY: 'test-key',
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('should allow custom API base URL', () => {
|
|
const customBaseUrl = 'https://dashscope.aliyuncs.com/api/v1';
|
|
const provider = new AlibabaChatCompletionProvider('qwen-max', {
|
|
config: {
|
|
apiBaseUrl: customBaseUrl,
|
|
},
|
|
});
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
|
|
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
|
|
'qwen-max',
|
|
expect.objectContaining({
|
|
config: expect.objectContaining({
|
|
apiBaseUrl: customBaseUrl,
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('AlibabaEmbeddingProvider', () => {
|
|
it('should create provider for embedding models', () => {
|
|
const provider = new AlibabaEmbeddingProvider('text-embedding-v3', {});
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
|
|
expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith(
|
|
'text-embedding-v3',
|
|
expect.objectContaining({
|
|
config: expect.objectContaining({
|
|
apiBaseUrl: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
|
|
apiKeyEnvar: 'DASHSCOPE_API_KEY',
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('should throw error when no model specified', () => {
|
|
expect(() => new AlibabaEmbeddingProvider('')).toThrow('Alibaba modelName is required');
|
|
});
|
|
|
|
it('should warn but not throw for unknown model', () => {
|
|
// Unknown models now only warn, they don't throw errors
|
|
const provider = new AlibabaEmbeddingProvider('unknown-model', {});
|
|
expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
|
|
expect(logger.warn).toHaveBeenCalledWith(
|
|
expect.stringContaining('Unknown Alibaba Cloud model: unknown-model.'),
|
|
);
|
|
});
|
|
|
|
it('should pass through environment variables', () => {
|
|
const provider = new AlibabaEmbeddingProvider('text-embedding-v3', {
|
|
env: {
|
|
DASHSCOPE_API_KEY: 'test-key',
|
|
},
|
|
} as ProviderOptions);
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
|
|
expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith(
|
|
'text-embedding-v3',
|
|
expect.objectContaining({
|
|
env: expect.objectContaining({
|
|
DASHSCOPE_API_KEY: 'test-key',
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('should allow custom API base URL', () => {
|
|
const customBaseUrl = 'https://dashscope.aliyuncs.com/api/v1';
|
|
const provider = new AlibabaEmbeddingProvider('text-embedding-v3', {
|
|
config: {
|
|
apiBaseUrl: customBaseUrl,
|
|
},
|
|
});
|
|
|
|
expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
|
|
expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith(
|
|
'text-embedding-v3',
|
|
expect.objectContaining({
|
|
config: expect.objectContaining({
|
|
apiBaseUrl: customBaseUrl,
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
});
|