Spaces:
Runtime error
Runtime error
Download server/src/__tests__/routes/proxy-stream-chunk.test.ts from Nryn215/FreeLLMAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/Nryn215/FreeLLMAPI/resolve/main/server/src/__tests__/routes/proxy-stream-chunk.test.ts
- Command line
-
hf download hf://spaces/Nryn215/FreeLLMAPI/server/src/__tests__/routes/proxy-stream-chunk.test.ts
-
curl -L -o proxy-stream-chunk.test.ts https://huggingface.co/spaces/Nryn215/FreeLLMAPI/resolve/main/server/src/__tests__/routes/proxy-stream-chunk.test.ts
1.42 kB
| import { describe, it, expect } from 'vitest'; | |
| import { streamChunkText } from '../../routes/proxy.js'; | |
| // Regression for the mid-stream crash: a streaming chunk with no `choices` | |
| // array (Groq and others emit usage/keepalive frames like this) used to throw | |
| // "Cannot read properties of undefined (reading '0')" via `chunk.choices[0]`, | |
| // aborting the SSE response after headers were already sent (so no fallback). | |
| describe('streamChunkText', () => { | |
| it('extracts delta content from a normal chunk', () => { | |
| expect(streamChunkText({ choices: [{ delta: { content: 'hello' } }] })).toBe('hello'); | |
| }); | |
| it('returns "" for a usage/keepalive chunk that has no choices array', () => { | |
| expect(streamChunkText({ usage: { prompt_tokens: 1, completion_tokens: 2 } })).toBe(''); | |
| expect(streamChunkText({ x_groq: { usage: {} } })).toBe(''); | |
| }); | |
| it('returns "" for an empty choices array', () => { | |
| expect(streamChunkText({ choices: [] })).toBe(''); | |
| }); | |
| it('returns "" for a tool-call delta with no text content', () => { | |
| expect(streamChunkText({ choices: [{ delta: { tool_calls: [{ index: 0 }] } }] })).toBe(''); | |
| }); | |
| it('returns "" for null / undefined / malformed chunks', () => { | |
| expect(streamChunkText(null)).toBe(''); | |
| expect(streamChunkText(undefined)).toBe(''); | |
| expect(streamChunkText({})).toBe(''); | |
| expect(streamChunkText({ choices: [{}] })).toBe(''); | |
| }); | |
| }); | |