mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
feat(ollama): Enhance Ollama support by adding new models, updating API format handling, and integrating translation functionality.
This commit is contained in:
@@ -159,7 +159,7 @@ export function createSSEStream(options = {}) {
|
||||
// Translate mode
|
||||
if (!trimmed) continue;
|
||||
|
||||
const parsed = parseSSELine(trimmed);
|
||||
const parsed = parseSSELine(trimmed, targetFormat);
|
||||
if (!parsed) continue;
|
||||
|
||||
if (parsed && parsed.done) {
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
import { FORMATS } from "../translator/formats.js";
|
||||
|
||||
// Parse SSE data line
|
||||
export function parseSSELine(line) {
|
||||
if (!line || line.charCodeAt(0) !== 100) return null; // 'd' = 100
|
||||
export function parseSSELine(line, format = null) {
|
||||
if (!line) return null;
|
||||
|
||||
// NDJSON format (Ollama): raw JSON lines without "data:" prefix
|
||||
if (format === FORMATS.OLLAMA) {
|
||||
const trimmed = line.trim();
|
||||
if (trimmed.startsWith("{")) {
|
||||
try {
|
||||
return JSON.parse(trimmed);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Standard SSE format: "data: {...}"
|
||||
if (line.charCodeAt(0) !== 100) return null; // 'd' = 100
|
||||
|
||||
const data = line.slice(5).trim();
|
||||
if (data === "[DONE]") return { done: true };
|
||||
|
||||
Reference in New Issue
Block a user