diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 53ba25d..5246c3f 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -85,7 +85,7 @@ async function createCompletion(messages: any[], refreshToken: string, useSearch const convId = await createConversation(`cmpl-${util.uuid(false)}`, refreshToken); const token = await acquireToken(refreshToken); const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, { - messages, + messages: messagesPrepare(messages), use_search: useSearch }, { headers: { @@ -107,7 +107,7 @@ async function createCompletionStream(messages: any[], refreshToken: string, use const convId = await createConversation(`cmpl-${util.uuid(false)}`, refreshToken); const token = await acquireToken(refreshToken); const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, { - messages, + messages: messagesPrepare(messages), use_search: useSearch }, { headers: { @@ -124,6 +124,15 @@ async function createCompletionStream(messages: any[], refreshToken: string, use }); } +function messagesPrepare(messages: any[]) { + const content = messages.reduce((content, message) => { + return content += `${message.role || 'user'}:${message.content}\n`; + }, ''); + return [ + { role: 'user', content } + ] +} + function checkResult(result: AxiosResponse, refreshToken: string) { if(result.status == 401) { accessTokenMap.delete(refreshToken);