UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

97 lines (96 loc) 2.45 kB
class b { // private apiKey: string; constructor(l) { } getOptionsDescription() { return { model: { type: "input", label: "Model", default: "llama2" }, apiUrl: { type: "input", label: "Api Url", default: "" }, maxTokens: { type: "number", label: "Max Tokens", default: 100, min: 1, max: 2048 }, temperature: { type: "number", label: "Temperature", default: 0.7, min: 0, max: 2 }, topP: { type: "number", label: "Top P", default: 1, min: 0, max: 1 }, frequencyPenalty: { type: "number", label: "Frequency Penalty", default: 0, min: 0, max: 2 }, presencePenalty: { type: "number", label: "Presence Penalty", default: 0, min: 0, max: 2 } }; } /** * Генерация текста с использованием API Ollama. * Поддерживает потоковые и не потоковые ответы. */ async generateText(l, e) { var m; const t = { model: (e == null ? void 0 : e.model) || "", prompt: l, max_tokens: (e == null ? void 0 : e.maxTokens) || 100, temperature: (e == null ? void 0 : e.temperature) || 0.7, top_p: (e == null ? void 0 : e.topP) || 1, frequency_penalty: (e == null ? void 0 : e.frequencyPenalty) || 0, presence_penalty: (e == null ? void 0 : e.presencePenalty) || 0, stream: (e == null ? void 0 : e.stream) || !1 // По умолчанию отключаем потоковый ответ }, a = await fetch(`${e == null ? void 0 : e.apiUrl}/api/generate`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(t) }); if (!a.ok) throw new Error("Failed to generate text with Ollama"); if (t.stream) { const r = (m = a.body) == null ? void 0 : m.getReader(); let u = ""; if (r) for (; ; ) { const { done: d, value: y } = await r.read(); if (d) break; const c = new TextDecoder().decode(y), n = JSON.parse(c); u += n.response; } return u; } else return (await a.json()).response; } } export { b as OllamaDriver };