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 bd8f2bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions react/src/components/lablupTalkativotUI/ChatUIModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand All @@ -12,13 +13,18 @@ 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 +53,7 @@ const ChatUIModal: React.FC<ChatUIModalProps> = ({
<EndpointChatContent
basePath={basePath}
endpointFrgmt={endpointFrgmt}
endpointTokenFrgmt={endpointTokenFrgmt}
/>
</Flex>
</Modal>
Expand All @@ -55,6 +62,7 @@ const ChatUIModal: React.FC<ChatUIModalProps> = ({

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

const {
data: modelsResult,
// error,
Expand Down Expand Up @@ -117,6 +142,7 @@ const EndpointChatContent: React.FC<ChatUIBasicProps> = ({
)
}
modelId={modelsResult?.data?.[0].id ?? 'custom'}
modelToken={newestToken}
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 bd8f2bc

Please sign in to comment.