Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
|
import nock from 'nock';
|
|
|
|
const credentials = {
|
|
perplexityApi: {
|
|
apiKey: 'test-api-key',
|
|
baseUrl: 'https://api.perplexity.ai',
|
|
},
|
|
};
|
|
|
|
describe('Perplexity Node - Chat Completions', () => {
|
|
beforeEach(() => {
|
|
nock.disableNetConnect();
|
|
nock('https://api.perplexity.ai')
|
|
.post('/chat/completions', (body) => {
|
|
return (
|
|
body?.model?.value === 'sonar' &&
|
|
body?.model?.mode === 'id' &&
|
|
Array.isArray(body?.messages) &&
|
|
body.messages.length === 3 &&
|
|
body.messages[0].role === 'user' &&
|
|
body.messages[1].role === 'assistant' &&
|
|
body.messages[2].role === 'user'
|
|
);
|
|
})
|
|
.reply(200, {
|
|
id: '6bb24c98-3071-4691-9a7b-dc4bc18c3c2c',
|
|
model: 'sonar',
|
|
created: 1743161086,
|
|
object: 'chat.completion',
|
|
usage: {
|
|
prompt_tokens: 4,
|
|
completion_tokens: 4,
|
|
total_tokens: 8,
|
|
},
|
|
choices: [
|
|
{
|
|
index: 0,
|
|
finish_reason: 'length',
|
|
message: {
|
|
role: 'assistant',
|
|
content: '<think>\nOkay,',
|
|
},
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
nock.cleanAll();
|
|
nock.enableNetConnect();
|
|
});
|
|
|
|
new NodeTestHarness().setupTests({ credentials });
|
|
});
|