Commit 6d6afe8f authored by JzoNg's avatar JzoNg

fix app mode in logs

parent e307947d
...@@ -2,15 +2,9 @@ import React from 'react' ...@@ -2,15 +2,9 @@ import React from 'react'
import Main from '@/app/components/app/log-annotation' import Main from '@/app/components/app/log-annotation'
import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type'
export type IProps = { const Logs = async () => {
params: { appId: string }
}
const Logs = async ({
params: { appId },
}: IProps) => {
return ( return (
<Main pageType={PageType.log} appId={appId} /> <Main pageType={PageType.log} />
) )
} }
......
...@@ -24,14 +24,14 @@ import { sleep } from '@/utils' ...@@ -24,14 +24,14 @@ import { sleep } from '@/utils'
import { useProviderContext } from '@/context/provider-context' import { useProviderContext } from '@/context/provider-context'
import AnnotationFullModal from '@/app/components/billing/annotation-full/modal' import AnnotationFullModal from '@/app/components/billing/annotation-full/modal'
import { Settings04 } from '@/app/components/base/icons/src/vender/line/general' import { Settings04 } from '@/app/components/base/icons/src/vender/line/general'
import { fetchAppDetail } from '@/service/apps' import type { App } from '@/types/app'
type Props = { type Props = {
appId: string appDetail: App
} }
const Annotation: FC<Props> = ({ const Annotation: FC<Props> = ({
appId, appDetail,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [isShowEdit, setIsShowEdit] = React.useState(false) const [isShowEdit, setIsShowEdit] = React.useState(false)
...@@ -39,16 +39,14 @@ const Annotation: FC<Props> = ({ ...@@ -39,16 +39,14 @@ const Annotation: FC<Props> = ({
const [isChatApp, setIsChatApp] = useState(false) const [isChatApp, setIsChatApp] = useState(false)
const fetchAnnotationConfig = async () => { const fetchAnnotationConfig = async () => {
const res = await doFetchAnnotationConfig(appId) const res = await doFetchAnnotationConfig(appDetail.id)
setAnnotationConfig(res as AnnotationReplyConfig) setAnnotationConfig(res as AnnotationReplyConfig)
} }
useEffect(() => { useEffect(() => {
fetchAppDetail({ url: '/apps', id: appId }).then(async (res: any) => { const isChatApp = appDetail.mode !== 'completion'
const isChatApp = res.mode === 'chat' setIsChatApp(isChatApp)
setIsChatApp(isChatApp) if (isChatApp)
if (isChatApp) fetchAnnotationConfig()
fetchAnnotationConfig()
})
}, []) }, [])
const [controlRefreshSwitch, setControlRefreshSwitch] = useState(Date.now()) const [controlRefreshSwitch, setControlRefreshSwitch] = useState(Date.now())
const { plan, enableBilling } = useProviderContext() const { plan, enableBilling } = useProviderContext()
...@@ -57,7 +55,7 @@ const Annotation: FC<Props> = ({ ...@@ -57,7 +55,7 @@ const Annotation: FC<Props> = ({
const ensureJobCompleted = async (jobId: string, status: AnnotationEnableStatus) => { const ensureJobCompleted = async (jobId: string, status: AnnotationEnableStatus) => {
let isCompleted = false let isCompleted = false
while (!isCompleted) { while (!isCompleted) {
const res: any = await queryAnnotationJobStatus(appId, status, jobId) const res: any = await queryAnnotationJobStatus(appDetail.id, status, jobId)
isCompleted = res.job_status === JobStatus.completed isCompleted = res.job_status === JobStatus.completed
if (isCompleted) if (isCompleted)
break break
...@@ -81,7 +79,7 @@ const Annotation: FC<Props> = ({ ...@@ -81,7 +79,7 @@ const Annotation: FC<Props> = ({
const fetchList = async (page = 1) => { const fetchList = async (page = 1) => {
setIsLoading(true) setIsLoading(true)
try { try {
const { data, total }: any = await fetchAnnotationList(appId, { const { data, total }: any = await fetchAnnotationList(appDetail.id, {
...query, ...query,
page, page,
}) })
...@@ -104,7 +102,7 @@ const Annotation: FC<Props> = ({ ...@@ -104,7 +102,7 @@ const Annotation: FC<Props> = ({
}, [queryParams]) }, [queryParams])
const handleAdd = async (payload: AnnotationItemBasic) => { const handleAdd = async (payload: AnnotationItemBasic) => {
await addAnnotation(appId, { await addAnnotation(appDetail.id, {
...payload, ...payload,
}) })
Toast.notify({ Toast.notify({
...@@ -116,7 +114,7 @@ const Annotation: FC<Props> = ({ ...@@ -116,7 +114,7 @@ const Annotation: FC<Props> = ({
} }
const handleRemove = async (id: string) => { const handleRemove = async (id: string) => {
await delAnnotation(appId, id) await delAnnotation(appDetail.id, id)
Toast.notify({ Toast.notify({
message: t('common.api.actionSuccess'), message: t('common.api.actionSuccess'),
type: 'success', type: 'success',
...@@ -137,7 +135,7 @@ const Annotation: FC<Props> = ({ ...@@ -137,7 +135,7 @@ const Annotation: FC<Props> = ({
} }
const handleSave = async (question: string, answer: string) => { const handleSave = async (question: string, answer: string) => {
await editAnnotation(appId, (currItem as AnnotationItem).id, { await editAnnotation(appDetail.id, (currItem as AnnotationItem).id, {
question, question,
answer, answer,
}) })
...@@ -153,7 +151,7 @@ const Annotation: FC<Props> = ({ ...@@ -153,7 +151,7 @@ const Annotation: FC<Props> = ({
<div className='flex flex-col h-full'> <div className='flex flex-col h-full'>
<p className='flex text-sm font-normal text-gray-500'>{t('appLog.description')}</p> <p className='flex text-sm font-normal text-gray-500'>{t('appLog.description')}</p>
<div className='grow flex flex-col py-4 '> <div className='grow flex flex-col py-4 '>
<Filter appId={appId} queryParams={queryParams} setQueryParams={setQueryParams}> <Filter appId={appDetail.id} queryParams={queryParams} setQueryParams={setQueryParams}>
<div className='flex items-center space-x-2'> <div className='flex items-center space-x-2'>
{isChatApp && ( {isChatApp && (
<> <>
...@@ -173,7 +171,7 @@ const Annotation: FC<Props> = ({ ...@@ -173,7 +171,7 @@ const Annotation: FC<Props> = ({
setIsShowEdit(true) setIsShowEdit(true)
} }
else { else {
const { job_id: jobId }: any = await updateAnnotationStatus(appId, AnnotationEnableStatus.disable, annotationConfig?.embedding_model, annotationConfig?.score_threshold) const { job_id: jobId }: any = await updateAnnotationStatus(appDetail.id, AnnotationEnableStatus.disable, annotationConfig?.embedding_model, annotationConfig?.score_threshold)
await ensureJobCompleted(jobId, AnnotationEnableStatus.disable) await ensureJobCompleted(jobId, AnnotationEnableStatus.disable)
await fetchAnnotationConfig() await fetchAnnotationConfig()
Toast.notify({ Toast.notify({
...@@ -205,7 +203,7 @@ const Annotation: FC<Props> = ({ ...@@ -205,7 +203,7 @@ const Annotation: FC<Props> = ({
)} )}
<HeaderOpts <HeaderOpts
appId={appId} appId={appDetail.id}
controlUpdateList={controlUpdateList} controlUpdateList={controlUpdateList}
onAdd={handleAdd} onAdd={handleAdd}
onAdded={() => { onAdded={() => {
...@@ -260,7 +258,7 @@ const Annotation: FC<Props> = ({ ...@@ -260,7 +258,7 @@ const Annotation: FC<Props> = ({
{isShowViewModal && ( {isShowViewModal && (
<ViewAnnotationModal <ViewAnnotationModal
appId={appId} appId={appDetail.id}
isShow={isShowViewModal} isShow={isShowViewModal}
onHide={() => setIsShowViewModal(false)} onHide={() => setIsShowViewModal(false)}
onRemove={async () => { onRemove={async () => {
...@@ -272,7 +270,7 @@ const Annotation: FC<Props> = ({ ...@@ -272,7 +270,7 @@ const Annotation: FC<Props> = ({
)} )}
{isShowEdit && ( {isShowEdit && (
<ConfigParamModal <ConfigParamModal
appId={appId} appId={appDetail.id}
isShow isShow
isInit={!annotationConfig?.enabled} isInit={!annotationConfig?.enabled}
onHide={() => { onHide={() => {
...@@ -283,12 +281,12 @@ const Annotation: FC<Props> = ({ ...@@ -283,12 +281,12 @@ const Annotation: FC<Props> = ({
embeddingModel.embedding_model_name !== annotationConfig?.embedding_model?.embedding_model_name embeddingModel.embedding_model_name !== annotationConfig?.embedding_model?.embedding_model_name
&& embeddingModel.embedding_provider_name !== annotationConfig?.embedding_model?.embedding_provider_name && embeddingModel.embedding_provider_name !== annotationConfig?.embedding_model?.embedding_provider_name
) { ) {
const { job_id: jobId }: any = await updateAnnotationStatus(appId, AnnotationEnableStatus.enable, embeddingModel, score) const { job_id: jobId }: any = await updateAnnotationStatus(appDetail.id, AnnotationEnableStatus.enable, embeddingModel, score)
await ensureJobCompleted(jobId, AnnotationEnableStatus.enable) await ensureJobCompleted(jobId, AnnotationEnableStatus.enable)
} }
if (score !== annotationConfig?.score_threshold) if (score !== annotationConfig?.score_threshold)
await updateAnnotationScore(appId, annotationConfig?.id || '', score) await updateAnnotationScore(appDetail.id, annotationConfig?.id || '', score)
await fetchAnnotationConfig() await fetchAnnotationConfig()
Toast.notify({ Toast.notify({
......
...@@ -14,12 +14,10 @@ import { useStore as useAppStore } from '@/app/components/app/store' ...@@ -14,12 +14,10 @@ import { useStore as useAppStore } from '@/app/components/app/store'
type Props = { type Props = {
pageType: PageType pageType: PageType
appId: string
} }
const LogAnnotation: FC<Props> = ({ const LogAnnotation: FC<Props> = ({
pageType, pageType,
appId,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const router = useRouter() const router = useRouter()
...@@ -45,14 +43,14 @@ const LogAnnotation: FC<Props> = ({ ...@@ -45,14 +43,14 @@ const LogAnnotation: FC<Props> = ({
className='shrink-0' className='shrink-0'
value={pageType} value={pageType}
onChange={(value) => { onChange={(value) => {
router.push(`/app/${appId}/${value === PageType.log ? 'logs' : 'annotations'}`) router.push(`/app/${appDetail.id}/${value === PageType.log ? 'logs' : 'annotations'}`)
}} }}
options={options} options={options}
/> />
)} )}
<div className={cn('grow', appDetail.mode !== 'workflow' && 'mt-3')}> <div className={cn('grow', appDetail.mode !== 'workflow' && 'mt-3')}>
{pageType === PageType.log && appDetail.mode !== 'workflow' && (<Log appId={appId} />)} {pageType === PageType.log && appDetail.mode !== 'workflow' && (<Log appDetail={appDetail} />)}
{pageType === PageType.annotation && (<Annotation appId={appId} />)} {pageType === PageType.annotation && (<Annotation appDetail={appDetail} />)}
{pageType === PageType.log && appDetail.mode === 'workflow' && (<WorkflowLog appDetail={appDetail} />)} {pageType === PageType.log && appDetail.mode === 'workflow' && (<WorkflowLog appDetail={appDetail} />)}
</div> </div>
</div> </div>
......
...@@ -14,10 +14,10 @@ import Filter from './filter' ...@@ -14,10 +14,10 @@ import Filter from './filter'
import s from './style.module.css' import s from './style.module.css'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import { fetchChatConversations, fetchCompletionConversations } from '@/service/log' import { fetchChatConversations, fetchCompletionConversations } from '@/service/log'
import { fetchAppDetail } from '@/service/apps'
import { APP_PAGE_LIMIT } from '@/config' import { APP_PAGE_LIMIT } from '@/config'
import type { App } from '@/types/app'
export type ILogsProps = { export type ILogsProps = {
appId: string appDetail: App
} }
export type QueryParam = { export type QueryParam = {
...@@ -50,7 +50,7 @@ const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => { ...@@ -50,7 +50,7 @@ const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => {
</div> </div>
} }
const Logs: FC<ILogsProps> = ({ appId }) => { const Logs: FC<ILogsProps> = ({ appDetail }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [queryParams, setQueryParams] = useState<QueryParam>({ period: 7, annotation_status: 'all' }) const [queryParams, setQueryParams] = useState<QueryParam>({ period: 7, annotation_status: 'all' })
const [currPage, setCurrPage] = React.useState<number>(0) const [currPage, setCurrPage] = React.useState<number>(0)
...@@ -68,20 +68,19 @@ const Logs: FC<ILogsProps> = ({ appId }) => { ...@@ -68,20 +68,19 @@ const Logs: FC<ILogsProps> = ({ appId }) => {
} }
// Get the app type first // Get the app type first
const { data: appDetail } = useSWR({ url: '/apps', id: appId }, fetchAppDetail) const isChatMode = appDetail.mode !== 'completion'
const isChatMode = appDetail?.mode === 'chat'
// When the details are obtained, proceed to the next request // When the details are obtained, proceed to the next request
const { data: chatConversations, mutate: mutateChatList } = useSWR(() => isChatMode const { data: chatConversations, mutate: mutateChatList } = useSWR(() => isChatMode
? { ? {
url: `/apps/${appId}/chat-conversations`, url: `/apps/${appDetail.id}/chat-conversations`,
params: query, params: query,
} }
: null, fetchChatConversations) : null, fetchChatConversations)
const { data: completionConversations, mutate: mutateCompletionList } = useSWR(() => !isChatMode const { data: completionConversations, mutate: mutateCompletionList } = useSWR(() => !isChatMode
? { ? {
url: `/apps/${appId}/completion-conversations`, url: `/apps/${appDetail.id}/completion-conversations`,
params: query, params: query,
} }
: null, fetchCompletionConversations) : null, fetchCompletionConversations)
...@@ -92,12 +91,12 @@ const Logs: FC<ILogsProps> = ({ appId }) => { ...@@ -92,12 +91,12 @@ const Logs: FC<ILogsProps> = ({ appId }) => {
<div className='flex flex-col h-full'> <div className='flex flex-col h-full'>
<p className='flex text-sm font-normal text-gray-500'>{t('appLog.description')}</p> <p className='flex text-sm font-normal text-gray-500'>{t('appLog.description')}</p>
<div className='flex flex-col py-4 flex-1'> <div className='flex flex-col py-4 flex-1'>
<Filter appId={appId} queryParams={queryParams} setQueryParams={setQueryParams} /> <Filter appId={appDetail.id} queryParams={queryParams} setQueryParams={setQueryParams} />
{total === undefined {total === undefined
? <Loading type='app' /> ? <Loading type='app' />
: total > 0 : total > 0
? <List logs={isChatMode ? chatConversations : completionConversations} appDetail={appDetail} onRefresh={isChatMode ? mutateChatList : mutateCompletionList} /> ? <List logs={isChatMode ? chatConversations : completionConversations} appDetail={appDetail} onRefresh={isChatMode ? mutateChatList : mutateCompletionList} />
: <EmptyElement appUrl={`${appDetail?.site.app_base_url}/${appDetail?.mode}/${appDetail?.site.access_token}`} /> : <EmptyElement appUrl={`${appDetail.site.app_base_url}/${appDetail.mode}/${appDetail.site.access_token}`} />
} }
{/* Show Pagination only if the total is more than the limit */} {/* Show Pagination only if the total is more than the limit */}
{(total && total > APP_PAGE_LIMIT) {(total && total > APP_PAGE_LIMIT)
......
...@@ -38,7 +38,7 @@ import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils' ...@@ -38,7 +38,7 @@ import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'
type IConversationList = { type IConversationList = {
logs?: ChatConversationsResponse | CompletionConversationsResponse logs?: ChatConversationsResponse | CompletionConversationsResponse
appDetail?: App appDetail: App
onRefresh: () => void onRefresh: () => void
} }
...@@ -175,11 +175,11 @@ function DetailPanel<T extends ChatConversationFullDetailResponse | CompletionCo ...@@ -175,11 +175,11 @@ function DetailPanel<T extends ChatConversationFullDetailResponse | CompletionCo
} }
useEffect(() => { useEffect(() => {
if (appDetail?.id && detail.id && appDetail?.mode === 'chat') if (appDetail?.id && detail.id && appDetail?.mode === 'completion')
fetchData() fetchData()
}, [appDetail?.id, detail.id, appDetail?.mode]) }, [appDetail?.id, detail.id, appDetail?.mode])
const isChatMode = appDetail?.mode === 'chat' const isChatMode = appDetail?.mode !== 'completion'
const targetTone = TONE_LIST.find((item: any) => { const targetTone = TONE_LIST.find((item: any) => {
let res = true let res = true
...@@ -460,7 +460,7 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh }) ...@@ -460,7 +460,7 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh })
const [showDrawer, setShowDrawer] = useState<boolean>(false) // Whether to display the chat details drawer const [showDrawer, setShowDrawer] = useState<boolean>(false) // Whether to display the chat details drawer
const [currentConversation, setCurrentConversation] = useState<ChatConversationGeneralDetail | CompletionConversationGeneralDetail | undefined>() // Currently selected conversation const [currentConversation, setCurrentConversation] = useState<ChatConversationGeneralDetail | CompletionConversationGeneralDetail | undefined>() // Currently selected conversation
const isChatMode = appDetail?.mode === 'chat' // Whether the app is a chat app const isChatMode = appDetail.mode !== 'completion' // Whether the app is a chat app
// Annotated data needs to be highlighted // Annotated data needs to be highlighted
const renderTdValue = (value: string | number | null, isEmptyStyle: boolean, isHighlight = false, annotation?: LogAnnotation) => { const renderTdValue = (value: string | number | null, isEmptyStyle: boolean, isHighlight = false, annotation?: LogAnnotation) => {
...@@ -559,8 +559,8 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh }) ...@@ -559,8 +559,8 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh })
appDetail, appDetail,
}}> }}>
{isChatMode {isChatMode
? <ChatConversationDetailComp appId={appDetail?.id} conversationId={currentConversation?.id} /> ? <ChatConversationDetailComp appId={appDetail.id} conversationId={currentConversation?.id} />
: <CompletionConversationDetailComp appId={appDetail?.id} conversationId={currentConversation?.id} /> : <CompletionConversationDetailComp appId={appDetail.id} conversationId={currentConversation?.id} />
} }
</DrawerContext.Provider> </DrawerContext.Provider>
</Drawer> </Drawer>
......
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