mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-12-23 02:49:19 +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 convId = await createConversation(`cmpl-${util.uuid(false)}`, refreshToken);
|
||||||
const token = await acquireToken(refreshToken);
|
const token = await acquireToken(refreshToken);
|
||||||
const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, {
|
const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, {
|
||||||
messages,
|
messages: messagesPrepare(messages),
|
||||||
use_search: useSearch
|
use_search: useSearch
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -107,7 +107,7 @@ async function createCompletionStream(messages: any[], refreshToken: string, use
|
|||||||
const convId = await createConversation(`cmpl-${util.uuid(false)}`, refreshToken);
|
const convId = await createConversation(`cmpl-${util.uuid(false)}`, refreshToken);
|
||||||
const token = await acquireToken(refreshToken);
|
const token = await acquireToken(refreshToken);
|
||||||
const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, {
|
const result = await axios.post(`https://kimi.moonshot.cn/api/chat/${convId}/completion/stream`, {
|
||||||
messages,
|
messages: messagesPrepare(messages),
|
||||||
use_search: useSearch
|
use_search: useSearch
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
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) {
|
function checkResult(result: AxiosResponse, refreshToken: string) {
|
||||||
if(result.status == 401) {
|
if(result.status == 401) {
|
||||||
accessTokenMap.delete(refreshToken);
|
accessTokenMap.delete(refreshToken);
|
||||||
|
Loading…
Reference in New Issue
Block a user