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
9c5cdd7d
Commit
9c5cdd7d
authored
Jul 15, 2023
by
John Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add support tools
parent
146a2fac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
app_model_config_service.py
api/services/app_model_config_service.py
+25
-3
No files found.
api/services/app_model_config_service.py
View file @
9c5cdd7d
...
...
@@ -7,6 +7,16 @@ from services.dataset_service import DatasetService
from
core.llm.llm_builder
import
LLMBuilder
SUPPORT_AGENT_MODELS
=
[
"gpt-4"
,
"gpt-4-32k"
,
"gpt-3.5-turbo"
,
"gpt-3.5-turbo-16k"
,
]
SUPPORT_TOOLS
=
[
"dataset"
,
"google_search"
,
"web_reader"
,
"wikipedia"
]
class
AppModelConfigService
:
@
staticmethod
def
is_dataset_exists
(
account
:
Account
,
dataset_id
:
str
)
->
bool
:
...
...
@@ -34,7 +44,8 @@ class AppModelConfigService:
if
not
isinstance
(
cp
[
"max_tokens"
],
int
)
or
cp
[
"max_tokens"
]
<=
0
or
cp
[
"max_tokens"
]
>
\
llm_constant
.
max_context_token_length
[
model_name
]:
raise
ValueError
(
"max_tokens must be an integer greater than 0 and not exceeding the maximum value of the corresponding model"
)
"max_tokens must be an integer greater than 0 "
"and not exceeding the maximum value of the corresponding model"
)
# temperature
if
'temperature'
not
in
cp
:
...
...
@@ -277,6 +288,17 @@ class AppModelConfigService:
if
not
isinstance
(
config
[
"agent_mode"
][
"enabled"
],
bool
):
raise
ValueError
(
"enabled in agent_mode must be of boolean type"
)
# provider
if
'model_provider'
not
in
config
[
"agent_mode"
]
or
config
[
"agent_mode"
][
"model_provider"
]
!=
"openai"
:
raise
ValueError
(
"agent_mode.model_provider must be 'openai'"
)
# model.name
if
'model_name'
not
in
config
[
"agent_mode"
]:
raise
ValueError
(
"agent_mode.model_name is required"
)
if
config
[
"agent_mode"
][
"model_name"
]
not
in
SUPPORT_AGENT_MODELS
:
raise
ValueError
(
"agent_mode.model_name must be in the specified model list"
)
if
"tools"
not
in
config
[
"agent_mode"
]
or
not
config
[
"agent_mode"
][
"tools"
]:
config
[
"agent_mode"
][
"tools"
]
=
[]
...
...
@@ -285,8 +307,8 @@ class AppModelConfigService:
for
tool
in
config
[
"agent_mode"
][
"tools"
]:
key
=
list
(
tool
.
keys
())[
0
]
if
key
not
in
[
"dataset"
]
:
raise
ValueError
(
"Keys in agent_mode.tools
list can only be 'dataset'
"
)
if
key
not
in
SUPPORT_TOOLS
:
raise
ValueError
(
"Keys in agent_mode.tools
must be in the specified tool list
"
)
tool_item
=
tool
[
key
]
...
...
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