Skip to content

Commit

Permalink
refactor: Set the most recently created token as the placeholder.
Browse files Browse the repository at this point in the history
  • Loading branch information
agatha197 committed Nov 20, 2024
1 parent 19f959b commit cf3c4b3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions react/src/components/lablupTalkativotUI/ChatUIModal.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { useTanQuery } from '../../hooks/reactQueryAlias';
import Flex from '../Flex';
import LLMChatCard from './LLMChatCard';
import { ChatUIModalEndpointTokenListFragment$key } from './__generated__/ChatUIModalEndpointTokenListFragment.graphql';
import { ChatUIModalFragment$key } from './__generated__/ChatUIModalFragment.graphql';
import { ReloadOutlined } from '@ant-design/icons';
import { Alert, Button, Modal, ModalProps, Skeleton, theme } from 'antd';
import graphql from 'babel-plugin-relay/macro';
import dayjs from 'dayjs';
import _ from 'lodash';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useFragment } from 'react-relay';

interface ChatUIBasicProps {
endpointFrgmt: ChatUIModalFragment$key | null | undefined;
endpointTokenFrgmt:
| ChatUIModalEndpointTokenListFragment$key
| null
| undefined;
basePath?: string;
// models?: GetProp<typeof LLMChatCard, 'models'>;
}
interface ChatUIModalProps extends ModalProps, ChatUIBasicProps {}

const ChatUIModal: React.FC<ChatUIModalProps> = ({
endpointFrgmt = null,
endpointTokenFrgmt = null,
basePath,
// models,
...props
Expand Down Expand Up @@ -47,6 +54,7 @@ const ChatUIModal: React.FC<ChatUIModalProps> = ({
<EndpointChatContent
basePath={basePath}
endpointFrgmt={endpointFrgmt}
endpointTokenFrgmt={endpointTokenFrgmt}
/>
</Flex>
</Modal>
Expand All @@ -55,6 +63,7 @@ const ChatUIModal: React.FC<ChatUIModalProps> = ({

const EndpointChatContent: React.FC<ChatUIBasicProps> = ({
endpointFrgmt,
endpointTokenFrgmt,
basePath = 'v1',
}) => {
const { t } = useTranslation();
Expand All @@ -68,6 +77,32 @@ const EndpointChatContent: React.FC<ChatUIBasicProps> = ({
`,
endpointFrgmt,
);
const endpointTokenList = useFragment(
graphql`
fragment ChatUIModalEndpointTokenListFragment on EndpointTokenList {
items {
id
token
created_at
valid_until
}
}
`,
endpointTokenFrgmt,
);

const newestToken = _.maxBy(
endpointTokenList?.items,
(item) => item?.created_at,
);
// FIXME: temporally parse UTC and change to timezone (timezone need to be added in server side)
const newestValidToken = dayjs
.utc(newestToken?.valid_until)
.tz()
.isAfter(dayjs())
? newestToken?.token
: undefined;

const {
data: modelsResult,
// error,
Expand Down Expand Up @@ -117,6 +152,7 @@ const EndpointChatContent: React.FC<ChatUIBasicProps> = ({
)
}
modelId={modelsResult?.data?.[0].id ?? 'custom'}
modelToken={newestValidToken}
showCompareMenuItem
/>
);
Expand Down
3 changes: 3 additions & 0 deletions react/src/components/lablupTalkativotUI/LLMChatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface LLMChatCardProps extends CardProps {
onInputChange?: (input: string) => void;
onSubmitChange?: () => void;
showCompareMenuItem?: boolean;
modelToken?: string;
}

const LLMChatCard: React.FC<LLMChatCardProps> = ({
Expand All @@ -76,6 +77,7 @@ const LLMChatCard: React.FC<LLMChatCardProps> = ({
onInputChange,
onSubmitChange,
showCompareMenuItem,
modelToken,
...cardProps
}) => {
const webuiNavigate = useWebUINavigate();
Expand Down Expand Up @@ -306,6 +308,7 @@ const LLMChatCard: React.FC<LLMChatCardProps> = ({
key={baseURL}
initialValues={{
baseURL: baseURL,
token: modelToken,
}}
>
{alert ? (
Expand Down
2 changes: 2 additions & 0 deletions react/src/pages/EndpointDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
created_at
valid_until
}
...ChatUIModalEndpointTokenListFragment
}
}
`,
Expand Down Expand Up @@ -723,6 +724,7 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
></EndpointTokenGenerationModal>
<ChatUIModal
endpointFrgmt={endpoint}
endpointTokenFrgmt={endpoint_token_list}
open={openChatModal}
onCancel={() => {
setOpenChatModal(false);
Expand Down

0 comments on commit cf3c4b3

Please sign in to comment.