From 407b0830c8ea3dc734c2869a508b8d4abb8ac691 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sat, 17 Aug 2024 02:18:57 +0900 Subject: [PATCH] Fix claude compatibility for custom --- src/ts/process/request.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index e01452c7..1e0e6c82 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -1687,6 +1687,11 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' content: Claude3ContentBlock[] } + interface Claude3ExtendedChat { + role: 'user'|'assistant' + content: Claude3ContentBlock[]|string + } + let claudeChat: Claude3Chat[] = [] let systemPrompt:string = '' @@ -1854,10 +1859,23 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' } } + let finalChat:Claude3ExtendedChat[] = claudeChat + + if(aiModel === 'reverse_proxy'){ + finalChat = claudeChat.map((v) => { + if(v.content.length === 0 && v.content[0].type === 'text'){ + return { + role: v.role, + content: v.content[0].text + } + } + }) + } + let body = { model: raiModel, - messages: claudeChat, + messages: finalChat, system: systemPrompt.trim(), max_tokens: maxTokens, temperature: temperature, @@ -2037,9 +2055,12 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' }] }) } - const block = body.messages[body.messages.length-1].content[0] - if(block.type === 'text'){ - block.text += text + let block = body.messages[body.messages.length-1].content + if(typeof block === 'string'){ + body.messages[body.messages.length-1].content += text + } + else if(block[0].type === 'text'){ + block[0].text += text } const res = await fetchNative(replacerURL, { body: JSON.stringify(body),