From 65fd4b39cece6903eb5f598e5f73fdb449d8d2cd Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 18 Dec 2023 15:41:24 +0800 Subject: [PATCH] feat: annotation management frontend (#1764) --- .../[appId]/annotations/page.tsx | 17 + .../(appDetailLayout)/[appId]/logs/page.tsx | 5 +- web/app/components/app-sidebar/navLink.tsx | 10 +- .../add-annotation-modal/edit-item/index.tsx | 47 +++ .../annotation/add-annotation-modal/index.tsx | 120 ++++++ .../csv-downloader.tsx | 74 ++++ .../csv-uploader.tsx | 126 ++++++ .../batch-add-annotation-modal/index.tsx | 124 ++++++ .../edit-annotation-modal/edit-item/index.tsx | 131 +++++++ .../edit-annotation-modal/index.tsx | 142 +++++++ .../app/annotation/empty-element.tsx | 26 ++ web/app/components/app/annotation/filter.tsx | 54 +++ .../app/annotation/header-opts/index.tsx | 141 +++++++ .../annotation/header-opts/style.module.css | 32 ++ web/app/components/app/annotation/index.tsx | 315 +++++++++++++++ web/app/components/app/annotation/list.tsx | 98 +++++ .../remove-annotation-confirm-modal/index.tsx | 29 ++ .../app/annotation/style.module.css | 9 + web/app/components/app/annotation/type.ts | 39 ++ .../hit-history-no-data.tsx | 19 + .../view-annotation-modal/index.tsx | 237 ++++++++++++ .../view-annotation-modal/style.module.css | 9 + web/app/components/app/chat/answer/index.tsx | 149 +++++--- web/app/components/app/chat/index.tsx | 80 +++- web/app/components/app/chat/style.module.css | 10 +- web/app/components/app/chat/type.ts | 9 + .../config/feature/choose-feature/index.tsx | 13 +- .../config/feature/use-feature.tsx | 8 + .../app/configuration/config/index.tsx | 81 +++- .../dataset-config/context-var/var-picker.tsx | 11 +- .../app/configuration/debug/index.tsx | 38 +- .../features/chat-group/index.tsx | 1 - .../components/app/configuration/index.tsx | 33 +- .../annotation/annotation-ctrl-btn/index.tsx | 132 +++++++ .../toolbox/annotation/config-param-modal.tsx | 138 +++++++ .../toolbox/annotation/config-param.tsx | 124 ++++++ .../configuration/toolbox/annotation/type.ts | 4 + .../annotation/use-annotation-config.ts | 89 +++++ .../app/configuration/toolbox/index.tsx | 20 +- .../score-slider/base-slider/index.tsx | 38 ++ .../score-slider/base-slider/style.module.css | 20 + .../toolbox/score-slider/index.tsx | 46 +++ .../components/app/log-annotation/index.tsx | 45 +++ web/app/components/app/log/index.tsx | 22 +- web/app/components/app/log/list.tsx | 58 ++- .../app/text-generate/item/index.tsx | 155 +++++--- web/app/components/base/drawer-plus/index.tsx | 69 ++++ web/app/components/base/drawer/index.tsx | 4 +- .../base/icons/assets/public/avatar/robot.svg | 11 + .../base/icons/assets/public/avatar/user.svg | 12 + .../icons/assets/public/billing/sparkles.svg | 4 +- .../communication/message-check-remove.svg | 5 + .../line/communication/message-fast-plus.svg | 3 + .../vender/line/files/file-download-02.svg | 3 + .../assets/vender/line/general/edit-04.svg | 3 + .../vender/line/time/clock-fast-forward.svg | 3 + .../solid/communication/message-fast.svg | 3 + .../assets/vender/solid/general/edit-04.svg | 4 + .../base/icons/src/public/avatar/Robot.json | 92 +++++ .../base/icons/src/public/avatar/Robot.tsx | 16 + .../base/icons/src/public/avatar/User.json | 89 +++++ .../base/icons/src/public/avatar/User.tsx | 16 + .../base/icons/src/public/avatar/index.ts | 2 + .../icons/src/public/billing/Sparkles.json | 4 +- .../communication/MessageCheckRemove.json | 39 ++ .../line/communication/MessageCheckRemove.tsx | 16 + .../line/communication/MessageFastPlus.json | 29 ++ .../line/communication/MessageFastPlus.tsx | 16 + .../src/vender/line/communication/index.ts | 2 + .../src/vender/line/files/FileDownload02.json | 29 ++ .../src/vender/line/files/FileDownload02.tsx | 16 + .../base/icons/src/vender/line/files/index.ts | 1 + .../icons/src/vender/line/general/Edit04.json | 29 ++ .../icons/src/vender/line/general/Edit04.tsx | 16 + .../icons/src/vender/line/general/index.ts | 1 + .../vender/line/time/ClockFastForward.json | 29 ++ .../src/vender/line/time/ClockFastForward.tsx | 16 + .../base/icons/src/vender/line/time/index.ts | 1 + .../solid/communication/MessageFast.json | 28 ++ .../solid/communication/MessageFast.tsx | 16 + .../src/vender/solid/communication/index.ts | 1 + .../src/vender/solid/general/Edit04.json | 39 ++ .../icons/src/vender/solid/general/Edit04.tsx | 16 + .../icons/src/vender/solid/general/index.ts | 1 + web/app/components/base/markdown.tsx | 6 +- .../base/modal/delete-confirm-modal/index.tsx | 66 ++++ .../delete-confirm-modal/style.module.css | 16 + web/app/components/base/modal/index.tsx | 9 +- .../base/tab-slider-plain/index.tsx | 68 ++++ .../billing/annotation-full/index.tsx | 31 ++ .../billing/annotation-full/modal.tsx | 47 +++ .../billing/annotation-full/style.module.css | 7 + .../billing/annotation-full/usage.tsx | 32 ++ web/app/components/billing/config.ts | 2 + .../components/billing/progress-bar/index.tsx | 2 +- web/app/components/billing/type.ts | 6 +- web/app/components/billing/utils/index.ts | 2 + .../model-selector/portal-select.tsx | 358 ++++++++++++++++++ web/app/components/share/chat/index.tsx | 16 + .../share/text-generation/result/index.tsx | 1 + web/config/index.ts | 6 + web/context/debug-configuration.ts | 25 +- web/context/modal-context.tsx | 27 +- web/context/provider-context.tsx | 26 +- web/i18n/i18next-config.ts | 4 + web/i18n/lang/app-annotation.en.ts | 87 +++++ web/i18n/lang/app-annotation.zh.ts | 90 +++++ web/i18n/lang/app-debug.en.ts | 21 + web/i18n/lang/app-debug.zh.ts | 21 + web/i18n/lang/app-log.en.ts | 2 +- web/i18n/lang/app-log.zh.ts | 2 +- web/i18n/lang/billing.en.ts | 5 + web/i18n/lang/billing.zh.ts | 5 + web/i18n/lang/common.en.ts | 3 + web/i18n/lang/common.zh.ts | 3 + web/models/debug.ts | 10 + web/models/log.ts | 19 +- web/service/annotation.ts | 65 ++++ web/service/base.ts | 13 +- web/service/debug.ts | 7 +- web/service/share.ts | 7 +- web/types/app.ts | 3 +- 122 files changed, 4718 insertions(+), 214 deletions(-) create mode 100644 web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx create mode 100644 web/app/components/app/annotation/add-annotation-modal/edit-item/index.tsx create mode 100644 web/app/components/app/annotation/add-annotation-modal/index.tsx create mode 100644 web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx create mode 100644 web/app/components/app/annotation/batch-add-annotation-modal/csv-uploader.tsx create mode 100644 web/app/components/app/annotation/batch-add-annotation-modal/index.tsx create mode 100644 web/app/components/app/annotation/edit-annotation-modal/edit-item/index.tsx create mode 100644 web/app/components/app/annotation/edit-annotation-modal/index.tsx create mode 100644 web/app/components/app/annotation/empty-element.tsx create mode 100644 web/app/components/app/annotation/filter.tsx create mode 100644 web/app/components/app/annotation/header-opts/index.tsx create mode 100644 web/app/components/app/annotation/header-opts/style.module.css create mode 100644 web/app/components/app/annotation/index.tsx create mode 100644 web/app/components/app/annotation/list.tsx create mode 100644 web/app/components/app/annotation/remove-annotation-confirm-modal/index.tsx create mode 100644 web/app/components/app/annotation/style.module.css create mode 100644 web/app/components/app/annotation/type.ts create mode 100644 web/app/components/app/annotation/view-annotation-modal/hit-history-no-data.tsx create mode 100644 web/app/components/app/annotation/view-annotation-modal/index.tsx create mode 100644 web/app/components/app/annotation/view-annotation-modal/style.module.css create mode 100644 web/app/components/app/configuration/toolbox/annotation/annotation-ctrl-btn/index.tsx create mode 100644 web/app/components/app/configuration/toolbox/annotation/config-param-modal.tsx create mode 100644 web/app/components/app/configuration/toolbox/annotation/config-param.tsx create mode 100644 web/app/components/app/configuration/toolbox/annotation/type.ts create mode 100644 web/app/components/app/configuration/toolbox/annotation/use-annotation-config.ts create mode 100644 web/app/components/app/configuration/toolbox/score-slider/base-slider/index.tsx create mode 100644 web/app/components/app/configuration/toolbox/score-slider/base-slider/style.module.css create mode 100644 web/app/components/app/configuration/toolbox/score-slider/index.tsx create mode 100644 web/app/components/app/log-annotation/index.tsx create mode 100644 web/app/components/base/drawer-plus/index.tsx create mode 100644 web/app/components/base/icons/assets/public/avatar/robot.svg create mode 100644 web/app/components/base/icons/assets/public/avatar/user.svg create mode 100644 web/app/components/base/icons/assets/vender/line/communication/message-check-remove.svg create mode 100644 web/app/components/base/icons/assets/vender/line/communication/message-fast-plus.svg create mode 100644 web/app/components/base/icons/assets/vender/line/files/file-download-02.svg create mode 100644 web/app/components/base/icons/assets/vender/line/general/edit-04.svg create mode 100644 web/app/components/base/icons/assets/vender/line/time/clock-fast-forward.svg create mode 100644 web/app/components/base/icons/assets/vender/solid/communication/message-fast.svg create mode 100644 web/app/components/base/icons/assets/vender/solid/general/edit-04.svg create mode 100644 web/app/components/base/icons/src/public/avatar/Robot.json create mode 100644 web/app/components/base/icons/src/public/avatar/Robot.tsx create mode 100644 web/app/components/base/icons/src/public/avatar/User.json create mode 100644 web/app/components/base/icons/src/public/avatar/User.tsx create mode 100644 web/app/components/base/icons/src/public/avatar/index.ts create mode 100644 web/app/components/base/icons/src/vender/line/communication/MessageCheckRemove.json create mode 100644 web/app/components/base/icons/src/vender/line/communication/MessageCheckRemove.tsx create mode 100644 web/app/components/base/icons/src/vender/line/communication/MessageFastPlus.json create mode 100644 web/app/components/base/icons/src/vender/line/communication/MessageFastPlus.tsx create mode 100644 web/app/components/base/icons/src/vender/line/files/FileDownload02.json create mode 100644 web/app/components/base/icons/src/vender/line/files/FileDownload02.tsx create mode 100644 web/app/components/base/icons/src/vender/line/general/Edit04.json create mode 100644 web/app/components/base/icons/src/vender/line/general/Edit04.tsx create mode 100644 web/app/components/base/icons/src/vender/line/time/ClockFastForward.json create mode 100644 web/app/components/base/icons/src/vender/line/time/ClockFastForward.tsx create mode 100644 web/app/components/base/icons/src/vender/line/time/index.ts create mode 100644 web/app/components/base/icons/src/vender/solid/communication/MessageFast.json create mode 100644 web/app/components/base/icons/src/vender/solid/communication/MessageFast.tsx create mode 100644 web/app/components/base/icons/src/vender/solid/communication/index.ts create mode 100644 web/app/components/base/icons/src/vender/solid/general/Edit04.json create mode 100644 web/app/components/base/icons/src/vender/solid/general/Edit04.tsx create mode 100644 web/app/components/base/modal/delete-confirm-modal/index.tsx create mode 100644 web/app/components/base/modal/delete-confirm-modal/style.module.css create mode 100644 web/app/components/base/tab-slider-plain/index.tsx create mode 100644 web/app/components/billing/annotation-full/index.tsx create mode 100644 web/app/components/billing/annotation-full/modal.tsx create mode 100644 web/app/components/billing/annotation-full/style.module.css create mode 100644 web/app/components/billing/annotation-full/usage.tsx create mode 100644 web/app/components/header/account-setting/model-page/model-selector/portal-select.tsx create mode 100644 web/i18n/lang/app-annotation.en.ts create mode 100644 web/i18n/lang/app-annotation.zh.ts create mode 100644 web/service/annotation.ts diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx new file mode 100644 index 0000000000..998184c0ee --- /dev/null +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx @@ -0,0 +1,17 @@ +import React from 'react' +import Main from '@/app/components/app/log-annotation' +import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' + +export type IProps = { + params: { appId: string } +} + +const Logs = async ({ + params: { appId }, +}: IProps) => { + return ( +
+ ) +} + +export default Logs diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx index 6c17986ce6..d23e690dc5 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx @@ -1,5 +1,6 @@ import React from 'react' -import Main from '@/app/components/app/log' +import Main from '@/app/components/app/log-annotation' +import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' export type IProps = { params: { appId: string } @@ -9,7 +10,7 @@ const Logs = async ({ params: { appId }, }: IProps) => { return ( -
+
) } diff --git a/web/app/components/app-sidebar/navLink.tsx b/web/app/components/app-sidebar/navLink.tsx index c7d79fb503..4cfec7e848 100644 --- a/web/app/components/app-sidebar/navLink.tsx +++ b/web/app/components/app-sidebar/navLink.tsx @@ -28,7 +28,15 @@ export default function NavLink({ mode = 'expand', }: NavLinkProps) { const segment = useSelectedLayoutSegment() - const isActive = href.toLowerCase().split('/')?.pop() === segment?.toLowerCase() + const formattedSegment = (() => { + let res = segment?.toLowerCase() + // logs and annotations use the same nav + if (res === 'annotations') + res = 'logs' + + return res + })() + const isActive = href.toLowerCase().split('/')?.pop() === formattedSegment const NavIcon = isActive ? iconMap.selected : iconMap.normal return ( diff --git a/web/app/components/app/annotation/add-annotation-modal/edit-item/index.tsx b/web/app/components/app/annotation/add-annotation-modal/edit-item/index.tsx new file mode 100644 index 0000000000..4da6b7cac4 --- /dev/null +++ b/web/app/components/app/annotation/add-annotation-modal/edit-item/index.tsx @@ -0,0 +1,47 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import { useTranslation } from 'react-i18next' +import Textarea from 'rc-textarea' +import { Robot, User } from '@/app/components/base/icons/src/public/avatar' + +export enum EditItemType { + Query = 'query', + Answer = 'answer', +} +type Props = { + type: EditItemType + content: string + onChange: (content: string) => void +} + +const EditItem: FC = ({ + type, + content, + onChange, +}) => { + const { t } = useTranslation() + const avatar = type === EditItemType.Query ? : + const name = type === EditItemType.Query ? t('appAnnotation.addModal.queryName') : t('appAnnotation.addModal.answerName') + const placeholder = type === EditItemType.Query ? t('appAnnotation.addModal.queryPlaceholder') : t('appAnnotation.addModal.answerPlaceholder') + + return ( +
e.stopPropagation()}> +
+ {avatar} +
+
+
{name}
+