forked from labring/FastGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'c121914yu:main' into main
- Loading branch information
Showing
61 changed files
with
1,287 additions
and
1,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
### Fast GPT V3.8.4 | ||
### Fast GPT V3.8.8 | ||
|
||
1. 新增 - mermaid 导图兼容,可以在应用市场 'mermaid 导图' 进行体验。 | ||
2. 优化 - 部分 UI 和账号页。 | ||
2. 优化 - 知识库搜索速度 | ||
1. 新增 - V2 版 OpenAPI,可以在任意第三方套壳 ChatGpt 项目中直接使用 FastGpt 的应用,注意!是直接,不需要改任何代码。具体参考[API 文档中《在第三方应用中使用 FastGpt》](https://kjqvjse66l.feishu.cn/docx/DmLedTWtUoNGX8xui9ocdUEjnNh) | ||
2. 新增 - 应用配置最大回复长度。 | ||
3. 新增 - 更多的知识库配置项:相似度、最大搜索数量、自定义空搜索结果回复。 | ||
4. 新增 - 知识库搜索测试,方便调试。 | ||
5. 优化 - 知识库提示词位置,拥有更强的引导。 | ||
6. 优化 - 应用编辑页面。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var _hmt = _hmt || []; | ||
|
||
(function () { | ||
const hm = document.createElement('script'); | ||
hm.src = 'https://hm.baidu.com/hm.js?a5357e9dab086658bac0b6faf148882e'; | ||
const s = document.getElementsByTagName('script')[0]; | ||
s.parentNode.insertBefore(hm, s); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,104 @@ | ||
import { GUIDE_PROMPT_HEADER, NEW_CHATID_HEADER, QUOTE_LEN_HEADER } from '@/constants/chat'; | ||
import { Props, ChatResponseType } from '@/pages/api/openapi/v1/chat/completions'; | ||
import { sseResponseEventEnum } from '@/constants/chat'; | ||
import { getErrText } from '@/utils/tools'; | ||
|
||
interface StreamFetchProps { | ||
url: string; | ||
data: any; | ||
data: Props; | ||
onMessage: (text: string) => void; | ||
abortSignal: AbortController; | ||
} | ||
export const streamFetch = ({ url, data, onMessage, abortSignal }: StreamFetchProps) => | ||
new Promise<{ | ||
responseText: string; | ||
newChatId: string; | ||
systemPrompt: string; | ||
quoteLen: number; | ||
}>(async (resolve, reject) => { | ||
export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps) => | ||
new Promise<ChatResponseType & { responseText: string }>(async (resolve, reject) => { | ||
try { | ||
const res = await fetch(url, { | ||
const response = await window.fetch('/api/openapi/v1/chat/completions', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(data), | ||
signal: abortSignal.signal | ||
signal: abortSignal.signal, | ||
body: JSON.stringify({ | ||
...data, | ||
stream: true | ||
}) | ||
}); | ||
const reader = res.body?.getReader(); | ||
if (!reader) return; | ||
|
||
const decoder = new TextDecoder(); | ||
if (!response?.body) { | ||
throw new Error('Request Error'); | ||
} | ||
|
||
const newChatId = decodeURIComponent(res.headers.get(NEW_CHATID_HEADER) || ''); | ||
const systemPrompt = decodeURIComponent(res.headers.get(GUIDE_PROMPT_HEADER) || '').trim(); | ||
const quoteLen = res.headers.get(QUOTE_LEN_HEADER) | ||
? Number(res.headers.get(QUOTE_LEN_HEADER)) | ||
: 0; | ||
const reader = response.body?.getReader(); | ||
const decoder = new TextDecoder('utf-8'); | ||
|
||
// response data | ||
let responseText = ''; | ||
let newChatId = ''; | ||
let quoteLen = 0; | ||
|
||
const read = async () => { | ||
try { | ||
const { done, value } = await reader?.read(); | ||
const { done, value } = await reader.read(); | ||
if (done) { | ||
if (res.status === 200) { | ||
resolve({ responseText, newChatId, quoteLen, systemPrompt }); | ||
if (response.status === 200) { | ||
return resolve({ | ||
responseText, | ||
newChatId, | ||
quoteLen | ||
}); | ||
} else { | ||
const parseError = JSON.parse(responseText); | ||
reject(parseError?.message || '请求异常'); | ||
return reject('响应过程出现异常~'); | ||
} | ||
|
||
return; | ||
} | ||
const text = decoder.decode(value); | ||
responseText += text; | ||
onMessage(text); | ||
const chunk = decoder.decode(value); | ||
const chunkLines = chunk.split('\n\n').filter((item) => item); | ||
const chunkResponse = chunkLines.map((item) => { | ||
const splitEvent = item.split('\n'); | ||
if (splitEvent.length === 2) { | ||
return { | ||
event: splitEvent[0].replace('event: ', ''), | ||
data: splitEvent[1].replace('data: ', '') | ||
}; | ||
} | ||
return { | ||
event: '', | ||
data: splitEvent[0].replace('data: ', '') | ||
}; | ||
}); | ||
|
||
chunkResponse.forEach((item) => { | ||
// parse json data | ||
const data = (() => { | ||
try { | ||
return JSON.parse(item.data); | ||
} catch (error) { | ||
return item.data; | ||
} | ||
})(); | ||
|
||
if (item.event === sseResponseEventEnum.answer && data !== '[DONE]') { | ||
const answer: string = data?.choices?.[0].delta.content || ''; | ||
onMessage(answer); | ||
responseText += answer; | ||
} else if (item.event === sseResponseEventEnum.chatResponse) { | ||
const chatResponse = data as ChatResponseType; | ||
newChatId = chatResponse.newChatId; | ||
quoteLen = chatResponse.quoteLen || 0; | ||
} | ||
}); | ||
read(); | ||
} catch (err: any) { | ||
if (err?.message === 'The user aborted a request.') { | ||
return resolve({ responseText, newChatId, quoteLen, systemPrompt }); | ||
return resolve({ | ||
responseText, | ||
newChatId, | ||
quoteLen | ||
}); | ||
} | ||
reject(typeof err === 'string' ? err : err?.message || '请求异常'); | ||
reject(getErrText(err, '请求异常')); | ||
} | ||
}; | ||
read(); | ||
} catch (err: any) { | ||
console.log(err, '===='); | ||
reject(typeof err === 'string' ? err : err?.message || '请求异常'); | ||
reject(getErrText(err, '请求异常')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { Box } from '@chakra-ui/react'; | ||
|
||
const regex = /((http|https|ftp):\/\/[^\s\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef]+)/gi; | ||
|
||
const Link = ({ href }: { href?: string }) => { | ||
const decText = decodeURIComponent(href || ''); | ||
const replaceText = decText.replace(regex, (match, p1) => { | ||
const isInternal = /^\/#/i.test(p1); | ||
const target = isInternal ? '_self' : '_blank'; | ||
return `<a href="${p1}" target=${target}>${p1}</a>`; | ||
}); | ||
|
||
return <Box as={'span'} dangerouslySetInnerHTML={{ __html: replaceText }} />; | ||
}; | ||
|
||
export default React.memo(Link); |
Oops, something went wrong.