mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-11-01 18:29:19 +08:00
Compare commits
No commits in common. "6105410dd2880ee0d0ce981660bc2e77fa9cfb07" and "82a835963433c8e72a54382e0e34a4977d1c5fb1" have entirely different histories.
6105410dd2
...
82a8359634
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kimi-free-api",
|
"name": "kimi-free-api",
|
||||||
"version": "0.0.32",
|
"version": "0.0.31",
|
||||||
"description": "Kimi Free API Server",
|
"description": "Kimi Free API Server",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -261,6 +261,11 @@ async function createCompletion(model = MODEL_NAME, messages: any[], refreshToke
|
|||||||
userId
|
userId
|
||||||
} = await acquireToken(refreshToken);
|
} = await acquireToken(refreshToken);
|
||||||
const sendMessages = messagesPrepare(messages, !!refConvId);
|
const sendMessages = messagesPrepare(messages, !!refConvId);
|
||||||
|
console.log(convId, {
|
||||||
|
messages: sendMessages,
|
||||||
|
refs,
|
||||||
|
use_search: useSearch
|
||||||
|
});
|
||||||
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: sendMessages,
|
messages: sendMessages,
|
||||||
refs,
|
refs,
|
||||||
@ -456,25 +461,12 @@ function extractRefFileUrls(messages: any[]) {
|
|||||||
* @param isRefConv 是否为引用会话
|
* @param isRefConv 是否为引用会话
|
||||||
*/
|
*/
|
||||||
function messagesPrepare(messages: any[], isRefConv = false) {
|
function messagesPrepare(messages: any[], isRefConv = false) {
|
||||||
let content;
|
|
||||||
if (isRefConv || messages.length < 2) {
|
|
||||||
content = messages.reduce((content, message) => {
|
|
||||||
if (_.isArray(message.content)) {
|
|
||||||
return message.content.reduce((_content, v) => {
|
|
||||||
if (!_.isObject(v) || v['type'] != 'text') return _content;
|
|
||||||
return _content + `${v["text"] || ""}\n`;
|
|
||||||
}, content);
|
|
||||||
}
|
|
||||||
return content += `${message.role == 'user' ? wrapUrlsToTags(message.content) : message.content}\n`;
|
|
||||||
}, '')
|
|
||||||
logger.info("\n透传内容:\n" + content);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 注入消息提升注意力
|
// 注入消息提升注意力
|
||||||
let latestMessage = messages[messages.length - 1];
|
let latestMessage = messages[messages.length - 1];
|
||||||
let hasFileOrImage = Array.isArray(latestMessage.content)
|
let hasFileOrImage = Array.isArray(latestMessage.content)
|
||||||
&& latestMessage.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type'])));
|
&& latestMessage.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type'])));
|
||||||
// 第二轮开始注入system prompt
|
// 第二轮开始注入system prompt
|
||||||
|
if (messages.length > 2) {
|
||||||
if (hasFileOrImage) {
|
if (hasFileOrImage) {
|
||||||
let newFileMessage = {
|
let newFileMessage = {
|
||||||
"content": "关注用户最新发送文件和消息",
|
"content": "关注用户最新发送文件和消息",
|
||||||
@ -490,6 +482,22 @@ function messagesPrepare(messages: any[], isRefConv = false) {
|
|||||||
messages.splice(messages.length - 1, 0, newTextMessage);
|
messages.splice(messages.length - 1, 0, newTextMessage);
|
||||||
logger.info("注入提升尾部消息注意力system prompt");
|
logger.info("注入提升尾部消息注意力system prompt");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let content;
|
||||||
|
if (isRefConv || messages.length < 2) {
|
||||||
|
content = messages.reduce((content, message) => {
|
||||||
|
if (_.isArray(message.content)) {
|
||||||
|
return message.content.reduce((_content, v) => {
|
||||||
|
if (!_.isObject(v) || v['type'] != 'text') return _content;
|
||||||
|
return _content + `${v["text"] || ""}\n`;
|
||||||
|
}, content);
|
||||||
|
}
|
||||||
|
return content += `${message.role == 'user' ? wrapUrlsToTags(message.content) : message.content}\n`;
|
||||||
|
}, '')
|
||||||
|
logger.info("\n透传内容:\n" + content);
|
||||||
|
}
|
||||||
|
else {
|
||||||
content = messages.reduce((content, message) => {
|
content = messages.reduce((content, message) => {
|
||||||
if (_.isArray(message.content)) {
|
if (_.isArray(message.content)) {
|
||||||
return message.content.reduce((_content, v) => {
|
return message.content.reduce((_content, v) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user