diff --git a/src/providers/ai21/chatComplete.ts b/src/providers/ai21/chatComplete.ts index 89515f9c8..9ab0052cc 100644 --- a/src/providers/ai21/chatComplete.ts +++ b/src/providers/ai21/chatComplete.ts @@ -1,5 +1,5 @@ import { AI21 } from '../../globals'; -import { Params } from '../../types/requestBody'; +import { Params, SYSTEM_MESSAGE_ROLES } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -19,7 +19,10 @@ export const AI21ChatCompleteConfig: ProviderConfig = { transform: (params: Params) => { let inputMessages: any = []; - if (params.messages?.[0]?.role === 'system') { + if ( + params.messages?.[0]?.role && + SYSTEM_MESSAGE_ROLES.includes(params.messages?.[0]?.role) + ) { inputMessages = params.messages.slice(1); } else if (params.messages) { inputMessages = params.messages; @@ -35,7 +38,10 @@ export const AI21ChatCompleteConfig: ProviderConfig = { param: 'system', required: false, transform: (params: Params) => { - if (params.messages?.[0].role === 'system') { + if ( + params.messages?.[0]?.role && + SYSTEM_MESSAGE_ROLES.includes(params.messages?.[0]?.role) + ) { return params.messages?.[0].content; } }, diff --git a/src/providers/anthropic/chatComplete.ts b/src/providers/anthropic/chatComplete.ts index 540aeef3e..c9546badf 100644 --- a/src/providers/anthropic/chatComplete.ts +++ b/src/providers/anthropic/chatComplete.ts @@ -4,6 +4,7 @@ import { Message, ContentType, AnthropicPromptCache, + SYSTEM_MESSAGE_ROLES, } from '../../types/requestBody'; import { ChatCompletionResponse, @@ -111,7 +112,7 @@ export const AnthropicChatCompleteConfig: ProviderConfig = { // Transform the chat messages into a simple prompt if (!!params.messages) { params.messages.forEach((msg: Message & AnthropicPromptCache) => { - if (msg.role === 'system') return; + if (SYSTEM_MESSAGE_ROLES.includes(msg.role)) return; if (msg.role === 'assistant') { messages.push(transformAssistantMessage(msg)); @@ -188,7 +189,7 @@ export const AnthropicChatCompleteConfig: ProviderConfig = { if (!!params.messages) { params.messages.forEach((msg: Message & AnthropicPromptCache) => { if ( - msg.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(msg.role) && msg.content && typeof msg.content === 'object' && msg.content[0].text @@ -203,7 +204,7 @@ export const AnthropicChatCompleteConfig: ProviderConfig = { }); }); } else if ( - msg.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(msg.role) && typeof msg.content === 'string' ) { systemMessages.push({ diff --git a/src/providers/anyscale/chatComplete.ts b/src/providers/anyscale/chatComplete.ts index d8ab8e056..8bfc152d3 100644 --- a/src/providers/anyscale/chatComplete.ts +++ b/src/providers/anyscale/chatComplete.ts @@ -1,4 +1,5 @@ import { ANYSCALE } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -20,6 +21,12 @@ export const AnyscaleChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, functions: { param: 'functions', diff --git a/src/providers/azure-ai-inference/chatComplete.ts b/src/providers/azure-ai-inference/chatComplete.ts index 379282940..26cfb7699 100644 --- a/src/providers/azure-ai-inference/chatComplete.ts +++ b/src/providers/azure-ai-inference/chatComplete.ts @@ -1,3 +1,4 @@ +import { Params } from '../../types/requestBody'; import { OpenAIErrorResponseTransform } from '../openai/utils'; import { ChatCompletionResponse, @@ -14,6 +15,12 @@ export const AzureAIInferenceChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/bedrock/chatComplete.ts b/src/providers/bedrock/chatComplete.ts index 7ff8e97db..a972f751d 100644 --- a/src/providers/bedrock/chatComplete.ts +++ b/src/providers/bedrock/chatComplete.ts @@ -1,5 +1,10 @@ import { BEDROCK, documentMimeTypes, imagesMimeTypes } from '../../globals'; -import { Message, Params, ToolCall } from '../../types/requestBody'; +import { + Message, + Params, + ToolCall, + SYSTEM_MESSAGE_ROLES, +} from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -150,7 +155,7 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = { transform: (params: BedrockChatCompletionsParams) => { if (!params.messages) return []; const transformedMessages = params.messages - .filter((msg) => msg.role !== 'system') + .filter((msg) => !SYSTEM_MESSAGE_ROLES.includes(msg.role)) .map((msg) => { return { role: msg.role === 'assistant' ? 'assistant' : 'user', @@ -183,7 +188,7 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = { if (!params.messages) return; const systemMessages = params.messages.reduce( (acc: { text: string }[], msg) => { - if (msg.role === 'system') + if (SYSTEM_MESSAGE_ROLES.includes(msg.role)) return acc.concat(...getMessageTextContentArray(msg)); return acc; }, @@ -603,7 +608,7 @@ export const BedrockCohereChatCompleteConfig: ProviderConfig = { if (!!params.messages) { let messages: Message[] = params.messages; messages.forEach((msg, index) => { - if (index === 0 && msg.role === 'system') { + if (index === 0 && SYSTEM_MESSAGE_ROLES.includes(msg.role)) { prompt += `system: ${messages}\n`; } else if (msg.role == 'user') { prompt += `user: ${msg.content}\n`; @@ -787,7 +792,7 @@ export const BedrockAI21ChatCompleteConfig: ProviderConfig = { if (!!params.messages) { let messages: Message[] = params.messages; messages.forEach((msg, index) => { - if (index === 0 && msg.role === 'system') { + if (index === 0 && SYSTEM_MESSAGE_ROLES.includes(msg.role)) { prompt += `system: ${messages}\n`; } else if (msg.role == 'user') { prompt += `user: ${msg.content}\n`; diff --git a/src/providers/deepbricks/chatComplete.ts b/src/providers/deepbricks/chatComplete.ts index 90b532215..50bd9d1a5 100644 --- a/src/providers/deepbricks/chatComplete.ts +++ b/src/providers/deepbricks/chatComplete.ts @@ -1,4 +1,5 @@ import { DEEPBRICKS } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -17,6 +18,12 @@ export const DeepbricksChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, functions: { param: 'functions', diff --git a/src/providers/deepinfra/chatComplete.ts b/src/providers/deepinfra/chatComplete.ts index 91f3a2a22..cf7ae626b 100644 --- a/src/providers/deepinfra/chatComplete.ts +++ b/src/providers/deepinfra/chatComplete.ts @@ -1,4 +1,5 @@ import { DEEPINFRA } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -22,6 +23,12 @@ export const DeepInfraChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, frequency_penalty: { param: 'frequency_penalty', diff --git a/src/providers/deepseek/chatComplete.ts b/src/providers/deepseek/chatComplete.ts index 0f8ad25aa..9dc46ef8f 100644 --- a/src/providers/deepseek/chatComplete.ts +++ b/src/providers/deepseek/chatComplete.ts @@ -1,4 +1,5 @@ import { DEEPSEEK } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, @@ -19,6 +20,12 @@ export const DeepSeekChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/fireworks-ai/chatComplete.ts b/src/providers/fireworks-ai/chatComplete.ts index 78a3cfffb..92947fca1 100644 --- a/src/providers/fireworks-ai/chatComplete.ts +++ b/src/providers/fireworks-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { FIREWORKS_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -19,6 +20,12 @@ export const FireworksAIChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, tools: { param: 'tools', diff --git a/src/providers/google-vertex-ai/chatComplete.ts b/src/providers/google-vertex-ai/chatComplete.ts index c428e4bd6..ac55a3a22 100644 --- a/src/providers/google-vertex-ai/chatComplete.ts +++ b/src/providers/google-vertex-ai/chatComplete.ts @@ -8,6 +8,7 @@ import { Params, Tool, ToolCall, + SYSTEM_MESSAGE_ROLES, } from '../../types/requestBody'; import { AnthropicChatCompleteResponse, @@ -71,7 +72,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = { // From gemini-1.5 onwards, systemInstruction is supported // Skipping system message and sending it in systemInstruction for gemini 1.5 models if ( - message.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(message.role) && !SYSTEM_INSTRUCTION_DISABLED_MODELS.includes(params.model as string) ) return; @@ -186,7 +187,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = { if (!firstMessage) return; if ( - firstMessage.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) && typeof firstMessage.content === 'string' ) { return { @@ -200,7 +201,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = { } if ( - firstMessage.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) && typeof firstMessage.content === 'object' && firstMessage.content?.[0]?.text ) { @@ -413,7 +414,7 @@ export const VertexAnthropicChatCompleteConfig: ProviderConfig = { // Transform the chat messages into a simple prompt if (!!params.messages) { params.messages.forEach((msg) => { - if (msg.role === 'system') return; + if (SYSTEM_MESSAGE_ROLES.includes(msg.role)) return; if (msg.role === 'assistant') { messages.push(transformAssistantMessageForAnthropic(msg)); @@ -481,14 +482,14 @@ export const VertexAnthropicChatCompleteConfig: ProviderConfig = { if (!!params.messages) { params.messages.forEach((msg) => { if ( - msg.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(msg.role) && msg.content && typeof msg.content === 'object' && msg.content[0].text ) { systemMessage = msg.content[0].text; } else if ( - msg.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(msg.role) && typeof msg.content === 'string' ) { systemMessage = msg.content; diff --git a/src/providers/google/chatComplete.ts b/src/providers/google/chatComplete.ts index 44937db3f..2bb01e15d 100644 --- a/src/providers/google/chatComplete.ts +++ b/src/providers/google/chatComplete.ts @@ -6,6 +6,7 @@ import { Params, ToolCall, ToolChoice, + SYSTEM_MESSAGE_ROLES, } from '../../types/requestBody'; import { buildGoogleSearchRetrievalTool } from '../google-vertex-ai/chatComplete'; import { derefer, getMimeType } from '../google-vertex-ai/utils'; @@ -152,7 +153,7 @@ export const GoogleChatCompleteConfig: ProviderConfig = { // From gemini-1.5 onwards, systemInstruction is supported // Skipping system message and sending it in systemInstruction for gemini 1.5 models if ( - message.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(message.role) && !SYSTEM_INSTRUCTION_DISABLED_MODELS.includes(params.model as string) ) return; @@ -261,7 +262,7 @@ export const GoogleChatCompleteConfig: ProviderConfig = { if (!firstMessage) return; if ( - firstMessage.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) && typeof firstMessage.content === 'string' ) { return { @@ -275,7 +276,7 @@ export const GoogleChatCompleteConfig: ProviderConfig = { } if ( - firstMessage.role === 'system' && + SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) && typeof firstMessage.content === 'object' && firstMessage.content?.[0]?.text ) { diff --git a/src/providers/huggingface/chatComplete.ts b/src/providers/huggingface/chatComplete.ts index e78e8b719..bfdf4a31e 100644 --- a/src/providers/huggingface/chatComplete.ts +++ b/src/providers/huggingface/chatComplete.ts @@ -1,4 +1,5 @@ import { HUGGING_FACE } from '../../globals'; +import { Params } from '../../types/requestBody'; import { OpenAIErrorResponseTransform } from '../openai/utils'; import { ChatCompletionResponse, @@ -18,6 +19,12 @@ export const HuggingfaceChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, functions: { param: 'functions', diff --git a/src/providers/lingyi/chatComplete.ts b/src/providers/lingyi/chatComplete.ts index 0d45622a6..6928c3f04 100644 --- a/src/providers/lingyi/chatComplete.ts +++ b/src/providers/lingyi/chatComplete.ts @@ -1,4 +1,5 @@ import { LINGYI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -18,6 +19,12 @@ export const LingyiChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/mistral-ai/chatComplete.ts b/src/providers/mistral-ai/chatComplete.ts index 3e310cb84..7a118e63d 100644 --- a/src/providers/mistral-ai/chatComplete.ts +++ b/src/providers/mistral-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { MISTRAL_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -18,6 +19,12 @@ export const MistralAIChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, temperature: { param: 'temperature', diff --git a/src/providers/monsterapi/chatComplete.ts b/src/providers/monsterapi/chatComplete.ts index fd3094693..4fc6ee354 100644 --- a/src/providers/monsterapi/chatComplete.ts +++ b/src/providers/monsterapi/chatComplete.ts @@ -1,4 +1,5 @@ import { MONSTERAPI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -47,6 +48,12 @@ export const MonsterAPIChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, }; diff --git a/src/providers/moonshot/chatComplete.ts b/src/providers/moonshot/chatComplete.ts index 69f417095..0a99395e5 100644 --- a/src/providers/moonshot/chatComplete.ts +++ b/src/providers/moonshot/chatComplete.ts @@ -1,4 +1,5 @@ import { MOONSHOT } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, @@ -19,6 +20,12 @@ export const MoonshotChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/novita-ai/chatComplete.ts b/src/providers/novita-ai/chatComplete.ts index ec892bb38..5c39a1cfa 100644 --- a/src/providers/novita-ai/chatComplete.ts +++ b/src/providers/novita-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { NOVITA_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -21,6 +22,12 @@ export const NovitaAIChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/ollama/chatComplete.ts b/src/providers/ollama/chatComplete.ts index 0451f2370..a1fea1fe7 100644 --- a/src/providers/ollama/chatComplete.ts +++ b/src/providers/ollama/chatComplete.ts @@ -8,6 +8,7 @@ import { generateErrorResponse, generateInvalidProviderResponseError, } from '../utils'; +import { Params } from '../../types/requestBody'; export const OllamaChatCompleteConfig: ProviderConfig = { model: { @@ -18,6 +19,12 @@ export const OllamaChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, frequency_penalty: { param: 'frequency_penalty', diff --git a/src/providers/open-ai-base/index.ts b/src/providers/open-ai-base/index.ts index 91d3fbe49..7392c4c25 100644 --- a/src/providers/open-ai-base/index.ts +++ b/src/providers/open-ai-base/index.ts @@ -1,5 +1,6 @@ import { OPEN_AI } from '../../globals'; import { EmbedResponse } from '../../types/embedRequestBody'; +import { Params } from '../../types/requestBody'; import { OpenAIChatCompleteResponse } from '../openai/chatComplete'; import { OpenAICompleteResponse } from '../openai/complete'; import { OpenAIErrorResponseTransform } from '../openai/utils'; @@ -51,6 +52,13 @@ export const chatCompleteParams = ( messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') + return { ...message, role: 'system' }; + return message; + }); + }, }, functions: { param: 'functions', diff --git a/src/providers/openrouter/chatComplete.ts b/src/providers/openrouter/chatComplete.ts index 280b09c90..7b97e67ba 100644 --- a/src/providers/openrouter/chatComplete.ts +++ b/src/providers/openrouter/chatComplete.ts @@ -1,4 +1,5 @@ import { OPENROUTER } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -18,6 +19,12 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/palm/chatComplete.ts b/src/providers/palm/chatComplete.ts index 7b4fa48c7..046e0537e 100644 --- a/src/providers/palm/chatComplete.ts +++ b/src/providers/palm/chatComplete.ts @@ -26,7 +26,7 @@ export const PalmChatCompleteConfig: ProviderConfig = { transform: (params: Params) => { const { examples, context, messages } = params; const palmMessages = messages?.map((message) => ({ - author: message.role, + author: message.role === 'developer' ? 'system' : message.role, content: message.content, })); const prompt = { diff --git a/src/providers/perplexity-ai/chatComplete.ts b/src/providers/perplexity-ai/chatComplete.ts index 57ee8598f..543dd5f2d 100644 --- a/src/providers/perplexity-ai/chatComplete.ts +++ b/src/providers/perplexity-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { PERPLEXITY_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -21,6 +22,12 @@ export const PerplexityAIChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/predibase/chatComplete.ts b/src/providers/predibase/chatComplete.ts index e3e68372b..b3047fe21 100644 --- a/src/providers/predibase/chatComplete.ts +++ b/src/providers/predibase/chatComplete.ts @@ -1,4 +1,5 @@ import { PREDIBASE } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -28,6 +29,12 @@ export const PredibaseChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: [], + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/siliconflow/chatComplete.ts b/src/providers/siliconflow/chatComplete.ts index b2708a9d3..dc6186671 100644 --- a/src/providers/siliconflow/chatComplete.ts +++ b/src/providers/siliconflow/chatComplete.ts @@ -1,4 +1,5 @@ import { SILICONFLOW } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -15,6 +16,12 @@ export const SiliconFlowChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/together-ai/chatComplete.ts b/src/providers/together-ai/chatComplete.ts index 60a2166c6..b405c8a8c 100644 --- a/src/providers/together-ai/chatComplete.ts +++ b/src/providers/together-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { TOGETHER_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -21,6 +22,12 @@ export const TogetherAIChatCompleteConfig: ProviderConfig = { param: 'messages', required: true, default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/providers/workers-ai/chatComplete.ts b/src/providers/workers-ai/chatComplete.ts index ae7c763ab..0d0760b27 100644 --- a/src/providers/workers-ai/chatComplete.ts +++ b/src/providers/workers-ai/chatComplete.ts @@ -1,4 +1,5 @@ import { WORKERS_AI } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -13,6 +14,12 @@ export const WorkersAiChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, stream: { param: 'stream', diff --git a/src/providers/zhipu/chatComplete.ts b/src/providers/zhipu/chatComplete.ts index 6a3363eec..500b75409 100644 --- a/src/providers/zhipu/chatComplete.ts +++ b/src/providers/zhipu/chatComplete.ts @@ -1,4 +1,5 @@ import { ZHIPU } from '../../globals'; +import { Params } from '../../types/requestBody'; import { ChatCompletionResponse, ErrorResponse, @@ -18,6 +19,12 @@ export const ZhipuChatCompleteConfig: ProviderConfig = { messages: { param: 'messages', default: '', + transform: (params: Params) => { + return params.messages?.map((message) => { + if (message.role === 'developer') return { ...message, role: 'system' }; + return message; + }); + }, }, max_tokens: { param: 'max_tokens', diff --git a/src/types/requestBody.ts b/src/types/requestBody.ts index 272a7b3aa..4f7833dd1 100644 --- a/src/types/requestBody.ts +++ b/src/types/requestBody.ts @@ -217,15 +217,18 @@ export enum MESSAGE_ROLES { ASSISTANT = 'assistant', FUNCTION = 'function', TOOL = 'tool', + DEVELOPER = 'developer', } +export const SYSTEM_MESSAGE_ROLES = ['system', 'developer']; + export type OpenAIMessageRole = | 'system' | 'user' | 'assistant' | 'function' - | 'tool'; - + | 'tool' + | 'developer'; /** * A message in the conversation. * @interface