mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
v4.5.1-2 (#421)
This commit is contained in:
@@ -83,6 +83,7 @@ export type ComponentRef = {
|
||||
resetVariables: (data?: Record<string, any>) => void;
|
||||
resetHistory: (history: ChatSiteItemType[]) => void;
|
||||
scrollToBottom: (behavior?: 'smooth' | 'auto') => void;
|
||||
sendPrompt: (question: string) => void;
|
||||
};
|
||||
|
||||
enum FeedbackTypeEnum {
|
||||
@@ -452,7 +453,8 @@ const ChatBox = (
|
||||
setVariableInputFinish(!!e.length);
|
||||
setChatHistory(e);
|
||||
},
|
||||
scrollToBottom
|
||||
scrollToBottom,
|
||||
sendPrompt: (question: string) => handleSubmit((item) => sendPrompt(item, question))()
|
||||
}));
|
||||
|
||||
/* style start */
|
||||
|
@@ -45,8 +45,16 @@ function App({ Component, pageProps }: AppProps) {
|
||||
// get init data
|
||||
(async () => {
|
||||
const {
|
||||
feConfigs: { scripts }
|
||||
feConfigs: { scripts, isPlus }
|
||||
} = await clientInitData();
|
||||
|
||||
// log fastgpt
|
||||
!isPlus &&
|
||||
console.log(
|
||||
'%cWelcome to FastGPT',
|
||||
'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;',
|
||||
`GitHub:https://github.com/labring/FastGPT`
|
||||
);
|
||||
setScripts(scripts || []);
|
||||
})();
|
||||
// add window error track
|
||||
@@ -61,12 +69,7 @@ function App({ Component, pageProps }: AppProps) {
|
||||
url
|
||||
});
|
||||
};
|
||||
// log fastgpt
|
||||
console.log(
|
||||
'%cWelcome to FastGPT',
|
||||
'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;',
|
||||
`GitHub:https://github.com/labring/FastGPT`
|
||||
);
|
||||
|
||||
return () => {
|
||||
window.onerror = null;
|
||||
};
|
||||
|
@@ -166,7 +166,10 @@ const OutLink = ({
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setIdEmbed(window !== parent);
|
||||
if (window !== top) {
|
||||
window.top?.postMessage({ type: 'shareChatReady' }, '*');
|
||||
}
|
||||
setIdEmbed(window !== top);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@@ -280,7 +283,13 @@ export async function getServerSideProps(context: any) {
|
||||
const authToken = context?.query?.authToken || '';
|
||||
|
||||
return {
|
||||
props: { shareId, chatId, showHistory, authToken, ...(await serviceSideProps(context)) }
|
||||
props: {
|
||||
shareId,
|
||||
chatId,
|
||||
showHistory,
|
||||
authToken,
|
||||
...(await serviceSideProps(context))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ export async function hasSameValue({
|
||||
const { rows: existsRows } = await PgClient.query(`
|
||||
SELECT COUNT(*) > 0 AS exists
|
||||
FROM ${PgDatasetTableName}
|
||||
WHERE md5(q)=md5('${q}') AND md5(a)=md5('${a}') collection_id='${collectionId}'
|
||||
WHERE md5(q)=md5('${q}') AND md5(a)=md5('${a}') AND collection_id='${collectionId}'
|
||||
`);
|
||||
const exists = existsRows[0]?.exists || false;
|
||||
|
||||
|
@@ -110,23 +110,30 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
||||
temperature = Math.max(temperature, 0.01);
|
||||
const ai = getAIApi(user.openaiAccount, 480000);
|
||||
|
||||
const response = await ai.chat.completions.create({
|
||||
model,
|
||||
temperature,
|
||||
max_tokens,
|
||||
stream,
|
||||
messages: [
|
||||
...(modelConstantsData.defaultSystemChatPrompt
|
||||
? [
|
||||
{
|
||||
role: ChatCompletionRequestMessageRoleEnum.System,
|
||||
content: modelConstantsData.defaultSystemChatPrompt
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...messages
|
||||
]
|
||||
});
|
||||
const response = await ai.chat.completions.create(
|
||||
{
|
||||
model,
|
||||
temperature,
|
||||
max_tokens,
|
||||
stream,
|
||||
messages: [
|
||||
...(modelConstantsData.defaultSystemChatPrompt
|
||||
? [
|
||||
{
|
||||
role: ChatCompletionRequestMessageRoleEnum.System,
|
||||
content: modelConstantsData.defaultSystemChatPrompt
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...messages
|
||||
]
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/json, text/plain, */*'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const { answerText, totalTokens, completeMessages } = await (async () => {
|
||||
if (stream) {
|
||||
@@ -355,7 +362,6 @@ async function streamResponse({
|
||||
readStream: stream
|
||||
});
|
||||
let answer = '';
|
||||
|
||||
for await (const part of stream) {
|
||||
if (res.closed) {
|
||||
stream.controller?.abort();
|
||||
|
@@ -42,13 +42,15 @@ export const dispatchAppRequest = async (props: Record<string, any>): Promise<Re
|
||||
return Promise.reject('App not found');
|
||||
}
|
||||
|
||||
responseWrite({
|
||||
res,
|
||||
event: detail ? sseResponseEventEnum.answer : undefined,
|
||||
data: textAdaptGptResponse({
|
||||
text: '\n'
|
||||
})
|
||||
});
|
||||
if (stream) {
|
||||
responseWrite({
|
||||
res,
|
||||
event: detail ? sseResponseEventEnum.answer : undefined,
|
||||
data: textAdaptGptResponse({
|
||||
text: '\n'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
const { responseData, answerText } = await dispatchModules({
|
||||
res,
|
||||
|
Reference in New Issue
Block a user