🐛 fix lm studio bug when empty messages are sent

This commit is contained in:
Nate Sesti 2024-01-28 14:47:45 -08:00
parent 38151b84ad
commit 8b9e99a8a1

View file

@ -178,6 +178,15 @@ class OpenAI extends BaseLLM {
return;
}
let body = {
...this._convertArgs(options, messages),
stream: true,
};
// Empty messages cause an error in LM Studio
body.messages = body.messages.map((m) => ({
...m,
content: m.content === "" ? " " : m.content,
})) as any;
const response = await this.fetch(this._getChatUrl(), {
method: "POST",
headers: {
@ -185,10 +194,7 @@ class OpenAI extends BaseLLM {
Authorization: `Bearer ${this.apiKey}`,
"api-key": this.apiKey || "", // For Azure
},
body: JSON.stringify({
...this._convertArgs(options, messages),
stream: true,
}),
body: JSON.stringify(body),
});
for await (const value of streamSse(response)) {