mirror of
https://github.com/langgenius/dify.git
synced 2026-04-21 03:07:39 +08:00
chore: add skill true for sandbox agent llm
This commit is contained in:
@ -2,6 +2,7 @@ import type { Memory, PromptItem, PromptTemplateItem, ValueSelector, Var, Variab
|
||||
import type { LLMNodeType, StructuredOutput } from './types'
|
||||
import { produce } from 'immer'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useFeatures } from '@/app/components/base/features/hooks'
|
||||
import { checkHasContextBlock, checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/constants'
|
||||
import {
|
||||
ModelFeatureEnum,
|
||||
@ -23,6 +24,8 @@ import useAvailableVarList from '../_base/hooks/use-available-var-list'
|
||||
const useConfig = (id: string, payload: LLMNodeType) => {
|
||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||
const isChatMode = useIsChatMode()
|
||||
const features = useFeatures(s => s.features)
|
||||
const isSupportSandbox = !!features.sandbox?.enabled
|
||||
|
||||
const defaultConfig = useStore(s => s.nodesDefaultConfigs)?.[payload.type]
|
||||
const [defaultRolePrefix, setDefaultRolePrefix] = useState<{ user: string, assistant: string }>({ user: '', assistant: '' })
|
||||
@ -35,17 +38,37 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
||||
const { deleteNodeInspectorVars } = useInspectVarsCrud()
|
||||
|
||||
const setInputs = useCallback((newInputs: LLMNodeType) => {
|
||||
let newPayload = { ...newInputs }
|
||||
if (newInputs.memory && !newInputs.memory.role_prefix) {
|
||||
const newPayload = produce(newInputs, (draft) => {
|
||||
newPayload = produce(newInputs, (draft) => {
|
||||
draft.memory!.role_prefix = defaultRolePrefix
|
||||
})
|
||||
doSetInputs(newPayload)
|
||||
inputRef.current = newPayload
|
||||
return
|
||||
}
|
||||
doSetInputs(newInputs)
|
||||
inputRef.current = newInputs
|
||||
}, [doSetInputs, defaultRolePrefix])
|
||||
|
||||
// set skill=true for sandbox
|
||||
if (isSupportSandbox) {
|
||||
if (Array.isArray(newPayload.prompt_template) && newPayload.prompt_template.find(item => !item.skill)) {
|
||||
newPayload = produce(newPayload, (draft) => {
|
||||
draft.prompt_template = (draft.prompt_template as PromptItem[]).map((item) => {
|
||||
return {
|
||||
...item,
|
||||
skill: true,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
else if (!Array.isArray(newPayload.prompt_template) && !newPayload.prompt_template.skill) {
|
||||
newPayload = produce(newPayload, (draft) => {
|
||||
draft.prompt_template = {
|
||||
...draft.prompt_template,
|
||||
skill: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
doSetInputs(newPayload)
|
||||
inputRef.current = newPayload
|
||||
}, [doSetInputs, defaultRolePrefix, isSupportSandbox])
|
||||
|
||||
// model
|
||||
const model = inputs.model
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable ts/no-explicit-any */
|
||||
import type {
|
||||
Edge as ReactFlowEdge,
|
||||
Node as ReactFlowNode,
|
||||
@ -255,11 +256,15 @@ export type PromptItem = {
|
||||
text: string
|
||||
edition_type?: EditionType
|
||||
jinja2_text?: string
|
||||
skill?: boolean
|
||||
metadata?: Record<string, any>
|
||||
}
|
||||
|
||||
export type PromptMessageContext = {
|
||||
id?: string
|
||||
$context: ValueSelector
|
||||
skill?: boolean
|
||||
metadata?: Record<string, any>
|
||||
}
|
||||
|
||||
export type PromptTemplateItem = PromptItem | PromptMessageContext
|
||||
|
||||
@ -4005,9 +4005,6 @@
|
||||
"app/components/workflow/types.ts": {
|
||||
"ts/no-empty-object-type": {
|
||||
"count": 3
|
||||
},
|
||||
"ts/no-explicit-any": {
|
||||
"count": 8
|
||||
}
|
||||
},
|
||||
"app/components/workflow/update-dsl-modal.tsx": {
|
||||
|
||||
Reference in New Issue
Block a user