chore: import upstream snapshot with attribution
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
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
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fetchWithCache } from '../../../src/cache';
|
||||
import {
|
||||
createHyperbolicAudioProvider,
|
||||
HyperbolicAudioProvider,
|
||||
} from '../../../src/providers/hyperbolic/audio';
|
||||
import { mockProcessEnv } from '../../util/utils';
|
||||
|
||||
vi.mock('../../../src/cache');
|
||||
|
||||
describe('HyperbolicAudioProvider', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('should create provider with default model', () => {
|
||||
const provider = new HyperbolicAudioProvider('');
|
||||
expect(provider.modelName).toBe('Melo-TTS');
|
||||
});
|
||||
|
||||
it('should create provider with specified model', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo');
|
||||
expect(provider.modelName).toBe('melo');
|
||||
});
|
||||
|
||||
it('should get API key from config', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
expect(provider.getApiKey()).toBe('test-key');
|
||||
});
|
||||
|
||||
it('should get API key from env', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
env: { HYPERBOLIC_API_KEY: 'env-key' },
|
||||
});
|
||||
expect(provider.getApiKey()).toBe('env-key');
|
||||
});
|
||||
|
||||
it('should get default API URL', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo');
|
||||
expect(provider.getApiUrl()).toBe('https://api.hyperbolic.xyz/v1');
|
||||
});
|
||||
|
||||
it('should get custom API URL from config', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiBaseUrl: 'https://custom.api.com' },
|
||||
});
|
||||
expect(provider.getApiUrl()).toBe('https://custom.api.com');
|
||||
});
|
||||
|
||||
it('should generate correct provider ID', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo');
|
||||
expect(provider.id()).toBe('hyperbolic:audio:melo');
|
||||
});
|
||||
|
||||
it('should have correct string representation', () => {
|
||||
const provider = new HyperbolicAudioProvider('melo');
|
||||
expect(provider.toString()).toBe('[Hyperbolic Audio Provider melo]');
|
||||
});
|
||||
|
||||
describe('callApi', () => {
|
||||
it('should throw error if API key is not set', async () => {
|
||||
const restoreEnv = mockProcessEnv({ HYPERBOLIC_API_KEY: undefined });
|
||||
try {
|
||||
const provider = new HyperbolicAudioProvider('melo');
|
||||
await expect(provider.callApi('test')).rejects.toThrow('Hyperbolic API key is not set');
|
||||
} finally {
|
||||
restoreEnv();
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle successful API call', async () => {
|
||||
const mockResponse = {
|
||||
data: { audio: 'base64audio' },
|
||||
cached: false,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
};
|
||||
|
||||
vi.mocked(fetchWithCache).mockResolvedValue(mockResponse);
|
||||
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test text');
|
||||
|
||||
expect(result).toEqual({
|
||||
output: 'base64audio',
|
||||
cached: false,
|
||||
cost: 0.001 * (9 / 1000), // 9 chars in 'test text'
|
||||
isBase64: true,
|
||||
audio: {
|
||||
data: 'base64audio',
|
||||
format: 'wav',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle API errors', async () => {
|
||||
const mockResponse = {
|
||||
data: { error: 'API Error' },
|
||||
cached: false,
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
};
|
||||
|
||||
vi.mocked(fetchWithCache).mockResolvedValue(mockResponse);
|
||||
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test');
|
||||
expect(result.error).toBe('API error: 400 Bad Request\n{"error":"API Error"}');
|
||||
});
|
||||
|
||||
it('should handle missing audio data', async () => {
|
||||
const mockResponse = {
|
||||
data: {},
|
||||
cached: false,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
};
|
||||
|
||||
vi.mocked(fetchWithCache).mockResolvedValue(mockResponse);
|
||||
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test');
|
||||
expect(result.error).toBe('No audio data returned from API');
|
||||
});
|
||||
|
||||
it('should handle cached responses', async () => {
|
||||
const mockResponse = {
|
||||
data: { audio: 'base64audio' },
|
||||
cached: true,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
};
|
||||
|
||||
vi.mocked(fetchWithCache).mockResolvedValue(mockResponse);
|
||||
|
||||
const provider = new HyperbolicAudioProvider('melo', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test text');
|
||||
expect(result.cached).toBe(true);
|
||||
expect(result.cost).toBe(0); // Cost should be 0 for cached responses
|
||||
});
|
||||
});
|
||||
|
||||
describe('createHyperbolicAudioProvider', () => {
|
||||
it('should create provider with default model', () => {
|
||||
const provider = createHyperbolicAudioProvider('hyperbolic:audio');
|
||||
expect((provider as HyperbolicAudioProvider).modelName).toBe('Melo-TTS');
|
||||
});
|
||||
|
||||
it('should create provider with specified model', () => {
|
||||
const provider = createHyperbolicAudioProvider('hyperbolic:audio:melo');
|
||||
expect((provider as HyperbolicAudioProvider).modelName).toBe('melo');
|
||||
});
|
||||
|
||||
it('should create provider with config', () => {
|
||||
const provider = createHyperbolicAudioProvider('hyperbolic:audio', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
expect((provider as HyperbolicAudioProvider).getApiKey()).toBe('test-key');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,206 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
calculateHyperbolicCost,
|
||||
createHyperbolicProvider,
|
||||
HYPERBOLIC_CHAT_MODELS,
|
||||
HYPERBOLIC_REASONING_MODELS,
|
||||
HyperbolicProvider,
|
||||
} from '../../../src/providers/hyperbolic/chat';
|
||||
import { OpenAiChatCompletionProvider } from '../../../src/providers/openai/chat';
|
||||
|
||||
describe('HyperbolicProvider', () => {
|
||||
let provider: HyperbolicProvider;
|
||||
const modelName = 'deepseek-ai/DeepSeek-R1';
|
||||
const options = {
|
||||
config: {
|
||||
config: {
|
||||
apiKey: 'test-key',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
provider = new HyperbolicProvider(modelName, options);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should create provider with correct config', () => {
|
||||
expect(provider.id()).toBe(`hyperbolic:${modelName}`);
|
||||
expect(provider.toString()).toBe(`[Hyperbolic Provider ${modelName}]`);
|
||||
});
|
||||
|
||||
it('should convert to JSON correctly', () => {
|
||||
const json = provider.toJSON();
|
||||
expect(json).toEqual({
|
||||
provider: 'hyperbolic',
|
||||
model: modelName,
|
||||
config: {
|
||||
apiKeyEnvar: 'HYPERBOLIC_API_KEY',
|
||||
apiBaseUrl: 'https://api.hyperbolic.xyz/v1',
|
||||
config: expect.any(Object),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should process API response correctly for reasoning model', async () => {
|
||||
const mockResponse = {
|
||||
raw: {
|
||||
usage: {
|
||||
completion_tokens_details: {
|
||||
reasoning_tokens: 100,
|
||||
accepted_prediction_tokens: 50,
|
||||
rejected_prediction_tokens: 25,
|
||||
},
|
||||
},
|
||||
},
|
||||
tokenUsage: {
|
||||
prompt: 200,
|
||||
completion: 150,
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(OpenAiChatCompletionProvider.prototype, 'callApi').mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
|
||||
expect(result.tokenUsage.completionDetails).toEqual({
|
||||
reasoning: 100,
|
||||
acceptedPrediction: 50,
|
||||
rejectedPrediction: 25,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle raw response as string', async () => {
|
||||
const mockResponse = {
|
||||
raw: JSON.stringify({
|
||||
usage: {
|
||||
completion_tokens_details: {
|
||||
reasoning_tokens: 100,
|
||||
accepted_prediction_tokens: 50,
|
||||
rejected_prediction_tokens: 25,
|
||||
},
|
||||
},
|
||||
}),
|
||||
tokenUsage: {
|
||||
prompt: 200,
|
||||
completion: 150,
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(OpenAiChatCompletionProvider.prototype, 'callApi').mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
|
||||
expect(result.tokenUsage.completionDetails).toEqual({
|
||||
reasoning: 100,
|
||||
acceptedPrediction: 50,
|
||||
rejectedPrediction: 25,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle error response', async () => {
|
||||
const mockResponse = { error: 'API error' };
|
||||
vi.spyOn(OpenAiChatCompletionProvider.prototype, 'callApi').mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.error).toBe('API error');
|
||||
});
|
||||
|
||||
it('should handle invalid JSON in raw response', async () => {
|
||||
const mockResponse = {
|
||||
raw: 'invalid json',
|
||||
tokenUsage: {
|
||||
prompt: 200,
|
||||
completion: 150,
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(OpenAiChatCompletionProvider.prototype, 'callApi').mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.tokenUsage.completionDetails).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should calculate cost for non-cached response', async () => {
|
||||
const mockResponse = {
|
||||
raw: 'test response',
|
||||
tokenUsage: {
|
||||
prompt: 1000,
|
||||
completion: 500,
|
||||
},
|
||||
cached: false,
|
||||
};
|
||||
|
||||
vi.spyOn(OpenAiChatCompletionProvider.prototype, 'callApi').mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.cost).toBe((0.5 / 1e6) * 1000 + (2.18 / 1e6) * 500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateHyperbolicCost', () => {
|
||||
it('should calculate cost correctly for known model', () => {
|
||||
const cost = calculateHyperbolicCost('deepseek-ai/DeepSeek-R1', {}, 1000, 500);
|
||||
expect(cost).toBe((0.5 / 1e6) * 1000 + (2.18 / 1e6) * 500);
|
||||
});
|
||||
|
||||
it('should calculate cost correctly for model alias', () => {
|
||||
const cost = calculateHyperbolicCost('DeepSeek-R1', {}, 1000, 500);
|
||||
expect(cost).toBe((0.5 / 1e6) * 1000 + (2.18 / 1e6) * 500);
|
||||
});
|
||||
|
||||
it('should return undefined for unknown model', () => {
|
||||
const cost = calculateHyperbolicCost('unknown-model', {}, 1000, 500);
|
||||
expect(cost).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined if tokens are missing', () => {
|
||||
const cost = calculateHyperbolicCost('deepseek-ai/DeepSeek-R1', {}, undefined, 500);
|
||||
expect(cost).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should use custom cost from config if provided', () => {
|
||||
const config = {
|
||||
cost: 0.001,
|
||||
};
|
||||
const cost = calculateHyperbolicCost('deepseek-ai/DeepSeek-R1', config, 1000, 500);
|
||||
expect(cost).toBe(0.001 * 1000 + 0.001 * 500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createHyperbolicProvider', () => {
|
||||
it('should create provider with correct model name', () => {
|
||||
const provider = createHyperbolicProvider('hyperbolic:deepseek-ai/DeepSeek-R1');
|
||||
expect(provider.id()).toBe('hyperbolic:deepseek-ai/DeepSeek-R1');
|
||||
});
|
||||
|
||||
it('should throw error if model name is missing', () => {
|
||||
expect(() => createHyperbolicProvider('hyperbolic:')).toThrow('Model name is required');
|
||||
});
|
||||
});
|
||||
|
||||
describe('HYPERBOLIC_CHAT_MODELS', () => {
|
||||
it('should contain valid model definitions', () => {
|
||||
for (const model of HYPERBOLIC_CHAT_MODELS) {
|
||||
expect(model).toHaveProperty('id');
|
||||
expect(model).toHaveProperty('cost.input');
|
||||
expect(model).toHaveProperty('cost.output');
|
||||
expect(model).toHaveProperty('aliases');
|
||||
expect(Array.isArray(model.aliases)).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('HYPERBOLIC_REASONING_MODELS', () => {
|
||||
it('should be a subset of HYPERBOLIC_CHAT_MODELS', () => {
|
||||
for (const modelId of HYPERBOLIC_REASONING_MODELS) {
|
||||
const found = HYPERBOLIC_CHAT_MODELS.some(
|
||||
(m) => m.id === modelId || m.aliases.includes(modelId),
|
||||
);
|
||||
expect(found).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,174 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fetchWithCache } from '../../../src/cache';
|
||||
import {
|
||||
createHyperbolicImageProvider,
|
||||
formatHyperbolicImageOutput,
|
||||
HyperbolicImageProvider,
|
||||
} from '../../../src/providers/hyperbolic/image';
|
||||
import { mockProcessEnv } from '../../util/utils';
|
||||
|
||||
vi.mock('../../../src/cache');
|
||||
|
||||
describe('HyperbolicImageProvider', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should initialize with default values', () => {
|
||||
const provider = new HyperbolicImageProvider('test-model');
|
||||
expect(provider.modelName).toBe('test-model');
|
||||
expect(provider.config).toEqual({});
|
||||
});
|
||||
|
||||
it('should initialize with config options', () => {
|
||||
const config = { apiKey: 'test-key' };
|
||||
const provider = new HyperbolicImageProvider('test-model', { config });
|
||||
expect(provider.config).toEqual(config);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getApiKey', () => {
|
||||
it('should return config apiKey if set', () => {
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
expect(provider.getApiKey()).toBe('test-key');
|
||||
});
|
||||
|
||||
it('should return env apiKey if set', () => {
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
env: { HYPERBOLIC_API_KEY: 'env-key' },
|
||||
});
|
||||
expect(provider.getApiKey()).toBe('env-key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatHyperbolicImageOutput', () => {
|
||||
it('should format b64_json output', () => {
|
||||
const result = formatHyperbolicImageOutput('test-data', 'test prompt', 'b64_json');
|
||||
expect(JSON.parse(result)).toEqual({
|
||||
data: [{ b64_json: 'test-data' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('should format JPEG data URL', () => {
|
||||
const result = formatHyperbolicImageOutput('/9j/test', 'test prompt');
|
||||
expect(result).toBe('data:image/jpeg;base64,/9j/test');
|
||||
});
|
||||
|
||||
it('should format PNG data URL', () => {
|
||||
const result = formatHyperbolicImageOutput('iVBORw0KGgo', 'test prompt');
|
||||
expect(result).toBe('data:image/png;base64,iVBORw0KGgo');
|
||||
});
|
||||
|
||||
it('should format WebP data URL', () => {
|
||||
const result = formatHyperbolicImageOutput('UklGR', 'test prompt');
|
||||
expect(result).toBe('data:image/webp;base64,UklGR');
|
||||
});
|
||||
});
|
||||
|
||||
describe('callApi', () => {
|
||||
it('should throw error if no API key', async () => {
|
||||
const restoreEnv = mockProcessEnv({ HYPERBOLIC_API_KEY: undefined });
|
||||
try {
|
||||
const provider = new HyperbolicImageProvider('test');
|
||||
await expect(provider.callApi('test prompt')).rejects.toThrow(
|
||||
'Hyperbolic API key is not set',
|
||||
);
|
||||
} finally {
|
||||
restoreEnv();
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle successful API call', async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
images: [
|
||||
{
|
||||
image: 'test-image-data',
|
||||
},
|
||||
],
|
||||
},
|
||||
cached: false,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
};
|
||||
|
||||
vi.mocked(fetchWithCache).mockResolvedValue(mockResponse);
|
||||
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
|
||||
expect(result).toEqual({
|
||||
output: 'data:image/jpeg;base64,test-image-data',
|
||||
cached: false,
|
||||
cost: 0.01,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle API errors', async () => {
|
||||
vi.mocked(fetchWithCache).mockResolvedValue({
|
||||
data: { error: 'API error' },
|
||||
cached: false,
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
});
|
||||
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.error).toBe('API error: 400 Bad Request\n{"error":"API error"}');
|
||||
});
|
||||
|
||||
it('should handle empty images array', async () => {
|
||||
vi.mocked(fetchWithCache).mockResolvedValue({
|
||||
data: { images: [] },
|
||||
cached: false,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
});
|
||||
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.error).toBe('No images returned from API');
|
||||
});
|
||||
|
||||
it('should handle network errors', async () => {
|
||||
vi.mocked(fetchWithCache).mockRejectedValue(new Error('Network error'));
|
||||
|
||||
const provider = new HyperbolicImageProvider('test', {
|
||||
config: { apiKey: 'test-key' },
|
||||
});
|
||||
|
||||
const result = await provider.callApi('test prompt');
|
||||
expect(result.error).toBe('API call error: Error: Network error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createHyperbolicImageProvider', () => {
|
||||
it('should create provider with default model', () => {
|
||||
const provider = createHyperbolicImageProvider('hyperbolic:image');
|
||||
expect(provider.id()).toBe('hyperbolic:image:SDXL1.0-base');
|
||||
});
|
||||
|
||||
it('should create provider with specified model', () => {
|
||||
const provider = createHyperbolicImageProvider('hyperbolic:image:test-model');
|
||||
expect(provider.id()).toBe('hyperbolic:image:test-model');
|
||||
});
|
||||
|
||||
it('should create provider with config', () => {
|
||||
const config = { apiKey: 'test-key' };
|
||||
const provider = createHyperbolicImageProvider('hyperbolic:image', { config });
|
||||
expect((provider as HyperbolicImageProvider).config).toEqual(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user