mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-11-30 02:08:37 +08:00
feat: switch to generation model set default stop word (#1341)
This commit is contained in:
parent
695841a3cf
commit
a07a6d8c26
@ -224,6 +224,8 @@ const ConfigModel: FC<IConfigModelProps> = ({
|
||||
const handleParamChange = (key: string, value: number | string[]) => {
|
||||
if (value === undefined)
|
||||
return
|
||||
if ((completionParams as any)[key] === value)
|
||||
return
|
||||
|
||||
if (key === 'stop') {
|
||||
onCompletionParamsChange({
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { clone } from 'lodash-es'
|
||||
import produce from 'immer'
|
||||
import type { ChatPromptConfig, CompletionPromptConfig, ConversationHistoriesRole, PromptItem } from '@/models/debug'
|
||||
import type { ChatPromptConfig, CompletionParams, CompletionPromptConfig, ConversationHistoriesRole, PromptItem } from '@/models/debug'
|
||||
import { PromptMode } from '@/models/debug'
|
||||
import { AppType, ModelModeType } from '@/types/app'
|
||||
import { DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
|
||||
@ -16,6 +16,9 @@ type Param = {
|
||||
prePrompt: string
|
||||
onUserChangedPrompt: () => void
|
||||
hasSetDataSet: boolean
|
||||
completionParams: CompletionParams
|
||||
setCompletionParams: (params: CompletionParams) => void
|
||||
setStop: (stop: string[]) => void
|
||||
}
|
||||
|
||||
const useAdvancedPromptConfig = ({
|
||||
@ -26,6 +29,9 @@ const useAdvancedPromptConfig = ({
|
||||
prePrompt,
|
||||
onUserChangedPrompt,
|
||||
hasSetDataSet,
|
||||
completionParams,
|
||||
setCompletionParams,
|
||||
setStop,
|
||||
}: Param) => {
|
||||
const isAdvancedPrompt = promptMode === PromptMode.advanced
|
||||
const [chatPromptConfig, setChatPromptConfig] = useState<ChatPromptConfig>(clone(DEFAULT_CHAT_PROMPT_CONFIG))
|
||||
@ -98,7 +104,7 @@ const useAdvancedPromptConfig = ({
|
||||
const mode = modelModeType
|
||||
const toReplacePrePrompt = prePrompt || ''
|
||||
if (!isAdvancedPrompt) {
|
||||
const { chat_prompt_config, completion_prompt_config } = await fetchPromptTemplate({
|
||||
const { chat_prompt_config, completion_prompt_config, stop } = await fetchPromptTemplate({
|
||||
appMode,
|
||||
mode,
|
||||
modelName,
|
||||
@ -121,12 +127,16 @@ const useAdvancedPromptConfig = ({
|
||||
draft.prompt.text = draft.prompt.text.replace(PRE_PROMPT_PLACEHOLDER_TEXT, toReplacePrePrompt)
|
||||
})
|
||||
setCompletionPromptConfig(newPromptConfig)
|
||||
setCompletionParams({
|
||||
...completionParams,
|
||||
stop,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (isMigrateToCompetition) {
|
||||
const { completion_prompt_config, chat_prompt_config } = await fetchPromptTemplate({
|
||||
const { completion_prompt_config, chat_prompt_config, stop } = await fetchPromptTemplate({
|
||||
appMode,
|
||||
mode: toModelModeType as ModelModeType,
|
||||
modelName,
|
||||
@ -145,6 +155,13 @@ const useAdvancedPromptConfig = ({
|
||||
draft.conversation_histories_role = completionPromptConfig.conversation_histories_role
|
||||
})
|
||||
setCompletionPromptConfig(newPromptConfig)
|
||||
if (!completionParams.stop || completionParams.stop.length === 0) {
|
||||
setCompletionParams({
|
||||
...completionParams,
|
||||
stop,
|
||||
})
|
||||
}
|
||||
setStop(stop) // switch mode's params is async. It may override the stop value.
|
||||
}
|
||||
else {
|
||||
const newPromptConfig = produce(chat_prompt_config, (draft) => {
|
||||
|
19
web/app/components/app/configuration/images/prompt.svg
Normal file
19
web/app/components/app/configuration/images/prompt.svg
Normal file
@ -0,0 +1,19 @@
|
||||
<svg width="72" height="35" viewBox="0 0 72 35" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.0565 5.76794C18.2191 5.76794 19.1045 6.03461 19.7125 6.56794C20.3205 7.09061 20.6245 7.77328 20.6245 8.61594C20.6245 8.86128 20.6031 9.09061 20.5605 9.30394C20.4325 10.0506 20.1071 10.7173 19.5845 11.3039C19.0618 11.8906 18.3631 12.3066 17.4885 12.5519L19.2965 16.9999H16.2085L14.6245 12.7599H13.9685L13.2165 16.9999H10.4805L12.4645 5.76794H17.0565ZM17.7605 9.41594C17.7818 9.24528 17.7925 9.13328 17.7925 9.07994C17.7925 8.73861 17.6805 8.47728 17.4565 8.29594C17.2431 8.10394 16.9231 8.00794 16.4965 8.00794H14.8005L14.3045 10.8239H16.0005C16.5018 10.8239 16.8965 10.7013 17.1845 10.4559C17.4831 10.2106 17.6751 9.86394 17.7605 9.41594Z" fill="#1D2939"/>
|
||||
<path d="M10.0798 9.38394C9.97312 10.0346 9.72245 10.6319 9.32778 11.1759C8.93312 11.7093 8.39445 12.1413 7.71178 12.4719C7.03978 12.8026 6.24511 12.9679 5.32778 12.9679H3.63178L2.91178 16.9999H0.175781L2.15978 5.76794H6.59178C7.76511 5.76794 8.65045 6.02928 9.24778 6.55194C9.84512 7.06394 10.1438 7.76261 10.1438 8.64794C10.1438 8.91461 10.1224 9.15994 10.0798 9.38394ZM5.48778 10.8239C6.51178 10.8239 7.11445 10.3439 7.29578 9.38394C7.31711 9.21328 7.32778 9.09061 7.32778 9.01594C7.32778 8.67461 7.21578 8.41328 6.99178 8.23194C6.77845 8.03994 6.44778 7.94394 5.99978 7.94394H4.51178L4.01578 10.8239H5.48778Z" fill="#1D2939"/>
|
||||
<path d="M26.52 17.112C25.5706 17.112 24.7333 16.9147 24.008 16.52C23.2933 16.1254 22.7386 15.5707 22.344 14.856C21.9493 14.1414 21.752 13.32 21.752 12.392C21.752 11.08 22.0346 9.91203 22.6 8.88803C23.1653 7.85337 23.9493 7.04803 24.952 6.47203C25.9653 5.89603 27.112 5.60803 28.392 5.60803C29.352 5.60803 30.1946 5.80537 30.92 6.20003C31.6453 6.58403 32.2053 7.13336 32.6 7.84803C32.9946 8.55203 33.192 9.3627 33.192 10.28C33.192 11.592 32.9093 12.7707 32.344 13.816C31.7786 14.8507 30.9893 15.6614 29.976 16.248C28.9626 16.824 27.8106 17.112 26.52 17.112ZM26.936 14.584C27.64 14.584 28.2586 14.4027 28.792 14.04C29.3253 13.6774 29.736 13.192 30.024 12.584C30.3226 11.9654 30.472 11.2987 30.472 10.584C30.472 9.81603 30.2586 9.21337 29.832 8.77603C29.4053 8.3387 28.808 8.12003 28.04 8.12003C27.336 8.12003 26.712 8.30137 26.168 8.66403C25.6346 9.0267 25.2186 9.51203 24.92 10.12C24.632 10.7174 24.488 11.3787 24.488 12.104C24.488 12.872 24.7013 13.48 25.128 13.928C25.5546 14.3654 26.1573 14.584 26.936 14.584Z" fill="#1D2939"/>
|
||||
<path d="M69.5515 5.76794L69.1835 7.92794H66.1915L64.5915 16.9999H61.8555L63.4555 7.92794H60.4795L60.8635 5.76794H69.5515Z" fill="#1D2939"/>
|
||||
<path d="M59.0876 9.38394C58.9809 10.0346 58.7303 10.6319 58.3356 11.1759C57.9409 11.7093 57.4023 12.1413 56.7196 12.4719C56.0476 12.8026 55.2529 12.9679 54.3356 12.9679H52.6396L51.9196 16.9999H49.1836L51.1676 5.76794H55.5996C56.7729 5.76794 57.6583 6.02928 58.2556 6.55194C58.8529 7.06394 59.1516 7.76261 59.1516 8.64794C59.1516 8.91461 59.1303 9.15994 59.0876 9.38394ZM54.4956 10.8239C55.5196 10.8239 56.1223 10.3439 56.3036 9.38394C56.3249 9.21328 56.3356 9.09061 56.3356 9.01594C56.3356 8.67461 56.2236 8.41328 55.9996 8.23194C55.7863 8.03994 55.4556 7.94394 55.0076 7.94394H53.5196L53.0236 10.8239H54.4956Z" fill="#1D2939"/>
|
||||
<path d="M48.8798 5.76794L46.8958 16.9999H44.1598L45.3598 10.2639L41.6478 16.9999H39.4398L38.0958 10.2319L36.9118 16.9999H34.1758L36.1598 5.76794H39.3918L41.1838 13.5439L45.6638 5.76794H48.8798Z" fill="#1D2939"/>
|
||||
<path d="M67.6792 24.28C68.1912 24.28 68.6272 24.384 68.9872 24.592C69.3552 24.792 69.6192 25.044 69.7792 25.348L69.9472 24.388H71.3272L70.1512 31.108C70.0392 31.716 69.8152 32.256 69.4792 32.728C69.1432 33.208 68.7072 33.584 68.1712 33.856C67.6352 34.128 67.0312 34.264 66.3592 34.264C65.7752 34.264 65.2632 34.168 64.8232 33.976C64.3832 33.792 64.0512 33.524 63.8272 33.172C63.6032 32.82 63.5072 32.404 63.5392 31.924H64.8952C64.9352 32.268 65.1072 32.544 65.4112 32.752C65.7152 32.968 66.1032 33.076 66.5752 33.076C67.1272 33.076 67.6032 32.908 68.0032 32.572C68.4032 32.236 68.6592 31.748 68.7712 31.108L68.9632 30.004C68.6752 30.316 68.3152 30.58 67.8832 30.796C67.4512 31.004 66.9832 31.108 66.4792 31.108C65.9752 31.108 65.5272 30.996 65.1352 30.772C64.7432 30.548 64.4352 30.232 64.2112 29.824C63.9952 29.408 63.8872 28.932 63.8872 28.396C63.8872 28.156 63.9112 27.912 63.9592 27.664C64.0792 27 64.3192 26.412 64.6792 25.9C65.0472 25.388 65.4952 24.992 66.0232 24.712C66.5512 24.424 67.1032 24.28 67.6792 24.28ZM69.3712 27.688C69.4032 27.536 69.4192 27.372 69.4192 27.196C69.4192 26.66 69.2592 26.24 68.9392 25.936C68.6272 25.624 68.2352 25.468 67.7632 25.468C67.4112 25.468 67.0672 25.556 66.7312 25.732C66.3952 25.9 66.1032 26.152 65.8552 26.488C65.6072 26.816 65.4432 27.208 65.3632 27.664C65.3312 27.816 65.3152 27.98 65.3152 28.156C65.3152 28.7 65.4712 29.132 65.7832 29.452C66.1032 29.764 66.4992 29.92 66.9712 29.92C67.3232 29.92 67.6672 29.832 68.0032 29.656C68.3392 29.48 68.6312 29.224 68.8792 28.888C69.1272 28.544 69.2912 28.144 69.3712 27.688Z" fill="#667085"/>
|
||||
<path d="M60.5582 24.28C61.2542 24.28 61.8062 24.468 62.2142 24.844C62.6302 25.212 62.8382 25.744 62.8382 26.44C62.8382 26.616 62.8182 26.836 62.7782 27.1L62.0822 31H60.7262L61.3862 27.304C61.4182 27.08 61.4342 26.92 61.4342 26.824C61.4342 26.384 61.3102 26.048 61.0622 25.816C60.8222 25.584 60.4862 25.468 60.0542 25.468C59.5342 25.468 59.0942 25.628 58.7342 25.948C58.3822 26.26 58.1582 26.712 58.0622 27.304V27.268L57.4022 31H56.0342L57.1982 24.388H58.5662L58.4342 25.156C58.7062 24.884 59.0262 24.672 59.3942 24.52C59.7702 24.36 60.1582 24.28 60.5582 24.28Z" fill="#667085"/>
|
||||
<path d="M54.8861 23.512C54.6701 23.512 54.4941 23.444 54.3581 23.308C54.2221 23.172 54.1541 23 54.1541 22.792C54.1541 22.512 54.2581 22.272 54.4661 22.072C54.6821 21.864 54.9261 21.76 55.1981 21.76C55.4141 21.76 55.5861 21.828 55.7141 21.964C55.8501 22.1 55.9181 22.272 55.9181 22.48C55.9181 22.76 55.8141 23.004 55.6061 23.212C55.3981 23.412 55.1581 23.512 54.8861 23.512ZM55.4021 24.388L54.2381 31H52.8701L54.0341 24.388H55.4021Z" fill="#667085"/>
|
||||
<path d="M50.5926 25.552C50.8646 25.152 51.1846 24.84 51.5526 24.616C51.9286 24.392 52.3446 24.28 52.8006 24.28L52.5486 25.696H52.2006C51.6726 25.696 51.2486 25.828 50.9286 26.092C50.6086 26.356 50.3846 26.812 50.2566 27.46L49.6326 31H48.2646L49.4286 24.388H50.7966L50.5926 25.552Z" fill="#667085"/>
|
||||
<path d="M44.89 24.28C45.714 24.28 46.37 24.512 46.858 24.976C47.354 25.44 47.602 26.064 47.602 26.848C47.602 27.032 47.582 27.252 47.542 27.508C47.51 27.684 47.454 27.9 47.374 28.156H42.322C42.314 28.212 42.31 28.296 42.31 28.408C42.31 28.88 42.454 29.256 42.742 29.536C43.038 29.816 43.422 29.956 43.894 29.956C44.638 29.956 45.21 29.648 45.61 29.032H47.086C46.782 29.64 46.334 30.14 45.742 30.532C45.15 30.916 44.466 31.108 43.69 31.108C43.138 31.108 42.654 31 42.238 30.784C41.822 30.568 41.498 30.26 41.266 29.86C41.034 29.452 40.918 28.976 40.918 28.432C40.918 28.2 40.942 27.952 40.99 27.688C41.11 27.008 41.354 26.412 41.722 25.9C42.09 25.38 42.546 24.98 43.09 24.7C43.642 24.42 44.242 24.28 44.89 24.28ZM46.174 27.172C46.19 27.028 46.198 26.924 46.198 26.86C46.198 26.42 46.05 26.072 45.754 25.816C45.466 25.56 45.09 25.432 44.626 25.432C44.138 25.432 43.698 25.588 43.306 25.9C42.914 26.212 42.646 26.636 42.502 27.172H46.174Z" fill="#667085"/>
|
||||
<path d="M37.4837 24.28C38.3077 24.28 38.9637 24.512 39.4517 24.976C39.9477 25.44 40.1957 26.064 40.1957 26.848C40.1957 27.032 40.1757 27.252 40.1357 27.508C40.1037 27.684 40.0477 27.9 39.9677 28.156H34.9157C34.9077 28.212 34.9037 28.296 34.9037 28.408C34.9037 28.88 35.0477 29.256 35.3357 29.536C35.6317 29.816 36.0157 29.956 36.4877 29.956C37.2317 29.956 37.8037 29.648 38.2037 29.032H39.6797C39.3757 29.64 38.9277 30.14 38.3357 30.532C37.7437 30.916 37.0597 31.108 36.2837 31.108C35.7317 31.108 35.2477 31 34.8317 30.784C34.4157 30.568 34.0917 30.26 33.8597 29.86C33.6277 29.452 33.5117 28.976 33.5117 28.432C33.5117 28.2 33.5357 27.952 33.5837 27.688C33.7037 27.008 33.9477 26.412 34.3157 25.9C34.6837 25.38 35.1397 24.98 35.6837 24.7C36.2357 24.42 36.8357 24.28 37.4837 24.28ZM38.7677 27.172C38.7837 27.028 38.7917 26.924 38.7917 26.86C38.7917 26.42 38.6437 26.072 38.3477 25.816C38.0597 25.56 37.6837 25.432 37.2197 25.432C36.7317 25.432 36.2917 25.588 35.8997 25.9C35.5077 26.212 35.2397 26.636 35.0957 27.172H38.7677Z" fill="#667085"/>
|
||||
<path d="M30.1832 24.28C30.8792 24.28 31.4312 24.468 31.8392 24.844C32.2552 25.212 32.4632 25.744 32.4632 26.44C32.4632 26.616 32.4432 26.836 32.4032 27.1L31.7072 31H30.3512L31.0112 27.304C31.0432 27.08 31.0592 26.92 31.0592 26.824C31.0592 26.384 30.9352 26.048 30.6872 25.816C30.4472 25.584 30.1112 25.468 29.6792 25.468C29.1592 25.468 28.7192 25.628 28.3592 25.948C28.0072 26.26 27.7832 26.712 27.6872 27.304V27.268L27.0272 31H25.6592L26.8232 24.388H28.1912L28.0592 25.156C28.3312 24.884 28.6512 24.672 29.0192 24.52C29.3952 24.36 29.7832 24.28 30.1832 24.28Z" fill="#667085"/>
|
||||
<path d="M24.5111 23.512C24.2951 23.512 24.1191 23.444 23.9831 23.308C23.8471 23.172 23.7791 23 23.7791 22.792C23.7791 22.512 23.8831 22.272 24.0911 22.072C24.3071 21.864 24.5511 21.76 24.8231 21.76C25.0391 21.76 25.2111 21.828 25.3391 21.964C25.4751 22.1 25.5431 22.272 25.5431 22.48C25.5431 22.76 25.4391 23.004 25.2311 23.212C25.0231 23.412 24.7831 23.512 24.5111 23.512ZM25.0271 24.388L23.8631 31H22.4951L23.6591 24.388H25.0271Z" fill="#667085"/>
|
||||
<path d="M18.2144 24.28C18.7264 24.28 19.1624 24.384 19.5224 24.592C19.8904 24.792 20.1544 25.044 20.3144 25.348L20.4824 24.388H21.8624L20.6864 31.108C20.5744 31.716 20.3504 32.256 20.0144 32.728C19.6784 33.208 19.2424 33.584 18.7064 33.856C18.1704 34.128 17.5664 34.264 16.8944 34.264C16.3104 34.264 15.7984 34.168 15.3584 33.976C14.9184 33.792 14.5864 33.524 14.3624 33.172C14.1384 32.82 14.0424 32.404 14.0744 31.924H15.4304C15.4704 32.268 15.6424 32.544 15.9464 32.752C16.2504 32.968 16.6384 33.076 17.1104 33.076C17.6624 33.076 18.1384 32.908 18.5384 32.572C18.9384 32.236 19.1944 31.748 19.3064 31.108L19.4984 30.004C19.2104 30.316 18.8504 30.58 18.4184 30.796C17.9864 31.004 17.5184 31.108 17.0144 31.108C16.5104 31.108 16.0624 30.996 15.6704 30.772C15.2784 30.548 14.9704 30.232 14.7464 29.824C14.5304 29.408 14.4224 28.932 14.4224 28.396C14.4224 28.156 14.4464 27.912 14.4944 27.664C14.6144 27 14.8544 26.412 15.2144 25.9C15.5824 25.388 16.0304 24.992 16.5584 24.712C17.0864 24.424 17.6384 24.28 18.2144 24.28ZM19.9064 27.688C19.9384 27.536 19.9544 27.372 19.9544 27.196C19.9544 26.66 19.7944 26.24 19.4744 25.936C19.1624 25.624 18.7704 25.468 18.2984 25.468C17.9464 25.468 17.6024 25.556 17.2664 25.732C16.9304 25.9 16.6384 26.152 16.3904 26.488C16.1424 26.816 15.9784 27.208 15.8984 27.664C15.8664 27.816 15.8504 27.98 15.8504 28.156C15.8504 28.7 16.0064 29.132 16.3184 29.452C16.6384 29.764 17.0344 29.92 17.5064 29.92C17.8584 29.92 18.2024 29.832 18.5384 29.656C18.8744 29.48 19.1664 29.224 19.4144 28.888C19.6624 28.544 19.8264 28.144 19.9064 27.688Z" fill="#667085"/>
|
||||
<path d="M11.0933 24.28C11.7893 24.28 12.3413 24.468 12.7493 24.844C13.1653 25.212 13.3733 25.744 13.3733 26.44C13.3733 26.616 13.3533 26.836 13.3133 27.1L12.6173 31H11.2613L11.9213 27.304C11.9533 27.08 11.9693 26.92 11.9693 26.824C11.9693 26.384 11.8453 26.048 11.5973 25.816C11.3573 25.584 11.0213 25.468 10.5893 25.468C10.0693 25.468 9.62934 25.628 9.26934 25.948C8.91734 26.26 8.69334 26.712 8.59734 27.304V27.268L7.93734 31H6.56934L7.73334 24.388H9.10134L8.96934 25.156C9.24134 24.884 9.56134 24.672 9.92934 24.52C10.3053 24.36 10.6933 24.28 11.0933 24.28Z" fill="#667085"/>
|
||||
<path d="M2.92837 23.7159L2.48437 26.2479H5.36437L5.18437 27.3039H2.30437L1.83637 29.9319H5.07637L4.88437 30.9999H0.276367L1.75237 22.6479H6.36037L6.16837 23.7159H2.92837Z" fill="#667085"/>
|
||||
</svg>
|
After Width: | Height: | Size: 11 KiB |
@ -1,11 +1,11 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import produce from 'immer'
|
||||
import { useBoolean } from 'ahooks'
|
||||
import { useBoolean, useGetState } from 'ahooks'
|
||||
import cn from 'classnames'
|
||||
import { clone, isEqual } from 'lodash-es'
|
||||
import Button from '../../base/button'
|
||||
@ -33,6 +33,7 @@ import { FlipBackward } from '@/app/components/base/icons/src/vender/line/arrows
|
||||
import { PromptMode } from '@/models/debug'
|
||||
import { DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
|
||||
import SelectDataSet from '@/app/components/app/configuration/dataset-config/select-dataset'
|
||||
import I18n from '@/context/i18n'
|
||||
|
||||
type PublichConfig = {
|
||||
modelConfig: ModelConfig
|
||||
@ -74,13 +75,26 @@ const Configuration: FC = () => {
|
||||
const [formattingChanged, setFormattingChanged] = useState(false)
|
||||
const [inputs, setInputs] = useState<Inputs>({})
|
||||
const [query, setQuery] = useState('')
|
||||
const [completionParams, setCompletionParams] = useState<CompletionParams>({
|
||||
const [completionParams, doSetCompletionParams] = useState<CompletionParams>({
|
||||
max_tokens: 16,
|
||||
temperature: 1, // 0-2
|
||||
top_p: 1,
|
||||
presence_penalty: 1, // -2-2
|
||||
frequency_penalty: 1, // -2-2
|
||||
stop: [],
|
||||
})
|
||||
const [tempStop, setTempStop, getTempStop] = useGetState<string[]>([])
|
||||
const setCompletionParams = (value: CompletionParams) => {
|
||||
const params = { ...value }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
if ((!params.stop || params.stop.length === 0) && (modeModeTypeRef.current === ModelModeType.completion)) {
|
||||
params.stop = getTempStop()
|
||||
setTempStop([])
|
||||
}
|
||||
doSetCompletionParams(params)
|
||||
}
|
||||
|
||||
const [modelConfig, doSetModelConfig] = useState<ModelConfig>({
|
||||
provider: ProviderEnum.openai,
|
||||
model_id: 'gpt-3.5-turbo',
|
||||
@ -110,6 +124,10 @@ const Configuration: FC = () => {
|
||||
}
|
||||
|
||||
const modelModeType = modelConfig.mode
|
||||
const modeModeTypeRef = useRef(modelModeType)
|
||||
useEffect(() => {
|
||||
modeModeTypeRef.current = modelModeType
|
||||
}, [modelModeType])
|
||||
|
||||
const [dataSets, setDataSets] = useState<DataSet[]>([])
|
||||
const contextVar = modelConfig.configs.prompt_variables.find(item => item.is_context_var)?.key
|
||||
@ -197,7 +215,7 @@ const Configuration: FC = () => {
|
||||
const hasSetAPIKEY = hasSetCustomAPIKEY || !isTrailFinished
|
||||
|
||||
const [isShowSetAPIKey, { setTrue: showSetAPIKey, setFalse: hideSetAPIkey }] = useBoolean()
|
||||
const [promptMode, doSetPromptMode] = useState(PromptMode.advanced)
|
||||
const [promptMode, doSetPromptMode] = useState(PromptMode.simple)
|
||||
const isAdvancedMode = promptMode === PromptMode.advanced
|
||||
const [canReturnToSimpleMode, setCanReturnToSimpleMode] = useState(true)
|
||||
const setPromptMode = async (mode: PromptMode) => {
|
||||
@ -230,6 +248,9 @@ const Configuration: FC = () => {
|
||||
onUserChangedPrompt: () => {
|
||||
setCanReturnToSimpleMode(false)
|
||||
},
|
||||
completionParams,
|
||||
setCompletionParams,
|
||||
setStop: setTempStop,
|
||||
})
|
||||
|
||||
const setModel = async ({
|
||||
@ -449,6 +470,7 @@ const Configuration: FC = () => {
|
||||
|
||||
const [showUseGPT4Confirm, setShowUseGPT4Confirm] = useState(false)
|
||||
const [showSetAPIKeyModal, setShowSetAPIKeyModal] = useState(false)
|
||||
const { locale } = useContext(I18n)
|
||||
|
||||
if (isLoading) {
|
||||
return <div className='flex h-full items-center justify-center'>
|
||||
@ -513,10 +535,9 @@ const Configuration: FC = () => {
|
||||
<>
|
||||
<div className="flex flex-col h-full">
|
||||
<div className='flex items-center justify-between px-6 shrink-0 h-14'>
|
||||
<div>
|
||||
<div className='italic text-base font-bold text-gray-900 leading-[18px]'>{t('appDebug.pageTitle.line1')}</div>
|
||||
<div className='flex items-center h-6 space-x-1 text-xs'>
|
||||
<div className='text-gray-500 font-medium italic'>{t('appDebug.pageTitle.line2')}</div>
|
||||
<div className='flex items-end'>
|
||||
<div className={s.promptTitle}></div>
|
||||
<div className='flex items-center h-[14px] space-x-1 text-xs'>
|
||||
{/* modelModeType missing can not load template */}
|
||||
{(!isAdvancedMode && modelModeType) && (
|
||||
<div
|
||||
@ -528,7 +549,7 @@ const Configuration: FC = () => {
|
||||
)}
|
||||
{isAdvancedMode && (
|
||||
<div className='flex items-center space-x-2'>
|
||||
<div className={`${s.advancedPromptMode} italic text-indigo-600`}>{t('appDebug.promptMode.advanced')}</div>
|
||||
<div className={cn(locale === 'en' && 'italic', `${s.advancedPromptMode} text-indigo-600`)}>{t('appDebug.promptMode.advanced')}</div>
|
||||
{canReturnToSimpleMode && (
|
||||
<div
|
||||
onClick={() => setPromptMode(PromptMode.simple)}
|
||||
|
@ -1,3 +1,10 @@
|
||||
.promptTitle {
|
||||
width: 72px;
|
||||
height: 31px;
|
||||
background: url(./images/prompt.svg) no-repeat 0 0;
|
||||
background-size: contain;
|
||||
}
|
||||
|
||||
.advancedPromptMode {
|
||||
position: relative;
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ const translation = {
|
||||
line2: 'Engineering',
|
||||
},
|
||||
promptMode: {
|
||||
simple: 'Switch to Advanced Mode to edit the built-in PROMPT',
|
||||
simple: 'Switch to Advanced Mode to edit the whole PROMPT',
|
||||
advanced: 'Advanced Mode',
|
||||
switchBack: 'Switch back',
|
||||
advancedWarning: {
|
||||
title: 'You have switched to Advanced Mode, and once you modify the PROMPT, you CANNOT return to the simple mode.',
|
||||
description: 'In Advanced Mode, you can edit built-in PROMPT.',
|
||||
description: 'In Advanced Mode, you can edit whole PROMPT.',
|
||||
learnMore: 'Learn more',
|
||||
ok: 'OK',
|
||||
},
|
||||
|
@ -4,12 +4,12 @@ const translation = {
|
||||
line2: '编排',
|
||||
},
|
||||
promptMode: {
|
||||
simple: '切换到高级模式以编辑内置的提示词',
|
||||
simple: '切换到高级模式以编辑完整的提示词',
|
||||
advanced: '高级模式',
|
||||
switchBack: '返回简单模式',
|
||||
advancedWarning: {
|
||||
title: '您已切换到高级模式,一旦修改提示词,将无法返回简单模式。',
|
||||
description: '在高级模式下,您可以编辑内置的提示词。',
|
||||
description: '在高级模式下,您可以编辑完整的提示词。',
|
||||
learnMore: '了解更多',
|
||||
ok: '确定',
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ export const fetchPromptTemplate = ({
|
||||
modelName,
|
||||
hasSetDataSet,
|
||||
}: { appMode: string; mode: ModelModeType; modelName: string; hasSetDataSet: boolean }) => {
|
||||
return get<Promise<{ chat_prompt_config: ChatPromptConfig; completion_prompt_config: CompletionPromptConfig }>>('/app/prompt-templates', {
|
||||
return get<Promise<{ chat_prompt_config: ChatPromptConfig; completion_prompt_config: CompletionPromptConfig; stop: [] }>>('/app/prompt-templates', {
|
||||
params: {
|
||||
app_mode: appMode,
|
||||
model_mode: mode,
|
||||
|
Loading…
Reference in New Issue
Block a user