|
@@ -14,6 +14,7 @@ import PromptEditorHeightResizeWrap from './prompt-editor-height-resize-wrap'
|
|
|
import cn from '@/utils/classnames'
|
|
|
import { type PromptVariable } from '@/models/debug'
|
|
|
import Tooltip from '@/app/components/base/tooltip'
|
|
|
+import type { CompletionParams } from '@/types/app'
|
|
|
import { AppType } from '@/types/app'
|
|
|
import { getNewVar, getVars } from '@/utils/var'
|
|
|
import AutomaticBtn from '@/app/components/app/configuration/config/automatic/automatic-btn'
|
|
@@ -28,6 +29,7 @@ import { useEventEmitterContextContext } from '@/context/event-emitter'
|
|
|
import { ADD_EXTERNAL_DATA_TOOL } from '@/app/components/app/configuration/config-var'
|
|
|
import { INSERT_VARIABLE_VALUE_BLOCK_COMMAND } from '@/app/components/base/prompt-editor/plugins/variable-block'
|
|
|
import { PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER } from '@/app/components/base/prompt-editor/plugins/update-block'
|
|
|
+import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
|
|
|
|
|
export type ISimplePromptInput = {
|
|
|
mode: AppType
|
|
@@ -35,6 +37,10 @@ export type ISimplePromptInput = {
|
|
|
promptVariables: PromptVariable[]
|
|
|
readonly?: boolean
|
|
|
onChange?: (promp: string, promptVariables: PromptVariable[]) => void
|
|
|
+ noTitle?: boolean
|
|
|
+ gradientBorder?: boolean
|
|
|
+ editorHeight?: number
|
|
|
+ noResize?: boolean
|
|
|
}
|
|
|
|
|
|
const Prompt: FC<ISimplePromptInput> = ({
|
|
@@ -43,11 +49,19 @@ const Prompt: FC<ISimplePromptInput> = ({
|
|
|
promptVariables,
|
|
|
readonly = false,
|
|
|
onChange,
|
|
|
+ noTitle,
|
|
|
+ gradientBorder,
|
|
|
+ editorHeight: initEditorHeight,
|
|
|
+ noResize,
|
|
|
}) => {
|
|
|
const { t } = useTranslation()
|
|
|
+ const media = useBreakpoints()
|
|
|
+ const isMobile = media === MediaType.mobile
|
|
|
+
|
|
|
const { eventEmitter } = useEventEmitterContextContext()
|
|
|
const {
|
|
|
modelConfig,
|
|
|
+ completionParams,
|
|
|
dataSets,
|
|
|
setModelConfig,
|
|
|
setPrevPromptConfig,
|
|
@@ -116,6 +130,11 @@ const Prompt: FC<ISimplePromptInput> = ({
|
|
|
|
|
|
const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false)
|
|
|
const handleAutomaticRes = (res: AutomaticRes) => {
|
|
|
+ // put eventEmitter in first place to prevent overwrite the configs.prompt_variables.But another problem is that prompt won't hight the prompt_variables.
|
|
|
+ eventEmitter?.emit({
|
|
|
+ type: PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER,
|
|
|
+ payload: res.prompt,
|
|
|
+ } as any)
|
|
|
const newModelConfig = produce(modelConfig, (draft) => {
|
|
|
draft.configs.prompt_template = res.prompt
|
|
|
draft.configs.prompt_variables = res.variables.map(key => ({ key, name: key, type: 'string', required: true }))
|
|
@@ -125,41 +144,41 @@ const Prompt: FC<ISimplePromptInput> = ({
|
|
|
if (mode !== AppType.completion)
|
|
|
setIntroduction(res.opening_statement)
|
|
|
showAutomaticFalse()
|
|
|
- eventEmitter?.emit({
|
|
|
- type: PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER,
|
|
|
- payload: res.prompt,
|
|
|
- } as any)
|
|
|
}
|
|
|
- const minHeight = 228
|
|
|
+ const minHeight = initEditorHeight || 228
|
|
|
const [editorHeight, setEditorHeight] = useState(minHeight)
|
|
|
|
|
|
return (
|
|
|
- <div className={cn(!readonly ? `${s.gradientBorder}` : 'bg-gray-50', ' relative shadow-md')}>
|
|
|
+ <div className={cn((!readonly || gradientBorder) ? `${s.gradientBorder}` : 'bg-gray-50', ' relative shadow-md')}>
|
|
|
<div className='rounded-xl bg-[#EEF4FF]'>
|
|
|
- <div className="flex justify-between items-center h-11 px-3">
|
|
|
- <div className="flex items-center space-x-1">
|
|
|
- <div className='h2'>{mode !== AppType.completion ? t('appDebug.chatSubTitle') : t('appDebug.completionSubTitle')}</div>
|
|
|
- {!readonly && (
|
|
|
- <Tooltip
|
|
|
- htmlContent={<div className='w-[180px]'>
|
|
|
- {t('appDebug.promptTip')}
|
|
|
- </div>}
|
|
|
- selector='config-prompt-tooltip'>
|
|
|
- <RiQuestionLine className='w-[14px] h-[14px] text-indigo-400' />
|
|
|
- </Tooltip>
|
|
|
- )}
|
|
|
- </div>
|
|
|
- <div className='flex items-center'>
|
|
|
- {!isAgent && !readonly && (
|
|
|
- <AutomaticBtn onClick={showAutomaticTrue} />
|
|
|
- )}
|
|
|
+ {!noTitle && (
|
|
|
+ <div className="flex justify-between items-center h-11 pl-3 pr-6">
|
|
|
+ <div className="flex items-center space-x-1">
|
|
|
+ <div className='h2'>{mode !== AppType.completion ? t('appDebug.chatSubTitle') : t('appDebug.completionSubTitle')}</div>
|
|
|
+ {!readonly && (
|
|
|
+ <Tooltip
|
|
|
+ htmlContent={<div className='w-[180px]'>
|
|
|
+ {t('appDebug.promptTip')}
|
|
|
+ </div>}
|
|
|
+ selector='config-prompt-tooltip'>
|
|
|
+ <RiQuestionLine className='w-[14px] h-[14px] text-indigo-400' />
|
|
|
+ </Tooltip>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ <div className='flex items-center'>
|
|
|
+ {!isAgent && !readonly && !isMobile && (
|
|
|
+ <AutomaticBtn onClick={showAutomaticTrue} />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ )}
|
|
|
+
|
|
|
<PromptEditorHeightResizeWrap
|
|
|
className='px-4 pt-2 min-h-[228px] bg-white rounded-t-xl text-sm text-gray-700'
|
|
|
height={editorHeight}
|
|
|
minHeight={minHeight}
|
|
|
onHeightChange={setEditorHeight}
|
|
|
+ hideResize={noResize}
|
|
|
footer={(
|
|
|
<div className='pl-4 pb-2 flex bg-white rounded-b-xl'>
|
|
|
<div className="h-[18px] leading-[18px] px-1 rounded-md bg-gray-100 text-xs text-gray-500">{promptTemplate.length}</div>
|
|
@@ -216,6 +235,7 @@ const Prompt: FC<ISimplePromptInput> = ({
|
|
|
onBlur={() => {
|
|
|
handleChange(promptTemplate, getVars(promptTemplate))
|
|
|
}}
|
|
|
+ editable={!readonly}
|
|
|
/>
|
|
|
</PromptEditorHeightResizeWrap>
|
|
|
</div>
|
|
@@ -232,6 +252,14 @@ const Prompt: FC<ISimplePromptInput> = ({
|
|
|
{showAutomatic && (
|
|
|
<GetAutomaticResModal
|
|
|
mode={mode as AppType}
|
|
|
+ model={
|
|
|
+ {
|
|
|
+ provider: modelConfig.provider,
|
|
|
+ name: modelConfig.model_id,
|
|
|
+ mode: modelConfig.mode,
|
|
|
+ completion_params: completionParams as CompletionParams,
|
|
|
+ }
|
|
|
+ }
|
|
|
isShow={showAutomatic}
|
|
|
onClose={showAutomaticFalse}
|
|
|
onFinished={handleAutomaticRes}
|