Commit 12b1fe30 by liimin

feat(chat): 添加 AI 导师模拟对练功能

- 在 Chat 组件中添加实践按钮,根据练习状态控制显示
- 实现 Practice 组件,用于模拟对练
- 更新 ChatWrapper 和 ChatWithHistory 以支持练习状态
- 添加 PracticeStatus 枚举和相关翻译
1 parent f0e4147f
{
"extends":["next/core-web-vitals","eslint:recommended","plugin:react/recommended"]
"extends":["next/core-web-vitals","eslint:recommended","plugin:react/recommended", "prettier"]
}
......@@ -68,6 +68,7 @@ const ChatWrapper = forwardRef<ChatWrapperMethods, Props>(
clearChatList,
setClearChatList,
setIsResponding,
isShowPracticeButton
} = useChatWithHistoryContext();
const appConfig = useMemo(() => {
......@@ -345,6 +346,7 @@ const ChatWrapper = forwardRef<ChatWrapperMethods, Props>(
inputDisabled={inputDisabled}
isMobile={isMobile}
sidebarCollapseState={sidebarCollapseState}
isShowPracticeButton={isShowPracticeButton}
/>
</div>
);
......
......@@ -59,6 +59,7 @@ export type ChatWithHistoryContextValue = {
setIsResponding: (state: boolean) => void;
currentConversationInputs: Record<string, any> | null;
setCurrentConversationInputs: (v: Record<string, any>) => void;
isShowPracticeButton: boolean;
};
export const ChatWithHistoryContext =
......@@ -93,6 +94,7 @@ export const ChatWithHistoryContext =
setIsResponding: noop,
currentConversationInputs: {},
setCurrentConversationInputs: noop,
isShowPracticeButton: false,
});
export const useChatWithHistoryContext = () =>
useContext(ChatWithHistoryContext);
......@@ -2,7 +2,7 @@
* @Author: liimin 17653212@qq.com
* @Date: 2025-04-16 18:17:38
* @LastEditors: limin
* @LastEditTime: 2025-06-10 18:42:49
* @LastEditTime: 2025-06-11 15:33:21
* @FilePath: \ai-assistant\app\components\base\chat\chat\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
......@@ -10,7 +10,7 @@ import type { FC, ReactNode } from 'react'
import { memo, useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { debounce } from 'lodash-es'
import { useShallow } from 'zustand/react/shallow'
// import { useShallow } from 'zustand/react/shallow'
import type { ChatConfig, ChatItem, Feedback, OnRegenerate, OnSend } from '../types'
import type { ThemeBuilder } from '../embedded-chatbot/theme/theme-context'
import Question from './question'
......@@ -25,7 +25,7 @@ import Button from '@/app/components/base/button'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
// import AgentLogModal from "@/app/components/base/agent-log-modal";
// import PromptLogModal from "@/app/components/base/prompt-log-modal";
import { useStore as useAppStore } from '@/app/components/app/store'
// import { useStore as useAppStore } from '@/app/components/app/store'
import type { AppData } from '@/models/share'
import Practice from './practice'
......@@ -68,20 +68,21 @@ export type ChatProps = {
inputDisabled?: boolean
isMobile?: boolean
sidebarCollapseState?: boolean
isShowPracticeButton: boolean
}
const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsForm, onRegenerate, chatList, isResponding, noStopResponding, onStopResponding, noChatInput, chatContainerClassName, chatContainerInnerClassName, chatFooterClassName, chatFooterInnerClassName, suggestedQuestions, showPromptLog, questionIcon, answerIcon, onAnnotationAdded, onAnnotationEdited, onAnnotationRemoved, chatNode, onFeedback, chatAnswerContainerInner, hideProcessDetail, hideLogModal, themeBuilder, switchSibling, showFeatureBar, showFileUpload, onFeatureBarClick, noSpacing, inputDisabled, isMobile, sidebarCollapseState }) => {
const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsForm, onRegenerate, chatList, isResponding, noStopResponding, onStopResponding, noChatInput, chatContainerClassName, chatContainerInnerClassName, chatFooterClassName, chatFooterInnerClassName, suggestedQuestions, showPromptLog, questionIcon, answerIcon, onAnnotationAdded, onAnnotationEdited, onAnnotationRemoved, chatNode, onFeedback, chatAnswerContainerInner, hideProcessDetail, hideLogModal, themeBuilder, switchSibling, showFeatureBar, showFileUpload, onFeatureBarClick, noSpacing, inputDisabled, isMobile, sidebarCollapseState,isShowPracticeButton }) => {
const { t } = useTranslation()
const { currentLogItem, setCurrentLogItem, showPromptLogModal, setShowPromptLogModal, showAgentLogModal, setShowAgentLogModal } = useAppStore(
useShallow(state => ({
currentLogItem: state.currentLogItem,
setCurrentLogItem: state.setCurrentLogItem,
showPromptLogModal: state.showPromptLogModal,
setShowPromptLogModal: state.setShowPromptLogModal,
showAgentLogModal: state.showAgentLogModal,
setShowAgentLogModal: state.setShowAgentLogModal,
})),
)
// const { currentLogItem, setCurrentLogItem, showPromptLogModal, setShowPromptLogModal, showAgentLogModal, setShowAgentLogModal } = useAppStore(
// useShallow(state => ({
// currentLogItem: state.currentLogItem,
// setCurrentLogItem: state.setCurrentLogItem,
// showPromptLogModal: state.showPromptLogModal,
// setShowPromptLogModal: state.setShowPromptLogModal,
// showAgentLogModal: state.showAgentLogModal,
// setShowAgentLogModal: state.setShowAgentLogModal,
// })),
// )
const [width, setWidth] = useState(0)
const chatContainerRef = useRef<HTMLDivElement>(null)
const chatContainerInnerRef = useRef<HTMLDivElement>(null)
......@@ -212,12 +213,12 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
<div className="mb-2 flex justify-center">
<Button onClick={onStopResponding}>
<StopCircle className="mr-[5px] h-3.5 w-3.5 text-gray-500" />
<span className="text-xs font-normal text-gray-500">{t('停止响应')}</span>
<span className="text-xs font-normal text-gray-500">{t('appDebug.operation.stopResponding')}</span>
</Button>
</div>
)}
{hasTryToAsk && <TryToAsk suggestedQuestions={suggestedQuestions} onSend={onSend} isMobile={isMobile} />}
{<Practice question='AI导师 模拟对练' onSend={handleSend} />}
{isShowPracticeButton && <Practice question={t('appDebug.feature.practice.text')} onSend={handleSend} />}
{!noChatInput && <ChatInputArea disabled={inputDisabled} showFeatureBar={showFeatureBar} showFileUpload={showFileUpload} featureBarDisabled={isResponding} onFeatureBarClick={onFeatureBarClick} visionConfig={config?.file_upload} speechToTextConfig={config?.speech_to_text} onSend={handleSend} onClear={onClear} inputs={inputs} inputsForm={inputsForm} theme={themeBuilder?.theme} isResponding={isResponding} />}
</div>
</div>
......
import type { FC } from 'react'
import { memo } from 'react'
import { useTranslation } from 'react-i18next'
import type { OnSend } from '../types'
import Button from '@/app/components/base/button'
import cn from '@/utils/classnames'
import { InputMessageType } from '../types'
import { Practice as PracticeIcon } from '@/app/components/base/icons/src/image/icons'
type PracticeProps = {
question: string
onSend: OnSend
}
const Practice: FC<PracticeProps> = ({ question, onSend }) => {
return (
<div className="[margin-bottom:12px]">
<div className={cn('flex flex-wrap')}>
{
<Button
size="small"
variant="secondary-accent"
className="mb-1 mr-1 last:mr-0 [width:159px] [height:32px]
rounded-8 opacity-100 bg-white
<div className="mb-3">
{
<Button
size="small"
variant="secondary-accent"
className="mb-1 w-40 h-8 pl-2
rounded-8
shadow-[0_3px_8px_0_#7D94B840]"
onClick={() =>
onSend({
message: question,
type: InputMessageType.SELF,
})
}>
{question}
</Button>
}
</div>
onClick={() =>
onSend({
message: question,
type: InputMessageType.SELF,
})
}>
<PracticeIcon className="size-4 mr-3" />
{question}
</Button>
}
</div>
)
}
......
import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { Annotation, MessageRating } from '@/models/log'
import type { TypeWithI18N,Annotation, MessageRating } from '@/types/app'
// import type { Annotation, MessageRating } from '@/models/log'
import type { FileEntity } from '@/app/components/base/file-uploader/types'
import type { InputVarType } from '@/app/components/workflow/types'
import type { FileResponse } from '@/types/workflow'
......
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-15 17:09:35
* @FilePath: \glsk-ai-assistant\app\components\base\chat\constants.ts
* @LastEditors: limin
* @LastEditTime: 2025-06-11 09:39:11
* @FilePath: \ai-assistant\app\components\base\chat\constants.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
export const CONVERSATION_ID_INFO = 'conversationIdInfo'
......@@ -12,7 +12,7 @@ export const UUID_NIL = '00000000-0000-0000-0000-000000000000'
export const AVATAR_AI_URL = 'https://img01.glsx.com.cn/weapp/resource/saas/ai/ai-avatar.png'
export const AVATAR_USER_URL = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/user-avatar.png'
export const MAIN_TITLE = '广联AI集市'
export const SELF_INPUT = '0'
export const AUTO_INPUT = '1'
// export const SELF_INPUT = '0'
// export const AUTO_INPUT = '1'
export const SEND_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-send.png'
export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-clear.png'
......@@ -2,7 +2,7 @@
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: limin
* @LastEditTime: 2025-06-10 17:57:27
* @LastEditTime: 2025-06-11 14:57:49
* @FilePath: \ai-assistant\app\components\base\chat\types.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
......@@ -17,10 +17,6 @@ import type { FileEntity } from '@/app/components/base/file-uploader/types'
export type { VisionFile } from '@/types/app'
export { TransferMethod } from '@/types/app'
export type {
Inputs,
PromptVariable,
} from '@/models/debug'
export type UserInputForm = {
default: string
......@@ -84,6 +80,12 @@ export enum InputMessageType {
SELF = '0',
SYSTEM = '1'
}
export enum PracticeStatus {
None = '0',
Practicing = '1',
Passed = '2',
Failed = '3'
}
export type OnSend = {
(message: InputMessageProp, files?: FileEntity[]): void
(message: InputMessageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
......
.wrapper {
display: inline-flex;
background: url(~@/app/components/base/icons/assets/image/icons/practice.png) center center no-repeat;
background-size: contain;
}
// GENERATE BY script
// DON NOT EDIT IT MANUALLY
import * as React from 'react'
import cn from '@/utils/classnames'
import s from './Practice.module.css'
const Icon = (
{
ref,
className,
...restProps
}: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> & {
ref?: React.RefObject<HTMLSpanElement>;
},
) => <span className={cn(s.wrapper, className)} {...restProps} ref={ref} />
Icon.displayName = 'Practice'
export default Icon
export { default as Practice } from './Practice'
......@@ -129,9 +129,9 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
const renderCodeContent = useMemo(() => {
const content = String(children).replace(/\n$/, '')
switch (language) {
// case 'mermaid':
// if (isSVG) return <Flowchart PrimitiveCode={content} />
// break
case 'mermaid':
if (isSVG) return <Flowchart PrimitiveCode={content} />
break
case 'echarts':
return (
<div style={{ minHeight: '350px', minWidth: '100%', overflowX: 'scroll' }}>
......@@ -284,7 +284,7 @@ export function Markdown(props: { content: string; className?: string; customDis
return (
<div className={cn('markdown-body', '!text-text-primary', props.className)}>
<ReactMarkdown
remarkPlugins={[[RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
RehypeRaw as any,
......
......@@ -43,6 +43,9 @@ const translation = {
description: 'Use gpt-4, please set API Key.',
},
feature: {
practice:{
text: 'AI Practice',
},
groupChat: {
title: 'Chat enhance',
description: 'Add pre-conversation settings for apps can enhance user experience.',
......
......@@ -43,6 +43,9 @@ const translation = {
description: '使用 gpt-4,请设置 API Key',
},
feature: {
practice:{
text: 'AI导师 模拟对练',
},
groupChat: {
title: '聊天增强',
description: '为聊天型应用添加预对话设置,可以提升用户体验。',
......
......@@ -15,7 +15,7 @@ const withMDX = require('@next/mdx')({
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config, { dev, isServer }) => {
config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }))
// config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }))
return config
},
productionBrowserSourceMaps: false, // enable browser source map generation during the production build
......
......@@ -126,6 +126,7 @@
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"magicast": "^0.3.5",
"prettier": "^3.5.3",
"sass": "^1.80.3",
"storybook": "8.5.0",
"stylelint": "^16.19.1",
......
......@@ -448,3 +448,29 @@ export type RetrievalConfig = {
}
}
}
export type TypeWithI18N<T = string> = {
en_US: T
zh_Hans: T
[key: string]: T
}
export const MessageRatings = ['like', 'dislike', null] as const
export type MessageRating = typeof MessageRatings[number]
export type LogAnnotation = {
id: string
content: string
account: {
id: string
name: string
email: string
}
created_at: number
}
export type Annotation = {
id: string
authorName: string
logAnnotation?: LogAnnotation
created_at?: number
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!