POST /api/generate HTTP/1.1 Content-Type: application/json Authorization: Bearer Host: localhost:11434 Connection: close Transfer-Encoding: chunked 649e {"model":"codellama:7b-code","prompt":"
 \n\n// Language: Javascript (javascript) \n// File uri: file:///Users/nick/.vscode/extensions/rjmacarthy.twinny-2.6.17/out/extension.js (javascript) \n                (0, i.exec)(\"ollama serve\"),\n                new Promise((e) => setTimeout(() => e(!0), 1e3))\n              );\n            })();\n        };\n      },\n      249: (e, t) => {\n        \"use strict\";\n        Object.defineProperty(t, \"__esModule\", { value: !0 }),\n          (t.languages = void 0),\n          (t.languages = {\n            typescript: {\n              name: \"Typescript\",\n              extensions: [\".ts\", \".cts\", \".mts\"],\n              comment: { start: \"//\" },\n            },\n            typescriptreact: {\n              name: \"Typescript React\",\n              extensions: [\".tsx\"],\n              comment: { start: \"//\" },\n            },\n            javascript: {\n              name: \"Javascript\",\n              extensions: [\".js\", \".jsx\", \".cjs\"],\n              comment: { start: \"//\" },\n            },\n            jsx: {\n              name: \"JSX\",\n              extensions: [\".jsx\"],\n              comment: { start: \"//\" },\n            },\n            html: {\n              name: \"HTML\",\n              extensions: [\".htm\", \".html\"],\n              comment: { start: \"\\x3c!--\", end: \"--\\x3e\" },\n            },\n            css: { name: \"CSS\", extensions: [\".css\"] },\n            sass: {\n              name: \"SASS\",\n              extensions: [\".sass\"],\n              comment: { start: \"//\" },\n            },\n            scss: {\n              name: \"SCSS\",\n              extensions: [\".scss\"],\n              comment: { start: \"//\" },\n            },\n            json: { name: \"JSON\", extensions: [\".json\", \".jsonl\", \".geojson\"] },\n            yaml: {\n              name: \"YAML\",\n              extensions: [\".yml\", \".yaml\"],\n              comment: { start: \"#\" },\n            },\n            xml: {\n              name: \"XML\",\n              extensions: [\".xml\"],\n              comment: { start: \"\\x3c!--\", end: \"--\\x3e\" },\n            },\n            java: {\n              name: \"Java\",\n              extensions: [\".java\"],\n              comment: { start: \"//\" },\n            },\n            kotlin: {\n              name: \"Kotlin\",\n              extensions: [\".kt\", \".ktm\", \".kts\"],\n              comment: { start: \"//\" },\n            },\n            swift: {\n              name: \"Swift\",\n              extensions: [\".swift\"],\n              comment: { start: \"//\" },\n            },\n            \"objective-c\": {\n              name: \"Objective C\",\n              extensions: [\".h\", \".m\", \".mm\"],\n              comment: { start: \"//\" },\n            },\n            rust: {\n              name: \"Rust\",\n              extensions: [\".rs\", \".rs.in\"],\n              comment: { start: \"//\" },\n            },\n            python: {\n              name: \"Python\",\n              extensions: [\".py\"],\n              comment: { start: \"#\" },\n            },\n            c: {\n              name: \"C\",\n              extensions: [\".c\", \".h\"],\n              comment: { start: \"//\" },\n            },\n            cpp: {\n              name: \"C++\",\n              extensions: [\".cpp\", \".h\"],\n              comment: { start: \"//\" },\n            },\n            go: { name: \"Go\", extensions: [\".go\"], comment: { start: \"//\" } },\n            php: {\n              name: \"PHP\",\n              extensions: [\n                \".aw\",\n                \".ctp\",\n                \".fcgi\",\n                \".inc\",\n                \".php\",\n                \".php3\",\n                \".php4\",\n                \".php5\",\n                \".phps\",\n                \".phpt\",\n              ],\n              comment: { start: \"//\" },\n            },\n            bat: {\n              name: \"BAT file\",\n              extensions: [\".bat\", \".cmd\"],\n              comment: { start: \"REM\" },\n            },\n            shellscript: {\n              name: \"Shell\",\n              extensions: [\".bash\", \".sh\"],\n              comment: { start: \"#\" },\n            },\n          });\n      },\n      861: (e, t) => {\n        \"use strict\";\n        Object.defineProperty(t, \"__esModule\", { value: !0 }),\n          (t.chatMessageDeepSeek =\n            t.chatMessageLlama =\n            t.generateDocs =\n            t.addTests =\n            t.refactor =\n            t.addTypes =\n            t.explain =\n            t.getSystemMessage =\n              void 0);\n        const n =\n          \"You are a helpful, respectful and honest coding assistant.\\nAlways reply with using markdown.\\nFor code refactoring, use markdown with code formatting.\\n\";\n        (t.getSystemMessage = (e) =>\n          e.includes(\"deepseek\") ? n : `<>${n}<>`),\n          (t.explain = (e, n) =>\n            `\\n    ${(0, t.getSystemMessage)(\n              n\n            )}\\n    Explain the following code \\`\\`\\`${e}\\`\\`\\` do not waffle on.\\n  `),\n          (t.addTypes = (e, n) =>\n            `\\n    ${(0, t.getSystemMessage)(\n              n\n            )}\\n    Add types to the following code, keep the code the same just add the types \\`\\`\\`${e}\\`\\`\\`.\\n  `),\n          (t.refactor = (e, n) =>\n            `\\n    ${(0, t.getSystemMessage)(\n              n\n            )}\\n    Refactor the following code without altering its functionality:\\n    \\`\\`\\`${e}\\`\\`\\`\\n    Always format responses with Markdown for code blocks. For instance, use \\`typescript\\` or \\`python\\` for code formatting.\\n    If the language of the code is uncertain, default to using \\`typescript\\`.\\n  `),\n          (t.addTests = (e, n) =>\n            `\\n    ${(0, t.getSystemMessage)(\n              n\n            )}\\n    Write unit tests for the following code block:\\n    \\`\\`\\`${e}\\`\\`\\`\\n    Please use the most popular testing library suitable for the language of the code.\\n  `),\n          (t.generateDocs = (e, n) =>\n            `\\n    ${(0, t.getSystemMessage)(\n              n\n            )}\\n    Generate documentation for the following code block:\\n    \\`\\`\\`${e}\\`\\`\\`\\n    Use the most popular documentation tool for the inferred language, e.g., JSDoc for JavaScript.\\n  `),\n          (t.chatMessageLlama = (e, n, i) =>\n            `\\n    ${\n              1 === e.length ? (0, t.getSystemMessage)(i) : \"\"\n            }\\n\\n    ${e\n              .map((e) =>\n                \"user\" === e.role\n                  ? `[INST] ${e.content} ${\n                      n ? ` \\`\\`\\`${n}\\`\\`\\` ` : \"\"\n                    } [/INST]`\n                  : `${e.content}`\n              )\n              .join(\"\\n\")}\\n  `),\n          (t.chatMessageDeepSeek = (e, n, i) =>\n            `\\n    ${\n              1 === e.length ? (0, t.getSystemMessage)(i) : \"\"\n            }\\n\\n    ${e\n              .map((e) =>\n                \"user\" === e.role\n                  ? `### Instruction:\\n          ${e.content} ${\n                      n ? ` \\`\\`\\`${n}\\`\\`\\` ` : \"\"\n                    }`\n                  : `\\n            ### Response:\\n            ${e.content}\\n            <|EOT|>\\n          `\n              )\n              .join(\"\\n\")}\\n  `);\n      },\n      237: (e, t, n) => {\n        \"use strict\";\n        Object.defineProperty(t, \"__esModule\", { value: !0 }),\n          (t.CompletionProvider = void 0);\n        const i = n(496);\n        n(284);\n        const o = n(593),\n          s = n(78),\n          a = n(249);\n        t.CompletionProvider = class {\n          constructor(e) {\n            (this._config = i.workspace.getConfiguration(\"twinny\")),\n              (this._debounceWait = this._config.get(\"debounceWait\")),\n              (this._contextLength = this._config.get(\"contextLength\")),\n              (this._fimModel = this._config.get(\"fimModelName\")),\n              (this._baseUrl = this._config.get(\"ollamaBaseUrl\")),\n              (this._port = this._config.get(\"ollamaApiPort\")),\n              (this._temperature = this._config.get(\"temperature\")),\n              (this._numPredictFim = this._config.get(\"numPredictFim\")),\n              (this._useFileContext = this._config.get(\"useFileContext\")),\n              (this._bearerToken = this._config.get(\"ollamaApiBearerToken\")),\n              (this._currentReq = void 0),\n              (this._isModelAvailable = !0),\n              (this.setModelAvailability = async () => {\n                this._isModelAvailable = await (0, o.getIsModelAvailable)(\n                  this._fimModel\n                );\n              }),\n              (this.destroyStream = () => {\n                this._currentReq?.destroy(), (this._statusBar.text = \"....\");\n              }),\n              (this.getFormattedCompletion = (e, t, n) => {\n                const o = t.selection.active,\n                  s = new i.Range(n.translate(0, -1), t.selection.start),\n                  a = t.document.lineAt(o.line).range.end,\n                  r = new i.Range(o, a),\n                  c = this._document?.getText(r).trim() || \"\",\n                  l = this._document?.getText(s),\n                  d = t.document.lineAt(o).range.start,\n                  m = new i.Range(d, a),\n                  p = this._document?.getText(m);\n                return \"/\" === e.trim() ||\n                  p?.includes(e.trim()) ||\n                  (\"/>\" === e.trim() && p?.includes(\" {\n                    this._debouncer && clearTimeout(this._debouncer),\n                      (this._debouncer = setTimeout(async () => {\n                        if (!this._config.get(\"enabled\")) return n([]);\n                        const r = this.getFileContext(e.uri),\n                          {\n                            prompt: c,\n                            prefix: l,\n                            suffix: d,\n                          } = this.getPrompt(e, t, r, a),\n                          m = (0, s.getCache)({ prefix: l, suffix: d });\n                        if (m)\n                          return n([\n                            new i.InlineCompletionItem(m, new i.Range(t, t)),\n                          ]);\n                        if (!c) return n([]);\n                        try {\n                          let e = \"\",\n                            i = 0;\n                          (this._statusBar.text = \"$(loading~spin)\"),\n                            (this._statusBar.command = \"twinny.stopGeneration\");\n                          const { requestBody: s, requestOptions: a } =\n                            this.buildStreamRequest(c);\n                          (0, o.streamResponse)({\n                            body: s,\n                            options: a,\n                            onStart: (e) => {\n                              this._currentReq = e;\n                            },\n                            onData: (o, s) => {\n                              console.log('NOOOOOOO!' + String(o)) \n                              const a = JSON.parse(o);\n                              (e += a.response),\n                                (i += 1),\n                                ((1 !== i && \"\\n\" === a.response) ||\n                                  a.response.match(\"\")) &&\n                                  ((this._statusBar.text = \"....\"),\n                                  (e = e.replace(\"\", \"\")),\n                                  s(),\n                                  n(\n                                    this.triggerInlineCompletion({\n                                      completion: e,\n                                      position: t,\n                                      prefix: l,\n                                      suffix: d,\n                                    })\n                                  ));\n                            },\n                          });\n                        } catch (e) {\n                          return (this._statusBar.text = \"$(alert)\"), n([]);\n                        }\n                      }, this._debounceWait));\n                  })\n                : void 0\n              : ((this._statusBar.text = \"$(error)\"),\n                void (this._statusBar.tooltip = `Model ${this._fimModel} not found.`));\n          }\n          getPrompt(e, t, n, i) {\n            const o = this._useFileContext ? this.getFileHeader(i, e.uri) : \"\",\n              { prefix: s, suffix: a } = this.getPositionContext(e, t),\n              r = this._useFileContext ? n : \"\";\n            return this._fimModel.includes(\"deepseek\")\n              ? {\n                  prompt: `<...fim...begin...> ${r}\\n${o}${s} <...fim...hole...>${a} <...fim...end...>`,\n                  prefix: s,\n                  suffix: a,\n                }\n              : {\n                  prompt: `
 ${r}\\n${o}${s} ${a} `,\n                  prefix: s,\n                  suffix: a,\n                };\n          }\n          getFileHeader(e, t) {\n            const n = a.languages[e];\n            return n\n              ? `\\n${n.comment?.start || \"\"} Language: ${n.name} (${e}) ${\n                  n.comment?.end || \"\"\n                }\\n${n.comment?.start || \"\"} File uri: ${t.toString()} (${e}) ${\n                  n.comment?.end || \"\"\n                }\\n`\n              : \"\";\n          }\n          calculateSimilarity(e, t) {\n            const n = e.split(\"/\"),\n              i = t.split(\"/\"),\n              o = n[n.length - 1],\n              s = i[i.length - 1];\n            return (\n              n.slice(0, -1).join(\"/\").score(i.slice(0, -1).join(\"/\"), 0.5) +\n              o.score(s, 0.5)\n            );\n          }\n          getFileContext(e) {\n            const t = [],\n              n = e.toString();\n            for (const e of i.workspace.textDocuments) {\n              if (\n                e.fileName === i.window.activeTextEditor?.document.fileName ||\n                e.fileName.includes(\"git\")\n              )\n                continue;\n              const o = `${this.getFileHeader(\n                e.languageId,\n                e.uri\n              )}${e.getText()}`;\n              this.calculateSimilarity(n.toString(), e.uri.toString()) > 1 &&\n                t.push(o);\n            }\n            return t.join(\"\\n\");\n          }\n          getPositionContext(e, t) {\n            const n = t.line,\n              o = Math.max(0, n - this._contextLength),\n              s = n + this._contextLength,\n              a = new i.Range(o, 0, n, t.character),\n              r = new i.Range(n, t.character, s, 0);\n            return { prefix: e.getText(a), suffix: e.getText(r) };\n          }\n          triggerInlineCompletion(e) {\n            const { position: t, prefix: n, suffix: o } = e,\n              a = i.window.activeTextEditor;\n            if (!a) return [];\n            const r = this.getFormattedCompletion(e.completion, a, t);\n            return (\n              (0, s.setCache)({ prefix: n, suffix: o, completion: r }),\n              [new i.InlineCompletionItem(r, new i.Range(t, t))]\n            );\n          }\n          updateConfig() {\n            (this._config = i.workspace.getConfiguration(\"twinny\")),\n              (this._debounceWait = this._config.get(\"debounceWait\")),\n              (this._contextLength = this._config.get(\"contextLength\")),\n              (this._temperature = this._config.get(\"temperature\")),\n              (this._useFileContext = this._config.get(\"useFileContext\")),\n              (this._fimModel = this._config.get(\"fimModelName\")),\n              (this._numPredictFim = this._config.get(\"numPredictFim\"));\n          }\n        };\n      },\n      318: function (e, t, n) {\n        \"use strict\";\n        var i =\n            (this && this.__createBinding) ||\n            (Object.create\n              ? function (e, t, n, i) {\n                  void 0 === i && (i = n);\n                  var o = Object.getOwnPropertyDescriptor(t, n);\n                  (o &&\n                    !(\"get\" in o\n                      ? !t.__esModule\n                      : o.writable || o.configurable)) ||\n                    (o = {\n                      enumerable: !0,\n                      get: function () {\n                        return t[n];\n                      },\n                    }),\n                    Object.defineProperty(e, i, o);\n                }\n              : function (e, t, n, i) {\n                  void 0 === i && (i = n), (e[i] = t[n]);\n                }),\n          o =\n            (this && this.__setModuleDefault) ||\n            (Object.create\n              ? function (e, t) {\n                  Object.defineProperty(e, \"default\", {\n                    enumerable: !0,\n                    value: t,\n                  });\n                }\n              : function (e, t) {\n                  e.default = t;\n                }),\n          s =\n            (this && this.__importStar) ||\n            function (e) {\n              if (e && e.__esModule) return e;\n              var t = {};\n              if (null != e)\n                for (var n in e)\n                  \"default\" !== n &&\n                    Object.prototype.hasOwnProperty.call(e, n) &&\n                    i(t, e, n);\n              return o(t, e), t;\n            };\n        Object.defineProperty(t, \"__esModule\", { value: !0 }),\n          (t.SidebarProvider = void 0);\n        const a = s(n(496)),\n          r = n(593),\n          c = n(523),\n          l = n(601),\n          d = n(769);\n        t.SidebarProvider = class {\n          constructor(e, t) {\n            (this._extensionUri = e),\n              (this._config = a.workspace.getConfiguration(\"twinny\")),\n              (this._model = this._config.get(\"chatModelName\")),\n              (this.chatService = void 0),\n              (this._statusBar = t);\n          }\n          resolveWebviewView(e) {\n            (this.chatService = new d.ChatService(this._statusBar, e)),\n              (e.webview.options = {\n                enableScripts: !0,\n                localResourceRoots: [this._extensionUri],\n              }),\n              (e.webview.html = this._getHtmlForWebview(e.webview)),\n              a.window.onDidChangeTextEditorSelection((t) => {\n                const n = t.textEditor.document.getText(t.selections[0]);\n                e.webview.postMessage({\n                  type: l.MESSAGE_NAME.twinnyTextSelection,\n                  value: { type: l.MESSAGE_KEY.selection, completion: n },\n                });\n              }),\n              e.webview.onDidReceiveMessage((t) => {\n                if (!(0, r.getIsModelAvailable)(this._model)) return;\n                const n = (0, c.getContext)();\n                if (\n                  (t.type === l.MESSAGE_NAME.twinnyChatMessage &&\n                    this.chatService?.streamChatCompletion(t.data),\n                  t.type === l.MESSAGE_NAME.twinnyOpenDiff)\n                ) {\n                  const e = a.window.activeTextEditor,\n                    n = e?.selection,\n                    i = e?.document.getText(n);\n                  (0, r.openDiffView)(i || \"\", t.data);\n                }\n                if (\n                  (t.type === l.MESSAGE_NAME.twinnyOpenSettings &&\n                    a.commands.executeCommand(\n                      \"workbench.action.openSettings\",\n                      l.EXTENSION_NAME\n                    ),\n                  t.type === l.MESSAGE_NAME.twinnyTextSelection &&\n                    e.webview.postMessage({\n                      type: l.MESSAGE_NAME.twinnyTextSelection,\n                      value: {\n                        type: l.MESSAGE_KEY.selection,\n                        completion: (0, r.getTextSelection)(),\n                      },\n                    }),\n                  t.type === l.MESSAGE_NAME.twinnyAcceptSolution)\n                ) {\n                  const e = a.window.activeTextEditor,\n                    n = e?.selection;\n                  if (!n) return;\n                  a.window.activeTextEditor?.edit((e) => {\n                    e.replace(n, t.data);\n                  });\n                }\n                if (t.type === l.MESSAGE_NAME.twinnyGlobalContext) {\n                  const i = n?.globalState.get(\n                    `${l.MESSAGE_NAME.twinnyGlobalContext}-${t.key}`\n                  );\n                  e.webview.postMessage({\n                    type: `${l.MESSAGE_NAME.twinnyGlobalContext}-${t.key}`,\n                    value: i,\n                  });\n                }\n                if (\n                  (t.type === l.MESSAGE_NAME.twinnySetGlobalContext &&\n                    n?.globalState.update(\n                      `${l.MESSAGE_NAME.twinnyGlobalContext}-${t.key}`,\n                      t.data\n                    ),\n                  t.type === l.MESSAGE_NAME.twinnyWorkspaceContext)\n                ) {\n                  const i = n?.workspaceState.get(\n                    `${l.MESSAGE_NAME.twinnyWorkspaceContext}-${t.key}`\n                  );\n                  e.webview.postMessage({\n                    type: `${l.MESSAGE_NAME.twinnyWorkspaceContext}-${t.key}`,\n                    value: i,\n                  });\n                }\n                t.type === l.MESSAGE_NAME.twinnySetWorkspaceContext &&\n                  n?.workspaceState.update(\n                    `${l.MESSAGE_NAME.twinnyWorkspaceContext}-${t.key}`,\n                    t.data\n                  ),\n                  t.type === l.MESSAGE_NAME.twinnyNotification &&\n                    a.window.showInformationMessage(t.data);\n              });\n          }\n          _getHtmlForWebview(e) {\n            const t = e.asWebviewUri(\n                a.Uri.joinPath(this._extensionUri, \"out\", \"sidebar.js\")\n              ),\n              n = (function () {\n                let e = \"\";\n                const t =\n                  \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n                for (let n = 0; n < 32; n++)\n                  e += t.charAt(Math.floor(62 * Math.random()));\n                return e;\n              })();\n            return `\\n    \\n    \\n        \\n\\t\\t\\t\\t\\n        \\n        Sidebar\\n    \\n    \\n        
\\n