Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
883a0a0e
Unverified
Commit
883a0a0e
authored
Jan 31, 2024
by
Joel
Committed by
GitHub
Jan 31, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: detect is function calling from model config (#2312)
parent
b5ed81b3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
43 deletions
+11
-43
index.tsx
web/app/components/app/configuration/index.tsx
+10
-2
hooks.ts
...nents/header/account-setting/model-provider-page/hooks.ts
+0
-14
index.ts
web/config/index.ts
+0
-2
provider-context.tsx
web/context/provider-context.tsx
+1
-25
No files found.
web/app/components/app/configuration/index.tsx
View file @
883a0a0e
...
@@ -46,7 +46,7 @@ import { fetchDatasets } from '@/service/datasets'
...
@@ -46,7 +46,7 @@ import { fetchDatasets } from '@/service/datasets'
import
{
useProviderContext
}
from
'@/context/provider-context'
import
{
useProviderContext
}
from
'@/context/provider-context'
import
{
AgentStrategy
,
AppType
,
ModelModeType
,
RETRIEVE_TYPE
,
Resolution
,
TransferMethod
}
from
'@/types/app'
import
{
AgentStrategy
,
AppType
,
ModelModeType
,
RETRIEVE_TYPE
,
Resolution
,
TransferMethod
}
from
'@/types/app'
import
{
PromptMode
}
from
'@/models/debug'
import
{
PromptMode
}
from
'@/models/debug'
import
{
ANNOTATION_DEFAULT
,
DEFAULT_AGENT_SETTING
,
DEFAULT_CHAT_PROMPT_CONFIG
,
DEFAULT_COMPLETION_PROMPT_CONFIG
,
supportFunctionCallModels
}
from
'@/config'
import
{
ANNOTATION_DEFAULT
,
DEFAULT_AGENT_SETTING
,
DEFAULT_CHAT_PROMPT_CONFIG
,
DEFAULT_COMPLETION_PROMPT_CONFIG
}
from
'@/config'
import
SelectDataSet
from
'@/app/components/app/configuration/dataset-config/select-dataset'
import
SelectDataSet
from
'@/app/components/app/configuration/dataset-config/select-dataset'
import
{
useModalContext
}
from
'@/context/modal-context'
import
{
useModalContext
}
from
'@/context/modal-context'
import
useBreakpoints
,
{
MediaType
}
from
'@/hooks/use-breakpoints'
import
useBreakpoints
,
{
MediaType
}
from
'@/hooks/use-breakpoints'
...
@@ -157,6 +157,7 @@ const Configuration: FC = () => {
...
@@ -157,6 +157,7 @@ const Configuration: FC = () => {
dataSets
:
[],
dataSets
:
[],
agentConfig
:
DEFAULT_AGENT_SETTING
,
agentConfig
:
DEFAULT_AGENT_SETTING
,
})
})
const
isChatApp
=
mode
===
AppType
.
chat
const
isChatApp
=
mode
===
AppType
.
chat
const
isAgent
=
modelConfig
.
agentConfig
?.
enabled
const
isAgent
=
modelConfig
.
agentConfig
?.
enabled
const
setIsAgent
=
(
value
:
boolean
)
=>
{
const
setIsAgent
=
(
value
:
boolean
)
=>
{
...
@@ -166,7 +167,7 @@ const Configuration: FC = () => {
...
@@ -166,7 +167,7 @@ const Configuration: FC = () => {
doSetModelConfig
(
newModelConfig
)
doSetModelConfig
(
newModelConfig
)
}
}
const
isOpenAI
=
modelConfig
.
provider
===
'openai'
const
isOpenAI
=
modelConfig
.
provider
===
'openai'
const
isFunctionCall
=
(
isOpenAI
&&
modelConfig
.
mode
===
ModelModeType
.
chat
)
||
supportFunctionCallModels
.
includes
(
modelConfig
.
model_id
)
const
[
collectionList
,
setCollectionList
]
=
useState
<
Collection
[]
>
([])
const
[
collectionList
,
setCollectionList
]
=
useState
<
Collection
[]
>
([])
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -262,6 +263,13 @@ const Configuration: FC = () => {
...
@@ -262,6 +263,13 @@ const Configuration: FC = () => {
},
},
)
)
const
isFunctionCall
=
(()
=>
{
const
features
=
currModel
?.
features
if
(
!
features
)
return
false
return
features
.
includes
(
ModelFeatureEnum
.
toolCall
)
||
features
.
includes
(
ModelFeatureEnum
.
multiToolCall
)
})()
// Fill old app data missing model mode.
// Fill old app data missing model mode.
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
hasFetchedDetail
&&
!
modelModeType
)
{
if
(
hasFetchedDetail
&&
!
modelModeType
)
{
...
...
web/app/components/header/account-setting/model-provider-page/hooks.ts
View file @
883a0a0e
...
@@ -153,20 +153,6 @@ export const useTextGenerationCurrentProviderAndModelAndModelList = (defaultMode
...
@@ -153,20 +153,6 @@ export const useTextGenerationCurrentProviderAndModelAndModelList = (defaultMode
}
}
}
}
export const useAgentThoughtCurrentProviderAndModelAndModelList = (defaultModel?: DefaultModel) => {
const { agentThoughtModelList } = useProviderContext()
const {
currentProvider,
currentModel,
} = useCurrentProviderAndModel(agentThoughtModelList, defaultModel)
return {
currentProvider,
currentModel,
agentThoughtModelList,
}
}
export const useModelListAndDefaultModel = (type: ModelTypeIndex) => {
export const useModelListAndDefaultModel = (type: ModelTypeIndex) => {
const { data: modelList } = useModelList(type)
const { data: modelList } = useModelList(type)
const { data: defaultModel } = useDefaultModel(type)
const { data: defaultModel } = useDefaultModel(type)
...
...
web/config/index.ts
View file @
883a0a0e
...
@@ -139,8 +139,6 @@ export const DEFAULT_AGENT_SETTING = {
...
@@ -139,8 +139,6 @@ export const DEFAULT_AGENT_SETTING = {
tools
:
[],
tools
:
[],
}
}
export
const
supportFunctionCallModels
=
[
'glm-3-turbo'
,
'glm-4'
]
export
const
DEFAULT_AGENT_PROMPT
=
{
export
const
DEFAULT_AGENT_PROMPT
=
{
chat
:
`Respond to the human as helpfully and accurately as possible.
chat
:
`Respond to the human as helpfully and accurately as possible.
...
...
web/context/provider-context.tsx
View file @
883a0a0e
...
@@ -2,14 +2,13 @@
...
@@ -2,14 +2,13 @@
import
{
createContext
,
useContext
}
from
'use-context-selector'
import
{
createContext
,
useContext
}
from
'use-context-selector'
import
useSWR
from
'swr'
import
useSWR
from
'swr'
import
{
useEffect
,
use
Memo
,
use
State
}
from
'react'
import
{
useEffect
,
useState
}
from
'react'
import
{
import
{
fetchModelList
,
fetchModelList
,
fetchModelProviders
,
fetchModelProviders
,
fetchSupportRetrievalMethods
,
fetchSupportRetrievalMethods
,
}
from
'@/service/common'
}
from
'@/service/common'
import
{
import
{
ModelFeatureEnum
,
ModelStatusEnum
,
ModelStatusEnum
,
ModelTypeEnum
,
ModelTypeEnum
,
}
from
'@/app/components/header/account-setting/model-provider-page/declarations'
}
from
'@/app/components/header/account-setting/model-provider-page/declarations'
...
@@ -23,7 +22,6 @@ import { defaultPlan } from '@/app/components/billing/config'
...
@@ -23,7 +22,6 @@ import { defaultPlan } from '@/app/components/billing/config'
const
ProviderContext
=
createContext
<
{
const
ProviderContext
=
createContext
<
{
modelProviders
:
ModelProvider
[]
modelProviders
:
ModelProvider
[]
textGenerationModelList
:
Model
[]
textGenerationModelList
:
Model
[]
agentThoughtModelList
:
Model
[]
supportRetrievalMethods
:
RETRIEVE_METHOD
[]
supportRetrievalMethods
:
RETRIEVE_METHOD
[]
hasSettedApiKey
:
boolean
hasSettedApiKey
:
boolean
plan
:
{
plan
:
{
...
@@ -38,7 +36,6 @@ const ProviderContext = createContext<{
...
@@ -38,7 +36,6 @@ const ProviderContext = createContext<{
}
>
({
}
>
({
modelProviders
:
[],
modelProviders
:
[],
textGenerationModelList
:
[],
textGenerationModelList
:
[],
agentThoughtModelList
:
[],
supportRetrievalMethods
:
[],
supportRetrievalMethods
:
[],
hasSettedApiKey
:
true
,
hasSettedApiKey
:
true
,
plan
:
{
plan
:
{
...
@@ -75,26 +72,6 @@ export const ProviderContextProvider = ({
...
@@ -75,26 +72,6 @@ export const ProviderContextProvider = ({
const
{
data
:
textGenerationModelList
}
=
useSWR
(
`
${
fetchModelListUrlPrefix
}${
ModelTypeEnum
.
textGeneration
}
`
,
fetchModelList
)
const
{
data
:
textGenerationModelList
}
=
useSWR
(
`
${
fetchModelListUrlPrefix
}${
ModelTypeEnum
.
textGeneration
}
`
,
fetchModelList
)
const
{
data
:
supportRetrievalMethods
}
=
useSWR
(
'/datasets/retrieval-setting'
,
fetchSupportRetrievalMethods
)
const
{
data
:
supportRetrievalMethods
}
=
useSWR
(
'/datasets/retrieval-setting'
,
fetchSupportRetrievalMethods
)
const
agentThoughtModelList
=
useMemo
(()
=>
{
const
result
:
Model
[]
=
[]
if
(
textGenerationModelList
?.
data
)
{
textGenerationModelList
?.
data
.
forEach
((
item
)
=>
{
const
agentThoughtModels
=
item
.
models
.
filter
(
model
=>
model
.
features
?.
includes
(
ModelFeatureEnum
.
agentThought
))
if
(
agentThoughtModels
.
length
)
{
result
.
push
({
...
item
,
models
:
agentThoughtModels
,
})
}
})
return
result
}
return
[]
},
[
textGenerationModelList
])
const
[
plan
,
setPlan
]
=
useState
(
defaultPlan
)
const
[
plan
,
setPlan
]
=
useState
(
defaultPlan
)
const
[
isFetchedPlan
,
setIsFetchedPlan
]
=
useState
(
false
)
const
[
isFetchedPlan
,
setIsFetchedPlan
]
=
useState
(
false
)
const
[
enableBilling
,
setEnableBilling
]
=
useState
(
true
)
const
[
enableBilling
,
setEnableBilling
]
=
useState
(
true
)
...
@@ -118,7 +95,6 @@ export const ProviderContextProvider = ({
...
@@ -118,7 +95,6 @@ export const ProviderContextProvider = ({
<
ProviderContext
.
Provider
value=
{
{
<
ProviderContext
.
Provider
value=
{
{
modelProviders
:
providersData
?.
data
||
[],
modelProviders
:
providersData
?.
data
||
[],
textGenerationModelList
:
textGenerationModelList
?.
data
||
[],
textGenerationModelList
:
textGenerationModelList
?.
data
||
[],
agentThoughtModelList
,
hasSettedApiKey
:
!!
textGenerationModelList
?.
data
.
some
(
model
=>
model
.
status
===
ModelStatusEnum
.
active
),
hasSettedApiKey
:
!!
textGenerationModelList
?.
data
.
some
(
model
=>
model
.
status
===
ModelStatusEnum
.
active
),
supportRetrievalMethods
:
supportRetrievalMethods
?.
retrieval_method
||
[],
supportRetrievalMethods
:
supportRetrievalMethods
?.
retrieval_method
||
[],
plan
,
plan
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment