🦙 fix: Ollama System Message order (#2655)

This commit is contained in:
Danny Avila 2024-05-10 00:50:02 -04:00 committed by GitHub
parent 8f20fb28e5
commit 98c96cd020
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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'));
@ -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');
@ -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,