A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
test: basic llm test with different providers
Christian Fei4a8254991d38
diff --git a/lib/llm/index.js b/lib/llm/index.jsindex e1d0a82..fbb4132 100644--- a/lib/llm/index.js+++ b/lib/llm/index.js@@ -9,8 +9,8 @@ export async function summarize(try {const llm = llmSettings.host.includes('api.anthropic.com')? new Anthropic(system, llmSettings)- : new Generic(system, llmSettings)-+ : new Generic(system, llmSettings)+return llm.summarize(prompt)} catch (e) {console.error('Error summarizing video', e.message)diff --git a/lib/llm/providers/generic.js b/lib/llm/providers/generic.jsindex 2808144..620b35d 100644--- a/lib/llm/providers/generic.js+++ b/lib/llm/providers/generic.js@@ -38,7 +38,7 @@ export class Generic {const message = messages[messages.length - 1]?.message?.content || ''return message.replace('<|eot_id|>', '')}-+async summarize(prompt) {if (prompt.length > MAX_PROMPT_LEN) prompt = prompt.substring(0, MAX_PROMPT_LEN)diff --git a/package-lock.json b/package-lock.jsonindex 51e4745..2917d88 100644--- a/package-lock.json+++ b/package-lock.json@@ -10,6 +10,9 @@"license": "ISC","dependencies": {"nano-spawn": "^0.2.0"+ },+ "devDependencies": {+ "undici": "^7.7.0"}},"node_modules/nano-spawn": {@@ -23,6 +26,16 @@"funding": {"url": "https://github.com/sindresorhus/nano-spawn?sponsor=1"}+ },+ "node_modules/undici": {+ "version": "7.7.0",+ "resolved": "https://registry.npmjs.org/undici/-/undici-7.7.0.tgz",+ "integrity": "sha512-tZ6+5NBq4KH35rr46XJ2JPFKxfcBlYNaqLF/wyWIO9RMHqqU/gx/CLB1Y2qMcgB8lWw/bKHa7qzspqCN7mUHvA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=20.18.1"+ }}}}diff --git a/package.json b/package.jsonindex b3789cf..d144f97 100644--- a/package.json+++ b/package.json@@ -13,5 +13,8 @@"description": "","dependencies": {"nano-spawn": "^0.2.0"+ },+ "devDependencies": {+ "undici": "^7.7.0"}}diff --git a/test/llm/index.test.js b/test/llm/index.test.jsnew file mode 100644index 0000000..6a9910f--- /dev/null+++ b/test/llm/index.test.js@@ -0,0 +1,108 @@+import {test, beforeEach} from "node:test"+import assert from "node:assert"+import { MockAgent, setGlobalDispatcher } from 'undici'++import { summarize } from "../../lib/llm/index.js"+const system = "You are a helpful assistant."+const prompt = "Just tell me something"++let agent;+beforeEach(() => {+ agent = new MockAgent()+ setGlobalDispatcher(agent)+})++test('should use Anthropic provider', async () => {+ const llmSettings = {+ host: 'https://api.anthropic.com',+ model: 'claude-v1',+ endpoint: '/v1/messages',+ apiKey: 'your-api-key',+ temperature: 0.7,+ maxTokens: 1000+ }++ agent+ .get('https://api.anthropic.com')+ .intercept({+ path: '/v1/messages',+ method: 'POST'+ })+ .reply(200, {+ "content": [+ {+ "text": "something",+ "type": "text"+ }+ ],+ "id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",+ "model": "claude-3-7-sonnet-20250219",+ "role": "assistant",+ "stop_reason": "end_turn",+ "stop_sequence": null,+ "type": "message",+ "usage": {+ "input_tokens": 2095,+ "output_tokens": 503+ }+ })++ const result = await summarize(system, prompt, llmSettings)+ assert.equal(result, 'something')+})++test('should use OpenAI provider', async () => {+ const llmSettings = {+ host: 'https://api.openai.com',+ model: 'gpt-4o',+ endpoint: '/v1/chat/completions',+ apiKey: 'your-api-key',+ temperature: 0.7,+ maxTokens: 1000+ }++ agent+ .get('https://api.openai.com')+ .intercept({+ path: '/v1/chat/completions',+ method: 'POST'+ })+ .reply(200, {+ "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",+ "object": "chat.completion",+ "created": 1741569952,+ "model": "gpt-4o-2024-08-06",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "something",+ "refusal": null,+ "annotations": []+ },+ "logprobs": null,+ "finish_reason": "stop"+ }+ ],+ "usage": {+ "prompt_tokens": 19,+ "completion_tokens": 10,+ "total_tokens": 29,+ "prompt_tokens_details": {+ "cached_tokens": 0,+ "audio_tokens": 0+ },+ "completion_tokens_details": {+ "reasoning_tokens": 0,+ "audio_tokens": 0,+ "accepted_prediction_tokens": 0,+ "rejected_prediction_tokens": 0+ }+ },+ "service_tier": "default"+ })++ const result = await summarize(system, prompt, llmSettings)+ assert.equal(result, 'something')+})\ No newline at end of file