Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/sdcb/chats into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 10, 2024
2 parents 858c0f6 + 48e347e commit d9e04b4
Show file tree
Hide file tree
Showing 114 changed files with 208 additions and 211 deletions.
9 changes: 0 additions & 9 deletions src/FE/components/Chat/MemoizedChatMessage.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/FE/components/Search/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/FE/components/Spinner/index.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/FE/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import { getUserInfo } from '@/utils/user';

import { UserRole } from '@/types/adminApis';

import { ThemeProvider } from '@/components/Theme/ThemeProvider';

import ErrorPage from './_error';
import AdminLayout from './admin/layout';
import './globals.css';

import { ThemeProvider } from '@/providers/ThemeProvider';
import 'katex/dist/katex.min.css';

function App({ Component, pageProps }: AppProps<{}> | any) {
Expand All @@ -25,7 +24,7 @@ function App({ Component, pageProps }: AppProps<{}> | any) {

useEffect(() => {
setIsClient(true);
document.title = "Chats";
document.title = 'Chats';
}, []);

const isAdmin = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import useTranslation from '@/hooks/useTranslation';
import { AdminModelDto } from '@/types/adminApis';
import { feModelProviders } from '@/types/model';

import ChatIcon from '@/components/ChatIcon/ChatIcon';
import ChatIcon from '@/pages/_components/ChatIcon/ChatIcon';
import { IconChevronDown } from '@/components/Icons';
import Search from '@/components/Search';
import { Button } from '@/components/ui/button';
import Search from '@/pages/_components/Search/Search';
import {
DropdownMenu,
DropdownMenuContent,
Expand All @@ -21,7 +20,7 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';

import { HomeContext } from '@/contexts/Home.context';
import { HomeContext } from '@/pages/home/_contents/Home.context';
import { cn } from '@/lib/utils';

const ChangeModel = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import useTranslation from '@/hooks/useTranslation';

import { IconError } from '@/components/Icons';
import { Alert, AlertDescription } from '@/components/ui/alert';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import useTranslation from '@/hooks/useTranslation';

import { feModelProviders } from '@/types/model';

import { IconShare } from '@/components/Icons';
import useTranslation from '@/hooks/useTranslation';

import { cn } from '@/lib/utils';
import { feModelProviders } from '@/types/model';

interface Props {
providerId: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useTranslation from '@/hooks/useTranslation';

import ChangeModel from '@/components/Chat/ChangeModel';
import Tips from '@/components/Tips/Tips';
import ChangeModel from '@/pages/_components/ChangeModel/ChangeModel';
import Tips from '@/pages/_components/Tips/Tips';

interface Props {
hidden?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { FC, memo, useContext } from 'react';
import { FC, memo } from 'react';

import { Message } from '@/types/chat';
import { IChat, Message } from '@/types/chat';
import { PropsMessage } from '@/types/components/chat';

import { HomeContext } from '@/contexts/Home.context';

import { IconRobot } from '@/components/Icons/index';

import ChatError from '../ChatError';
import ChatError from '../ChatError/ChatError';
import ResponseMessage from './ResponseMessage';
import ResponseMessageActions from './ResponseMessageActions';
import UserMessage from './UserMessage';
Expand All @@ -23,7 +21,11 @@ export interface Props {
modelName?: string;
modelId?: number;
lastMessageId: string;
currentChatMessageId: string;
message: PropsMessage;
messageIsStreaming: boolean;
chatError: boolean;
selectChat: IChat;
onChangeMessage?: (messageId: string) => void;
onEdit?: (editedMessage: Message, parentId: string | null) => void;
onRegenerate?: (modelId?: number) => void;
Expand All @@ -41,14 +43,14 @@ export const ChatMessage: FC<Props> = memo(
modelId,
lastMessageId,
message,
messageIsStreaming,
currentChatMessageId,
chatError,
selectChat,
onEdit,
onChangeMessage,
onRegenerate,
}) => {
const {
state: { messageIsStreaming, currentChatMessageId, chatError },
} = useContext(HomeContext);

return (
<div className={'group md:px-4 text-gray-800 dark:text-gray-100'}>
<div className="relative m-auto flex px-4 py-[10px] text-base md:max-w-2xl lg:max-w-2xl lg:px-0 xl:max-w-5xl">
Expand All @@ -59,6 +61,8 @@ export const ChatMessage: FC<Props> = memo(
<div className="prose w-full dark:prose-invert rounded-r-md">
{message.role === 'user' && (
<UserMessage
selectChat={selectChat}
messageIsStreaming={messageIsStreaming}
message={message}
parentId={parentId}
currentSelectIndex={currentSelectIndex}
Expand All @@ -70,6 +74,7 @@ export const ChatMessage: FC<Props> = memo(

{message.role === 'assistant' && (
<ResponseMessage
messageIsStreaming={messageIsStreaming}
currentChatMessageId={currentChatMessageId}
message={message}
parentId={parentId}
Expand All @@ -85,7 +90,7 @@ export const ChatMessage: FC<Props> = memo(

{message.role === 'assistant' && (
<ResponseMessageActions
hidden={messageIsStreaming}
messageIsStreaming={messageIsStreaming}
readonly={readonly}
message={message}
lastMessageId={lastMessageId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from 'react';
import useTranslation from '@/hooks/useTranslation';

import { IconCheck, IconCopy } from '@/components/Icons';
import Tips from '@/components/Tips/Tips';
import Tips from '@/pages/_components/Tips/Tips';
import { Button } from '@/components/ui/button';

import { cn } from '@/lib/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import useTranslation from '@/hooks/useTranslation';

import Tips from '@/pages/_components/Tips/Tips';

import { IconEdit } from '@/components/Icons';
import Tips from '@/components/Tips/Tips';
import { Button } from '@/components/ui/button';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { formatNumberAsMoney } from '@/utils/common';

import { PropsMessage } from '@/types/components/chat';

import Tips from '@/pages/_components/Tips/Tips';

import { IconInfo } from '@/components/Icons';
import Tips from '@/components/Tips/Tips';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';

Expand All @@ -32,7 +33,8 @@ export const GenerateInformationAction = (props: Props) => {
const Render = () => {
return (
<Tips
className="h-[28px]" side="bottom"
className="h-[28px]"
side="bottom"
trigger={
<Button variant="ghost" className="p-1 m-0 h-auto">
<IconInfo />
Expand Down Expand Up @@ -63,7 +65,9 @@ export const GenerateInformationAction = (props: Props) => {
/>
<GenerateInformation
name={'response tokens'}
value={`${(message.outputTokens - message.reasoningTokens).toLocaleString()}`}
value={`${(
message.outputTokens - message.reasoningTokens
).toLocaleString()}`}
/>
{!!message.reasoningTokens && (
<GenerateInformation
Expand All @@ -76,20 +80,25 @@ export const GenerateInformationAction = (props: Props) => {
value={
message?.duration
? (
((message.outputTokens - message.reasoningTokens) / (message?.duration || 0)) *
((message.outputTokens - message.reasoningTokens) /
(message?.duration || 0)) *
1000
).toFixed(2) + ' token/s'
: '-'
}
/>
{!message.inputPrice.isZero() && (<GenerateInformation
name={'prompt_price'}
value={'¥' + formatNumberAsMoney(+message.inputPrice, 6)}
/>)}
{!message.outputPrice.isZero() && (<GenerateInformation
name={'response_price'}
value={'¥' + formatNumberAsMoney(+message.outputPrice, 6)}
/>)}
{!message.inputPrice.isZero() && (
<GenerateInformation
name={'prompt_price'}
value={'¥' + formatNumberAsMoney(+message.inputPrice, 6)}
/>
)}
{!message.outputPrice.isZero() && (
<GenerateInformation
name={'response_price'}
value={'¥' + formatNumberAsMoney(+message.outputPrice, 6)}
/>
)}
<GenerateInformation
name={'total_price'}
value={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useTranslation from '@/hooks/useTranslation';

import { IconRefresh } from '@/components/Icons';
import Tips from '@/components/Tips/Tips';
import Tips from '@/pages/_components/Tips/Tips';
import { Button } from '@/components/ui/button';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { useContext } from 'react';
import { preprocessLaTeX } from '@/utils/chats';

import { PropsMessage } from '@/types/components/chat';

import { HomeContext } from '@/contexts/Home.context';

import { CodeBlock } from '@/components/Markdown/CodeBlock';
import { MemoizedReactMarkdown } from '@/components/Markdown/MemoizedReactMarkdown';
import { CodeBlock } from '@/pages/_components/Markdown/CodeBlock';
import { MemoizedReactMarkdown } from '@/pages/_components/Markdown/MemoizedReactMarkdown';

import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import remarkGfm from 'remark-gfm';
import { preprocessLaTeX } from '@/utils/chats';
import remarkMath from 'remark-math';

interface Props {
messageIsStreaming: boolean;
currentChatMessageId: string;
message: PropsMessage;
parentId: string | null;
Expand All @@ -21,11 +19,7 @@ interface Props {
}

const ResponseMessage = (props: Props) => {
const {
state: { messageIsStreaming },
} = useContext(HomeContext);

const { message, currentChatMessageId } = props;
const { messageIsStreaming, message, currentChatMessageId } = props;

return (
<div className="pr-0">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { useContext } from 'react';

import { PropsMessage } from '@/types/components/chat';

import { HomeContext } from '@/contexts/Home.context';

import ChangeModelAction from './ChangeModelAction';
import CopyAction from './CopyAction';
import GenerateInformationAction from './GenerateInformationAction';
Expand All @@ -13,23 +9,19 @@ import RegenerateAction from './RegenerateAction';
import { cn } from '@/lib/utils';

interface Props {
hidden?: boolean;
readonly?: boolean;
message: PropsMessage;
modelName?: string;
modelId?: number;
lastMessageId: string | null;
assistantCurrentSelectIndex: number;
assistantChildrenIds: string[];
messageIsStreaming: boolean;
onChangeMessage?: (messageId: string) => void;
onRegenerate?: (modelId?: number) => void;
}

const ResponseMessageActions = (props: Props) => {
const {
state: { messageIsStreaming },
} = useContext(HomeContext);

const {
readonly,
message,
Expand All @@ -40,12 +32,14 @@ const ResponseMessageActions = (props: Props) => {
assistantChildrenIds,
onChangeMessage,
onRegenerate,
hidden,
messageIsStreaming,
} = props;

return (
<>
{!hidden ? (
{messageIsStreaming ? (
<div className="h-9"></div>
) : (
<div className="flex gap-1 flex-wrap mt-1">
<PaginationAction
hidden={assistantChildrenIds.length <= 1}
Expand Down Expand Up @@ -82,8 +76,6 @@ const ResponseMessageActions = (props: Props) => {
/>
</div>
</div>
) : (
<div className="h-9"></div>
)}
</>
);
Expand Down
Loading

0 comments on commit d9e04b4

Please sign in to comment.