-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add overview tab for model configuration
- Loading branch information
Showing
25 changed files
with
998 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...c/app/projects/[projectId]/applications/[applicationId]/prompts/[promptConfigId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
'use client'; | ||
|
||
import { useTranslations } from 'next-intl'; | ||
import { useState } from 'react'; | ||
import { Speedometer2 } from 'react-bootstrap-icons'; | ||
import useSWR from 'swr'; | ||
|
||
import { handleRetrievePromptConfigs } from '@/api'; | ||
import { PromptAnalyticsPage } from '@/components/projects/[projectId]/applications/[applicationId]/prompts/[promptId]/prompt-analytics-page'; | ||
import { PromptGeneralInfo } from '@/components/projects/[projectId]/applications/[applicationId]/prompts/[promptId]/prompt-general-info'; | ||
import { TabData, TabNavigation } from '@/components/tab-navigation'; | ||
import { ApiError } from '@/errors'; | ||
import { useAuthenticatedUser } from '@/hooks/use-authenticated-user'; | ||
import { useProjectBootstrap } from '@/hooks/use-project-bootstrap'; | ||
import { usePromptConfig, useSetPromptConfigs } from '@/stores/project-store'; | ||
import { useShowError } from '@/stores/toast-store'; | ||
|
||
enum TAB_NAMES { | ||
OVERVIEW, | ||
MODEL, | ||
PROMPT, | ||
SETTINGS, | ||
} | ||
|
||
export default function PromptConfiguration({ | ||
params: { projectId, applicationId, promptConfigId }, | ||
}: { | ||
params: { | ||
projectId: string; | ||
applicationId: string; | ||
promptConfigId: string; | ||
}; | ||
}) { | ||
useAuthenticatedUser(); | ||
useProjectBootstrap(false); | ||
|
||
const t = useTranslations('promptConfig'); | ||
const showError = useShowError(); | ||
|
||
const promptConfig = usePromptConfig(applicationId, promptConfigId); | ||
const setPromptConfigs = useSetPromptConfigs(); | ||
|
||
const { isLoading } = useSWR( | ||
promptConfig ? null : { projectId, applicationId }, | ||
handleRetrievePromptConfigs, | ||
{ | ||
onError({ message }: ApiError) { | ||
showError(message); | ||
}, | ||
onSuccess(promptConfigs) { | ||
setPromptConfigs(applicationId, promptConfigs); | ||
}, | ||
}, | ||
); | ||
|
||
const tabs: TabData<TAB_NAMES>[] = [ | ||
{ | ||
id: TAB_NAMES.OVERVIEW, | ||
text: t('overview'), | ||
icon: <Speedometer2 className="w-3.5 h-3.5" />, | ||
}, | ||
]; | ||
const [selectedTab, setSelectedTab] = useState(TAB_NAMES.OVERVIEW); | ||
|
||
if (!promptConfig && isLoading) { | ||
return ( | ||
<div | ||
data-testid="prompt-config-page-loading" | ||
className="h-full w-full flex items-center justify-center" | ||
> | ||
<span className="loading loading-spinner loading-md" /> | ||
</div> | ||
); | ||
} else if (promptConfig) { | ||
return ( | ||
<div data-testid="prompt-page" className="my-8 mx-32"> | ||
<h1 | ||
data-testid="prompt-page-title" | ||
className="text-2xl font-semibold text-base-content" | ||
> | ||
{t('modelConfiguration')} / {promptConfig.name} | ||
</h1> | ||
<div className="mt-3.5 w-full mb-8"> | ||
<TabNavigation<TAB_NAMES> | ||
tabs={tabs} | ||
selectedTab={selectedTab} | ||
onTabChange={setSelectedTab} | ||
trailingLine={true} | ||
/> | ||
</div> | ||
{selectedTab === TAB_NAMES.OVERVIEW && ( | ||
<> | ||
<PromptAnalyticsPage | ||
applicationId={applicationId} | ||
projectId={projectId} | ||
promptConfigId={promptConfigId} | ||
/> | ||
<div className="h-8" /> | ||
<PromptGeneralInfo | ||
applicationId={applicationId} | ||
projectId={projectId} | ||
promptConfigId={promptConfigId} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...cts/[projectId]/applications/[applicationId]/prompts/[promptId]/prompt-analytics-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useTranslations } from 'next-intl'; | ||
import { useState } from 'react'; | ||
import { Activity, Cash } from 'react-bootstrap-icons'; | ||
import { DateValueType } from 'react-tailwindcss-datepicker'; | ||
import useSWR from 'swr'; | ||
|
||
import { handlePromptConfigAnalytics } from '@/api'; | ||
import { DataCard } from '@/components/dashboard/data-card'; | ||
import { DatePicker } from '@/components/dashboard/date-picker'; | ||
import { ApiError } from '@/errors'; | ||
import { useShowError } from '@/stores/toast-store'; | ||
import { useDateFormat } from '@/stores/user-config-store'; | ||
|
||
export function PromptAnalyticsPage({ | ||
projectId, | ||
applicationId, | ||
promptConfigId, | ||
}: { | ||
projectId: string; | ||
applicationId: string; | ||
promptConfigId: string; | ||
}) { | ||
const t = useTranslations('promptConfig'); | ||
const dateFormat = useDateFormat(); | ||
const showError = useShowError(); | ||
|
||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); | ||
|
||
const [dateRange, setDateRange] = useState<DateValueType>({ | ||
startDate: oneWeekAgo, | ||
endDate: new Date(), | ||
}); | ||
|
||
const { data: analytics, isLoading } = useSWR( | ||
{ | ||
projectId, | ||
applicationId, | ||
promptConfigId, | ||
fromDate: dateRange?.startDate, | ||
toDate: dateRange?.endDate, | ||
}, | ||
handlePromptConfigAnalytics, | ||
{ | ||
onError({ message }: ApiError) { | ||
showError(message); | ||
}, | ||
}, | ||
); | ||
|
||
return ( | ||
<div data-testid="prompt-analytics-container"> | ||
<div className="flex justify-between items-center"> | ||
<h2 className="font-semibold text-white text-xl"> | ||
{t('status')} | ||
</h2> | ||
<DatePicker | ||
displayFormat={dateFormat} | ||
showShortcuts={true} | ||
useRange={true} | ||
value={dateRange} | ||
onValueChange={setDateRange} | ||
/> | ||
</div> | ||
<div className="flex items-center justify-between custom-card"> | ||
<DataCard | ||
imageSrc={<Activity className="text-secondary w-6 h-6" />} | ||
metric={t('apiCalls')} | ||
totalValue={analytics?.totalRequests ?? ''} | ||
percentage={'100'} | ||
currentValue={'324'} | ||
loading={isLoading} | ||
/> | ||
<div className="w-px h-12 bg-gray-200 mx-4" /> | ||
<DataCard | ||
imageSrc={<Cash className="text-secondary w-6 h-6" />} | ||
metric={t('modelsCost')} | ||
totalValue={`${analytics?.tokensCost ?? ''}$`} | ||
percentage={'103'} | ||
currentValue={'3.3'} | ||
loading={isLoading} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.