mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-12-22 21:09:20 +08:00
修复多轮对话
This commit is contained in:
parent
399242b09e
commit
6284628d99
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user