| |
| |
|
|
| import { beforeEach, vi } from 'vitest'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| const originalFetch = globalThis.fetch.bind(globalThis); |
|
|
| beforeEach(() => { |
| vi.spyOn(globalThis, 'fetch').mockImplementation( |
| async (input: RequestInfo | URL, init?: RequestInit) => { |
| const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; |
|
|
| |
| if (url.includes('/server')) { |
| return new Response( |
| JSON.stringify({ |
| git_branch: 'test', |
| git_commit: 'test', |
| mode: 'router', |
| version: 'test' |
| }), |
| { headers: { 'Content-Type': 'application/json' }, status: 200 } |
| ); |
| } |
|
|
| |
| if (/\/v1\/models|\/models\b/.test(url)) { |
| return new Response( |
| JSON.stringify({ |
| data: [ |
| { |
| created: 0, |
| id: 'test-model.gguf', |
| in_cache: false, |
| meta: {}, |
| object: 'model', |
| owned_by: 'llamacpp', |
| path: 'models/test-model.gguf', |
| status: { value: 'unloaded' } |
| } |
| ], |
| models: [ |
| { |
| details: {}, |
| model: 'test-model.gguf', |
| name: 'Test Model' |
| } |
| ], |
| object: 'list' |
| }), |
| { headers: { 'Content-Type': 'application/json' }, status: 200 } |
| ); |
| } |
|
|
| |
| if (url.includes('/props')) { |
| return new Response( |
| JSON.stringify({ |
| default_generation_settings: { n_ctx: 2048 } |
| }), |
| { headers: { 'Content-Type': 'application/json' }, status: 200 } |
| ); |
| } |
|
|
| |
| if (url.includes('/tools')) { |
| return new Response(JSON.stringify([]), { |
| headers: { 'Content-Type': 'application/json' }, |
| status: 200 |
| }); |
| } |
|
|
| |
| return originalFetch(input, init); |
| } |
| ); |
| }); |
|
|