18 lines
1.2 KiB
TypeScript
18 lines
1.2 KiB
TypeScript
/** Exercise both real pi-ai transports and their catalog prices, without provider SDK mocks. */
|
|
import { proxyModels } from './proxy-models';
|
|
const models = await proxyModels(globalThis.testProxy);
|
|
for (const [provider, id] of [['openai', 'gpt-6.1-sol'], ['anthropic', 'claude-opus-5-5']]) {
|
|
const model = models.getModel(provider, id);
|
|
if (model.cost.input !== 2 || model.cost.cacheWrite !== 3) throw new Error('catalog prices lost');
|
|
const result = await models.completeSimple(model, {messages: [{role: 'user', content: 'Say hello.', timestamp: Date.now()}]}, {reasoning: 'low', maxTokens: 128});
|
|
if (result.stopReason === 'error' || !result.content.some(block => block.type === 'text' && block.text === 'hello')) {
|
|
throw new Error(`${provider}: ${result.errorMessage ?? JSON.stringify(result.content)}`);
|
|
}
|
|
if (!(result.usage.cost.total > 0)) throw new Error('turn cost missing');
|
|
}
|
|
const fallback = await proxyModels({...globalThis.testProxy, base_url: `${globalThis.testProxy.base_url}/offline`});
|
|
for (const [provider, api] of [['openai', 'openai-responses'], ['anthropic', 'anthropic-messages']]) {
|
|
const model = fallback.getModels(provider)[0];
|
|
if (model.api !== api || model.cost.input !== 0) throw new Error('offline transport fallback failed');
|
|
}
|