mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-12-23 08:09:20 +08:00
支持多路refresh_token
This commit is contained in:
parent
17809274a5
commit
4949b16091
13
README.md
13
README.md
@ -5,7 +5,7 @@
|
|||||||
![](https://img.shields.io/github/forks/llm-red-team/kimi-free-api.svg)
|
![](https://img.shields.io/github/forks/llm-red-team/kimi-free-api.svg)
|
||||||
![](https://img.shields.io/docker/pulls/vinlic/kimi-free-api.svg)
|
![](https://img.shields.io/docker/pulls/vinlic/kimi-free-api.svg)
|
||||||
|
|
||||||
支持高速流式输出、支持多轮对话、支持联网搜索、支持长文档解读、支持图像解析,零配置部署,自动清理会话痕迹。
|
支持高速流式输出、支持多轮对话、支持联网搜索、支持长文档解读、支持图像解析,零配置部署,多路token支持,自动清理会话痕迹。
|
||||||
|
|
||||||
与ChatGPT接口完全兼容。
|
与ChatGPT接口完全兼容。
|
||||||
|
|
||||||
@ -15,6 +15,7 @@
|
|||||||
* [在线体验](#在线体验)
|
* [在线体验](#在线体验)
|
||||||
* [效果示例](#效果示例)
|
* [效果示例](#效果示例)
|
||||||
* [接入准备](#接入准备)
|
* [接入准备](#接入准备)
|
||||||
|
* [多账号接入](#多账号接入)
|
||||||
* [Docker部署](#Docker部署)
|
* [Docker部署](#Docker部署)
|
||||||
* [Docker-compose部署](#Docker-compose部署)
|
* [Docker-compose部署](#Docker-compose部署)
|
||||||
* [原生部署](#原生部署)
|
* [原生部署](#原生部署)
|
||||||
@ -69,10 +70,18 @@ https://udify.app/chat/Po0F6BMJ15q5vu2P
|
|||||||
|
|
||||||
从 [kimi.moonshot.cn](https://kimi.moonshot.cn) 获取refresh_token
|
从 [kimi.moonshot.cn](https://kimi.moonshot.cn) 获取refresh_token
|
||||||
|
|
||||||
进入kimi随便发起一个对话,然后F12打开开发者工具,从Application > Local Storage中找到refresh_token的值,这将作为Authorization的Bearer KEY值。
|
进入kimi随便发起一个对话,然后F12打开开发者工具,从Application > Local Storage中找到refresh_token的值,这将作为Authorization的Bearer Token值:`Authorization: Bearer TOKEN`
|
||||||
|
|
||||||
![example0](./doc/example-0.png)
|
![example0](./doc/example-0.png)
|
||||||
|
|
||||||
|
### 多账号接入
|
||||||
|
|
||||||
|
目前kimi限制普通账号每3小时内只能进行30轮长文本的问答,你可以通过提供多个账号的refresh_token并使用`,`拼接提供:
|
||||||
|
|
||||||
|
`Authorization: Bearer TOKEN1,TOKEN2,TOKEN3`
|
||||||
|
|
||||||
|
每次请求服务会从中挑选一个。
|
||||||
|
|
||||||
## Docker部署
|
## Docker部署
|
||||||
|
|
||||||
请准备一台具有公网IP的服务器并将8000端口开放。
|
请准备一台具有公网IP的服务器并将8000端口开放。
|
||||||
|
@ -619,8 +619,18 @@ function createTransStream(convId: string, stream: any, endCallback?: Function)
|
|||||||
return transStream;
|
return transStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token切分
|
||||||
|
*
|
||||||
|
* @param authorization 认证字符串
|
||||||
|
*/
|
||||||
|
function tokenSplit(authorization: string) {
|
||||||
|
return authorization.replace('Bearer ', '').split(',');
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
createConversation,
|
createConversation,
|
||||||
createCompletion,
|
createCompletion,
|
||||||
createCompletionStream
|
createCompletionStream,
|
||||||
|
tokenSplit
|
||||||
};
|
};
|
||||||
|
@ -15,17 +15,19 @@ export default {
|
|||||||
request
|
request
|
||||||
.validate('body.messages', _.isArray)
|
.validate('body.messages', _.isArray)
|
||||||
.validate('headers.authorization', _.isString)
|
.validate('headers.authorization', _.isString)
|
||||||
const token = request.headers.authorization;
|
// refresh_token切分
|
||||||
const refreshToken = token.replace('Bearer ', '');
|
const tokens = chat.tokenSplit(request.headers.authorization);
|
||||||
|
// 随机挑选一个refresh_token
|
||||||
|
const token = _.sample(tokens);
|
||||||
const messages = request.body.messages;
|
const messages = request.body.messages;
|
||||||
if (request.body.stream) {
|
if (request.body.stream) {
|
||||||
const stream = await chat.createCompletionStream(request.body.messages, refreshToken, request.body.use_search);
|
const stream = await chat.createCompletionStream(request.body.messages, token, request.body.use_search);
|
||||||
return new Response(stream, {
|
return new Response(stream, {
|
||||||
type: "text/event-stream"
|
type: "text/event-stream"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return await chat.createCompletion(messages, refreshToken, request.body.use_search);
|
return await chat.createCompletion(messages, token, request.body.use_search);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user