Compare commits

...

3 Commits

Author SHA1 Message Date
Vinlic科技 a695921e73
Update README.md 2024-04-26 16:56:11 +08:00
Vinlic 50d07922c9 Release 0.0.25 2024-04-26 16:20:04 +08:00
Vinlic 600a42938c 修复多轮对话时文件传送角色错配,抹除临时文件路径减少多轮幻觉 2024-04-26 16:19:57 +08:00
3 changed files with 24 additions and 13 deletions

View File

@ -36,6 +36,7 @@ Moonshot AIKimi.ai接口转API [kimi-free-api](https://github.com/LLM-Red-
* [Render部署](#Render部署)
* [Vercel部署](#Vercel部署)
* [原生部署](#原生部署)
* [推荐使用客户端](#推荐使用客户端)
* [接口列表](#接口列表)
* [对话补全](#对话补全)
* [AI绘图](#AI绘图)
@ -248,6 +249,14 @@ pm2 reload glm-free-api
pm2 stop glm-free-api
```
## 推荐使用客户端
使用以下二次开发客户端接入free-api系列项目更快更简单支持文档/图像上传!
由 [Clivia](https://github.com/Yanyutin753/lobe-chat) 二次开发的LobeChat [https://github.com/Yanyutin753/lobe-chat](https://github.com/Yanyutin753/lobe-chat)
由 [时光@](https://github.com/SuYxh) 二次开发的ChatGPT Web [https://github.com/SuYxh/chatgpt-web-sea](https://github.com/SuYxh/chatgpt-web-sea)
## 接口列表
目前支持与openai兼容的 `/v1/chat/completions` 接口可自行使用与openai或其他兼容的客户端接入接口或者使用 [dify](https://dify.ai/) 等线上服务接入使用。

View File

@ -1,6 +1,6 @@
{
"name": "glm-free-api",
"version": "0.0.24",
"version": "0.0.25",
"description": "GLM Free API Server",
"type": "module",
"main": "dist/index.js",

View File

@ -486,10 +486,6 @@ function extractRefFileUrls(messages: any[]) {
*
*
*
* 使\n
* :旧消息1
* :旧消息2
* :新消息
*
* @param messages gpt系列消息格式
*/
@ -520,20 +516,25 @@ function messagesPrepare(messages: any[], refs: any[]) {
const content = (
messages.reduce((content, message) => {
const role = message.role
.replace("system", "<|sytstem|>")
.replace("assistant", "<|assistant|>")
.replace("user", "<|user|>");
if (_.isArray(message.content)) {
return (
message.content.reduce((_content, v) => {
if (!_.isObject(v) || v["type"] != "text") return _content;
return _content + ("<|user|>\n" + v["text"] || "") + "\n";
return _content + (`${role}\n` + v["text"] || "") + "\n";
}, content)
);
}
return (content += `${message.role
.replace("system", "<|sytstem|>")
.replace("assistant", "<|assistant|>")
.replace("user", "<|user|>")}\n${message.content}\n`);
return (content += `${role}\n${message.content}\n`);
}, "") + "<|assistant|>\n"
).replace(/\!\[.+\]\(.+\)/g, "");
)
// 移除MD图像URL避免幻觉
.replace(/\!\[.+\]\(.+\)/g, "")
// 移除临时路径避免在新会话引发幻觉
.replace(/\/mnt\/data\/.+/g, "");
const fileRefs = refs.filter((ref) => !ref.width && !ref.height);
const imageRefs = refs
.filter((ref) => ref.width || ref.height)
@ -541,6 +542,7 @@ function messagesPrepare(messages: any[], refs: any[]) {
ref.image_url = ref.file_url;
return ref;
});
content
logger.info("\n对话合并\n" + content);
return [
{
@ -1062,7 +1064,7 @@ async function receiveImages(
let match;
while ((match = urlPattern.exec(text)) !== null) {
const url = match[1];
if(imageUrls.indexOf(url) == -1)
if (imageUrls.indexOf(url) == -1)
imageUrls.push(url);
}
}
@ -1141,7 +1143,7 @@ async function getTokenLiveStatus(refreshToken: string) {
const { accessToken } = _result;
return !!accessToken;
}
catch(err) {
catch (err) {
return false;
}
}