This commit is contained in:
2025-12-01 17:21:38 +08:00
parent 32fee2b8ab
commit fab8c13cb3
7511 changed files with 996300 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useToastContext } from '@/app/components/base/toast'
import { ssePost } from '@/service/base'
export const useTextGeneration = () => {
const { t } = useTranslation()
const { notify } = useToastContext()
const [isResponding, setIsResponding] = useState(false)
const [completion, setCompletion] = useState('')
const [messageId, setMessageId] = useState<string | null>(null)
const handleSend = async (
url: string,
data: any,
) => {
if (isResponding) {
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
return false
}
setIsResponding(true)
setCompletion('')
setMessageId('')
let res: string[] = []
ssePost(
url,
{
body: {
response_mode: 'streaming',
...data,
},
},
{
onData: (data: string, _isFirstMessage: boolean, { messageId }) => {
res.push(data)
setCompletion(res.join(''))
setMessageId(messageId)
},
onMessageReplace: (messageReplace) => {
res = [messageReplace.answer]
setCompletion(res.join(''))
},
onCompleted() {
setIsResponding(false)
},
onError() {
setIsResponding(false)
},
})
return true
}
return {
completion,
isResponding,
setIsResponding,
handleSend,
messageId,
}
}

View File

@@ -0,0 +1,43 @@
import type {
ModelConfig,
VisionFile,
VisionSettings,
} from '@/types/app'
import type { ExternalDataTool } from '@/models/common'
export type { VisionFile } from '@/types/app'
export { TransferMethod } from '@/types/app'
export type UserInputForm = {
default: string
label: string
required: boolean
variable: string
}
export type UserInputFormTextInput = {
'text-input': UserInputForm & {
max_length: number
}
}
export type UserInputFormSelect = {
select: UserInputForm & {
options: string[]
}
}
export type UserInputFormParagraph = {
paragraph: UserInputForm
}
export type VisionConfig = VisionSettings
export type EnableType = {
enabled: boolean
}
export type TextGenerationConfig = Omit<ModelConfig, 'model'> & {
external_data_tools: ExternalDataTool[]
}
export type OnSend = (message: string, files?: VisionFile[]) => void