Commit ba9e2ea9 authored by Joel's avatar Joel

feat: can get agent thought

parent 2374af61
...@@ -35,7 +35,6 @@ import { replaceStringWithValues } from '@/app/components/app/configuration/prom ...@@ -35,7 +35,6 @@ import { replaceStringWithValues } from '@/app/components/app/configuration/prom
import { userInputsFormToPromptVariables } from '@/utils/model-config' import { userInputsFormToPromptVariables } from '@/utils/model-config'
import Confirm from '@/app/components/base/confirm' import Confirm from '@/app/components/base/confirm'
import type { DataSet } from '@/models/datasets' import type { DataSet } from '@/models/datasets'
import { UNIVERSAL_CHAT_MODEL_LIST as MODEL_LIST } from '@/config'
const APP_ID = 'universal-chat' const APP_ID = 'universal-chat'
const isUniversalChat = true const isUniversalChat = true
...@@ -384,9 +383,14 @@ const Main: FC<IMainProps> = () => { ...@@ -384,9 +383,14 @@ const Main: FC<IMainProps> = () => {
return return
} }
const data = { const data = {
inputs: currInputs,
query: message, query: message,
conversation_id: isNewConversation ? null : currConversationId, conversation_id: isNewConversation ? null : currConversationId,
model: modelId,
tools: Object.keys(plugins).map(key => ({
[key]: {
enabled: plugins[key],
},
})),
} }
// qustion // qustion
...@@ -419,6 +423,7 @@ const Main: FC<IMainProps> = () => { ...@@ -419,6 +423,7 @@ const Main: FC<IMainProps> = () => {
setHasStopResponded(false) setHasStopResponded(false)
setResponsingTrue() setResponsingTrue()
setIsShowSuggestion(false) setIsShowSuggestion(false)
sendChatMessage(data, { sendChatMessage(data, {
getAbortController: (abortController) => { getAbortController: (abortController) => {
setAbortController(abortController) setAbortController(abortController)
...@@ -514,8 +519,8 @@ const Main: FC<IMainProps> = () => { ...@@ -514,8 +519,8 @@ const Main: FC<IMainProps> = () => {
) )
} }
const [modelId, setModeId] = useState('gpt-3.5-turbo') const [modelId, setModeId] = useState('claude-2') // gpt-4, claude-2
const currModel = MODEL_LIST.find(item => item.id === modelId) // const currModel = MODEL_LIST.find(item => item.id === modelId)
const [plugins, setPlugins] = useState<Record<string, boolean>>({ const [plugins, setPlugins] = useState<Record<string, boolean>>({
google_search: false, google_search: false,
......
...@@ -45,6 +45,9 @@ type IOtherOptions = { ...@@ -45,6 +45,9 @@ type IOtherOptions = {
} }
function unicodeToChar(text: string) { function unicodeToChar(text: string) {
if (!text)
return ''
return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => { return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
return String.fromCharCode(parseInt(p1, 16)) return String.fromCharCode(parseInt(p1, 16))
}) })
...@@ -101,6 +104,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted ...@@ -101,6 +104,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
onCompleted && onCompleted(true) onCompleted && onCompleted(true)
return return
} }
if (bufferObj.event === 'message') {
// can not use format here. Because message is splited. // can not use format here. Because message is splited.
onData(unicodeToChar(bufferObj.answer), isFirstMessage, { onData(unicodeToChar(bufferObj.answer), isFirstMessage, {
conversationId: bufferObj.conversation_id, conversationId: bufferObj.conversation_id,
...@@ -109,6 +113,10 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted ...@@ -109,6 +113,10 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
}) })
isFirstMessage = false isFirstMessage = false
} }
else if (bufferObj.event === 'agent_thought') {
console.log(bufferObj)
}
}
}) })
buffer = lines[lines.length - 1] buffer = lines[lines.length - 1]
} }
...@@ -333,6 +341,7 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o ...@@ -333,6 +341,7 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
} }
return handleStream(res, (str: string, isFirstMessage: boolean, moreInfo: IOnDataMoreInfo) => { return handleStream(res, (str: string, isFirstMessage: boolean, moreInfo: IOnDataMoreInfo) => {
if (moreInfo.errorMessage) { if (moreInfo.errorMessage) {
// debugger
onError?.(moreInfo.errorMessage) onError?.(moreInfo.errorMessage)
if (moreInfo.errorMessage !== 'AbortError: The user aborted a request.') if (moreInfo.errorMessage !== 'AbortError: The user aborted a request.')
Toast.notify({ type: 'error', message: moreInfo.errorMessage }) Toast.notify({ type: 'error', message: moreInfo.errorMessage })
...@@ -343,7 +352,6 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o ...@@ -343,7 +352,6 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
}).catch((e) => { }).catch((e) => {
if (e.toString() !== 'AbortError: The user aborted a request.') if (e.toString() !== 'AbortError: The user aborted a request.')
Toast.notify({ type: 'error', message: e }) Toast.notify({ type: 'error', message: e })
onError?.(e) onError?.(e)
}) })
} }
......
...@@ -16,7 +16,7 @@ export const sendChatMessage = async (body: Record<string, any>, { onData, onCom ...@@ -16,7 +16,7 @@ export const sendChatMessage = async (body: Record<string, any>, { onData, onCom
onError: IOnError onError: IOnError
getAbortController?: (abortController: AbortController) => void getAbortController?: (abortController: AbortController) => void
}) => { }) => {
return ssePost(getUrl('chat-messages'), { return ssePost(getUrl('messages'), {
body: { body: {
...body, ...body,
response_mode: 'streaming', response_mode: 'streaming',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment