Fix issues parsing Ollama /api/show endpoint payloads. (#1199)

This commit is contained in:
Chad Yates 2024-04-27 20:34:57 -07:00 • committed by GitHub
parent c43975d6a5
commit 53bbaeef2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,12 +38,12 @@ class Ollama extends BaseLLM {
if (body.parameters) {
const params = [];
for (let line of body.parameters.split("\n")) {
let parts = line.split(" ");
let parts = line.match(/^(\S+)\s+((?:".*")|\S+)$/);
if (parts.length < 2) {
continue;
}
let key = parts[0];
let value = parts[parts.length - 1];
let key = parts[1];
let value = parts[2];
switch (key) {
case "num_ctx":
this.contextLength = parseInt(value);
@ -52,7 +52,12 @@ class Ollama extends BaseLLM {
if (!this.completionOptions.stop) {
this.completionOptions.stop = [];
}
this.completionOptions.stop.push(JSON.parse(value));
try {
this.completionOptions.stop.push(JSON.parse(value));
}
catch(e) {
console.warn('Error parsing stop parameter value "{value}: ${e}');
}
break;
default:
break;