Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set the initial value of the chat modal to the recently created token #2864

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading