Skip to content

Commit

Permalink
修复url解析
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Mar 10, 2024
1 parent 6284628 commit cc0ea38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kimi-free-api",
"version": "0.0.3",
"version": "0.0.5",
"description": "Kimi Free Server",
"type": "module",
"main": "dist/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ 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 content += `${message.role || 'user'}:${wrapUrlsToTags(message.content)}\n`;
}, '');
return [
{ role: 'user', content }
]
}

function wrapUrlsToTags(content: string) {
return content.replace(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi, url => `<url id="" type="url" status="" title="" wc="">${url}</url>`);
}

function checkResult(result: AxiosResponse, refreshToken: string) {
if(result.status == 401) {
accessTokenMap.delete(refreshToken);
Expand Down

0 comments on commit cc0ea38

Please sign in to comment.