feat: add api-based extension & external data tool & moderation (#1459)

This commit is contained in:
zxhlyh
2023-11-06 19:36:32 +08:00
committed by GitHub
parent db43ed6f41
commit 32747641e4
84 changed files with 3327 additions and 167 deletions

View File

@@ -24,14 +24,18 @@ import { promptVariablesToUserInputsForm } from '@/utils/model-config'
import TextGeneration from '@/app/components/app/text-generate/item'
import { IS_CE_EDITION } from '@/config'
import { useProviderContext } from '@/context/provider-context'
import type { Inputs } from '@/models/debug'
type IDebug = {
hasSetAPIKEY: boolean
onSetting: () => void
inputs: Inputs
}
const Debug: FC<IDebug> = ({
hasSetAPIKEY = true,
onSetting,
inputs,
}) => {
const { t } = useTranslation()
const {
@@ -47,9 +51,8 @@ const Debug: FC<IDebug> = ({
suggestedQuestionsAfterAnswerConfig,
speechToTextConfig,
citationConfig,
moderationConfig,
moreLikeThisConfig,
inputs,
// setInputs,
formattingChanged,
setFormattingChanged,
conversationId,
@@ -60,6 +63,7 @@ const Debug: FC<IDebug> = ({
completionParams,
hasSetContextVar,
datasetConfigs,
externalDataToolsConfig,
} = useContext(ConfigContext)
const { speech2textDefaultModel } = useProviderContext()
const [chatList, setChatList, getChatList] = useGetState<IChatItem[]>([])
@@ -190,6 +194,8 @@ const Debug: FC<IDebug> = ({
suggested_questions_after_answer: suggestedQuestionsAfterAnswerConfig,
speech_to_text: speechToTextConfig,
retriever_resource: citationConfig,
sensitive_word_avoidance: moderationConfig,
external_data_tools: externalDataToolsConfig,
agent_mode: {
enabled: true,
tools: [...postDatasets],
@@ -319,6 +325,9 @@ const Debug: FC<IDebug> = ({
})
setChatList(newListWithAnswer)
},
onMessageReplace: (messageReplace) => {
responseItem.content = messageReplace.answer
},
onError() {
setResponsingFalse()
// role back placeholder answer
@@ -371,6 +380,8 @@ const Debug: FC<IDebug> = ({
suggested_questions_after_answer: suggestedQuestionsAfterAnswerConfig,
speech_to_text: speechToTextConfig,
retriever_resource: citationConfig,
sensitive_word_avoidance: moderationConfig,
external_data_tools: externalDataToolsConfig,
more_like_this: moreLikeThisConfig,
agent_mode: {
enabled: true,
@@ -397,7 +408,7 @@ const Debug: FC<IDebug> = ({
setCompletionRes('')
setMessageId('')
const res: string[] = []
let res: string[] = []
setResponsingTrue()
sendCompletionMessage(appId, data, {
@@ -406,6 +417,10 @@ const Debug: FC<IDebug> = ({
setCompletionRes(res.join(''))
setMessageId(messageId)
},
onMessageReplace: (messageReplace) => {
res = [messageReplace.answer]
setCompletionRes(res.join(''))
},
onCompleted() {
setResponsingFalse()
},
@@ -432,6 +447,7 @@ const Debug: FC<IDebug> = ({
<PromptValuePanel
appType={mode as AppType}
onSend={sendTextCompletion}
inputs={inputs}
/>
</div>
<div className="flex flex-col grow">