mirror of
https://github.com/LLM-Red-Team/glm-free-api.git
synced 2024-09-21 04:04:24 +08:00
Compare commits
3 Commits
c70a4a4102
...
a695921e73
Author | SHA1 | Date | |
---|---|---|---|
|
a695921e73 | ||
|
50d07922c9 | ||
|
600a42938c |
@ -36,6 +36,7 @@ Moonshot AI(Kimi.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/) 等线上服务接入使用。
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user