Skip to content

Commit

Permalink
🦙 fix: Ollama System Message order (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored May 10, 2024
1 parent 8f20fb2 commit 98c96cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/app/clients/OpenAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class OpenAIClient extends BaseClient {
this.useOpenRouter = true;
}

if (this.options.endpoint?.toLowerCase() === 'ollama') {
this.isOllama = true;
}

this.FORCE_PROMPT =
isEnabled(OPENAI_FORCE_PROMPT) ||
(reverseProxy && reverseProxy.includes('completions') && !reverseProxy.includes('chat'));
Expand Down Expand Up @@ -1121,7 +1125,7 @@ ${convo}
});

/* Re-orders system message to the top of the messages payload, as not allowed anywhere else */
if (opts.baseURL.includes('api.mistral.ai') && modelOptions.messages) {
if (modelOptions.messages && (opts.baseURL.includes('api.mistral.ai') || this.isOllama)) {
const { messages } = modelOptions;

const systemMessageIndex = messages.findIndex((msg) => msg.role === 'system');
Expand Down Expand Up @@ -1165,7 +1169,7 @@ ${convo}
});
}

if (this.message_file_map && this.options.endpoint?.toLowerCase() === 'ollama') {
if (this.message_file_map && this.isOllama) {
const ollamaClient = new OllamaClient({ baseURL });
return await ollamaClient.chatCompletion({
payload: modelOptions,
Expand Down

0 comments on commit 98c96cd

Please sign in to comment.