From cc0ea384a7e95c7f1429d21d2e9b5afd74c6fe6b Mon Sep 17 00:00:00 2001 From: Vinlic Date: Sun, 10 Mar 2024 14:42:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Durl=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/api/controllers/chat.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3c4266..5b4b3a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 5246c3f..4013e01 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -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}`); +} + function checkResult(result: AxiosResponse, refreshToken: string) { if(result.status == 401) { accessTokenMap.delete(refreshToken);