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
14a19a3d
Unverified
Commit
14a19a3d
authored
Feb 08, 2024
by
Bowen Liang
Committed by
GitHub
Feb 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: apply ruff's pyflakes linter rules (#2420)
parent
1b04382a
Changes
34
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
91 additions
and
86 deletions
+91
-86
app.py
api/controllers/console/app/app.py
+2
-2
datasets.py
api/controllers/console/datasets/datasets.py
+4
-4
datasets_document.py
api/controllers/console/datasets/datasets_document.py
+8
-8
datasets_segments.py
api/controllers/console/datasets/datasets_segments.py
+6
-6
hit_testing.py
api/controllers/console/datasets/hit_testing.py
+2
-2
parameter.py
api/controllers/console/explore/parameter.py
+1
-1
image_preview.py
api/controllers/files/image_preview.py
+1
-1
tool_files.py
api/controllers/files/tool_files.py
+1
-1
app.py
api/controllers/service_api/app/app.py
+1
-1
segment.py
api/controllers/service_api/dataset/segment.py
+6
-6
app.py
api/controllers/web/app.py
+1
-1
assistant_app_runner.py
api/core/app_runner/assistant_app_runner.py
+1
-1
basic_app_runner.py
api/core/app_runner/basic_app_runner.py
+1
-1
assistant_base_runner.py
api/core/features/assistant_base_runner.py
+1
-1
assistant_cot_runner.py
api/core/features/assistant_cot_runner.py
+2
-2
assistant_fc_runner.py
api/core/features/assistant_fc_runner.py
+1
-1
vector_index.py
api/core/index/vector_index/vector_index.py
+1
-1
model_manager.py
api/core/model_manager.py
+6
-6
logging_callback.py
api/core/model_runtime/callbacks/logging_callback.py
+4
-4
llm.py
api/core/model_runtime/model_providers/baichuan/llm/llm.py
+1
-1
llm.py
..._runtime/model_providers/openai_api_compatible/llm/llm.py
+3
-3
text_embedding.py
...rs/openai_api_compatible/text_embedding/text_embedding.py
+2
-2
ernie_bot.py
...ore/model_runtime/model_providers/wenxin/llm/ernie_bot.py
+8
-8
_client.py
...el_runtime/model_providers/zhipuai/zhipuai_sdk/_client.py
+1
-1
rule_config_generator.py
api/core/prompt/output_parser/rule_config_generator.py
+2
-2
tool_model_manager.py
api/core/tools/model/tool_model_manager.py
+4
-4
analytics.py
api/core/tools/provider/builtin/yahoo/tools/analytics.py
+1
-1
news.py
api/core/tools/provider/builtin/yahoo/tools/news.py
+1
-1
ticker.py
api/core/tools/provider/builtin/yahoo/tools/ticker.py
+1
-1
tool.py
api/core/tools/tool/tool.py
+1
-1
helper.py
api/libs/helper.py
+1
-1
pyproject.toml
api/pyproject.toml
+7
-2
dataset_service.py
api/services/dataset_service.py
+4
-4
tools_manage_service.py
api/services/tools_manage_service.py
+4
-4
No files found.
api/controllers/console/app/app.py
View file @
14a19a3d
...
@@ -133,8 +133,8 @@ class AppListApi(Resource):
...
@@ -133,8 +133,8 @@ class AppListApi(Resource):
if
not
model_instance
:
if
not
model_instance
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Default System Reasoning Model available. Please configure "
"No Default System Reasoning Model available. Please configure "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
else
:
else
:
model_config_dict
[
"model"
][
"provider"
]
=
model_instance
.
provider
model_config_dict
[
"model"
][
"provider"
]
=
model_instance
.
provider
model_config_dict
[
"model"
][
"name"
]
=
model_instance
.
model
model_config_dict
[
"model"
][
"name"
]
=
model_instance
.
model
...
...
api/controllers/console/datasets/datasets.py
View file @
14a19a3d
...
@@ -288,8 +288,8 @@ class DatasetIndexingEstimateApi(Resource):
...
@@ -288,8 +288,8 @@ class DatasetIndexingEstimateApi(Resource):
args
[
'indexing_technique'
])
args
[
'indexing_technique'
])
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
elif
args
[
'info_list'
][
'data_source_type'
]
==
'notion_import'
:
elif
args
[
'info_list'
][
'data_source_type'
]
==
'notion_import'
:
...
@@ -304,8 +304,8 @@ class DatasetIndexingEstimateApi(Resource):
...
@@ -304,8 +304,8 @@ class DatasetIndexingEstimateApi(Resource):
args
[
'indexing_technique'
])
args
[
'indexing_technique'
])
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
else
:
else
:
...
...
api/controllers/console/datasets/datasets_document.py
View file @
14a19a3d
...
@@ -296,8 +296,8 @@ class DatasetInitApi(Resource):
...
@@ -296,8 +296,8 @@ class DatasetInitApi(Resource):
)
)
except
InvokeAuthorizationError
:
except
InvokeAuthorizationError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
...
@@ -372,8 +372,8 @@ class DocumentIndexingEstimateApi(DocumentResource):
...
@@ -372,8 +372,8 @@ class DocumentIndexingEstimateApi(DocumentResource):
'English'
,
dataset_id
)
'English'
,
dataset_id
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
...
@@ -442,8 +442,8 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):
...
@@ -442,8 +442,8 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):
'English'
,
dataset_id
)
'English'
,
dataset_id
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
elif
dataset
.
data_source_type
==
'notion_import'
:
elif
dataset
.
data_source_type
==
'notion_import'
:
...
@@ -456,8 +456,8 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):
...
@@ -456,8 +456,8 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):
None
,
'English'
,
dataset_id
)
None
,
'English'
,
dataset_id
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
else
:
else
:
...
...
api/controllers/console/datasets/datasets_segments.py
View file @
14a19a3d
...
@@ -143,8 +143,8 @@ class DatasetDocumentSegmentApi(Resource):
...
@@ -143,8 +143,8 @@ class DatasetDocumentSegmentApi(Resource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
...
@@ -234,8 +234,8 @@ class DatasetDocumentSegmentAddApi(Resource):
...
@@ -234,8 +234,8 @@ class DatasetDocumentSegmentAddApi(Resource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
try
:
try
:
...
@@ -286,8 +286,8 @@ class DatasetDocumentSegmentUpdateApi(Resource):
...
@@ -286,8 +286,8 @@ class DatasetDocumentSegmentUpdateApi(Resource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
# check segment
# check segment
...
...
api/controllers/console/datasets/hit_testing.py
View file @
14a19a3d
...
@@ -76,8 +76,8 @@ class HitTestingApi(Resource):
...
@@ -76,8 +76,8 @@ class HitTestingApi(Resource):
raise
ProviderModelCurrentlyNotSupportError
()
raise
ProviderModelCurrentlyNotSupportError
()
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model or Reranking Model available. Please configure a valid provider "
"No Embedding Model or Reranking Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
InvokeError
as
e
:
except
InvokeError
as
e
:
raise
CompletionRequestError
(
e
.
description
)
raise
CompletionRequestError
(
e
.
description
)
except
ValueError
as
e
:
except
ValueError
as
e
:
...
...
api/controllers/console/explore/parameter.py
View file @
14a19a3d
...
@@ -78,7 +78,7 @@ class ExploreAppMetaApi(InstalledAppResource):
...
@@ -78,7 +78,7 @@ class ExploreAppMetaApi(InstalledAppResource):
# get all tools
# get all tools
tools
=
agent_config
.
get
(
'tools'
,
[])
tools
=
agent_config
.
get
(
'tools'
,
[])
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
+
f
"/console/api/workspaces/current/tool-provider/builtin/"
)
+
"/console/api/workspaces/current/tool-provider/builtin/"
)
for
tool
in
tools
:
for
tool
in
tools
:
keys
=
list
(
tool
.
keys
())
keys
=
list
(
tool
.
keys
())
if
len
(
keys
)
>=
4
:
if
len
(
keys
)
>=
4
:
...
...
api/controllers/files/image_preview.py
View file @
14a19a3d
...
@@ -41,7 +41,7 @@ class WorkspaceWebappLogoApi(Resource):
...
@@ -41,7 +41,7 @@ class WorkspaceWebappLogoApi(Resource):
webapp_logo_file_id
=
custom_config
.
get
(
'replace_webapp_logo'
)
if
custom_config
is
not
None
else
None
webapp_logo_file_id
=
custom_config
.
get
(
'replace_webapp_logo'
)
if
custom_config
is
not
None
else
None
if
not
webapp_logo_file_id
:
if
not
webapp_logo_file_id
:
raise
NotFound
(
f
'webapp logo is not found'
)
raise
NotFound
(
'webapp logo is not found'
)
try
:
try
:
generator
,
mimetype
=
FileService
.
get_public_image_preview
(
generator
,
mimetype
=
FileService
.
get_public_image_preview
(
...
...
api/controllers/files/tool_files.py
View file @
14a19a3d
...
@@ -32,7 +32,7 @@ class ToolFilePreviewApi(Resource):
...
@@ -32,7 +32,7 @@ class ToolFilePreviewApi(Resource):
)
)
if
not
result
:
if
not
result
:
raise
NotFound
(
f
'file is not found'
)
raise
NotFound
(
'file is not found'
)
generator
,
mimetype
=
result
generator
,
mimetype
=
result
except
Exception
:
except
Exception
:
...
...
api/controllers/service_api/app/app.py
View file @
14a19a3d
...
@@ -78,7 +78,7 @@ class AppMetaApi(AppApiResource):
...
@@ -78,7 +78,7 @@ class AppMetaApi(AppApiResource):
# get all tools
# get all tools
tools
=
agent_config
.
get
(
'tools'
,
[])
tools
=
agent_config
.
get
(
'tools'
,
[])
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
+
f
"/console/api/workspaces/current/tool-provider/builtin/"
)
+
"/console/api/workspaces/current/tool-provider/builtin/"
)
for
tool
in
tools
:
for
tool
in
tools
:
keys
=
list
(
tool
.
keys
())
keys
=
list
(
tool
.
keys
())
if
len
(
keys
)
>=
4
:
if
len
(
keys
)
>=
4
:
...
...
api/controllers/service_api/dataset/segment.py
View file @
14a19a3d
...
@@ -46,8 +46,8 @@ class SegmentApi(DatasetApiResource):
...
@@ -46,8 +46,8 @@ class SegmentApi(DatasetApiResource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
# validate args
# validate args
...
@@ -90,8 +90,8 @@ class SegmentApi(DatasetApiResource):
...
@@ -90,8 +90,8 @@ class SegmentApi(DatasetApiResource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
...
@@ -182,8 +182,8 @@ class DatasetSegmentApi(DatasetApiResource):
...
@@ -182,8 +182,8 @@ class DatasetSegmentApi(DatasetApiResource):
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ProviderNotInitializeError
(
raise
ProviderNotInitializeError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
raise
ProviderNotInitializeError
(
ex
.
description
)
# check segment
# check segment
...
...
api/controllers/web/app.py
View file @
14a19a3d
...
@@ -77,7 +77,7 @@ class AppMeta(WebApiResource):
...
@@ -77,7 +77,7 @@ class AppMeta(WebApiResource):
# get all tools
# get all tools
tools
=
agent_config
.
get
(
'tools'
,
[])
tools
=
agent_config
.
get
(
'tools'
,
[])
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
+
f
"/console/api/workspaces/current/tool-provider/builtin/"
)
+
"/console/api/workspaces/current/tool-provider/builtin/"
)
for
tool
in
tools
:
for
tool
in
tools
:
keys
=
list
(
tool
.
keys
())
keys
=
list
(
tool
.
keys
())
if
len
(
keys
)
>=
4
:
if
len
(
keys
)
>=
4
:
...
...
api/core/app_runner/assistant_app_runner.py
View file @
14a19a3d
...
@@ -38,7 +38,7 @@ class AssistantApplicationRunner(AppRunner):
...
@@ -38,7 +38,7 @@ class AssistantApplicationRunner(AppRunner):
"""
"""
app_record
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
application_generate_entity
.
app_id
)
.
first
()
app_record
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
application_generate_entity
.
app_id
)
.
first
()
if
not
app_record
:
if
not
app_record
:
raise
ValueError
(
f
"App not found"
)
raise
ValueError
(
"App not found"
)
app_orchestration_config
=
application_generate_entity
.
app_orchestration_config_entity
app_orchestration_config
=
application_generate_entity
.
app_orchestration_config_entity
...
...
api/core/app_runner/basic_app_runner.py
View file @
14a19a3d
...
@@ -35,7 +35,7 @@ class BasicApplicationRunner(AppRunner):
...
@@ -35,7 +35,7 @@ class BasicApplicationRunner(AppRunner):
"""
"""
app_record
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
application_generate_entity
.
app_id
)
.
first
()
app_record
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
application_generate_entity
.
app_id
)
.
first
()
if
not
app_record
:
if
not
app_record
:
raise
ValueError
(
f
"App not found"
)
raise
ValueError
(
"App not found"
)
app_orchestration_config
=
application_generate_entity
.
app_orchestration_config_entity
app_orchestration_config
=
application_generate_entity
.
app_orchestration_config_entity
...
...
api/core/features/assistant_base_runner.py
View file @
14a19a3d
...
@@ -134,7 +134,7 @@ class BaseAssistantApplicationRunner(AppRunner):
...
@@ -134,7 +134,7 @@ class BaseAssistantApplicationRunner(AppRunner):
result
+=
f
"result link: {response.message}. please tell user to check it."
result
+=
f
"result link: {response.message}. please tell user to check it."
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE_LINK
or
\
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE_LINK
or
\
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE
:
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE
:
result
+=
f
"image has been created and sent to user already, you should tell user to check it now."
result
+=
"image has been created and sent to user already, you should tell user to check it now."
else
:
else
:
result
+=
f
"tool response: {response.message}."
result
+=
f
"tool response: {response.message}."
...
...
api/core/features/assistant_cot_runner.py
View file @
14a19a3d
...
@@ -238,7 +238,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -238,7 +238,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
message_file_ids
=
[
message_file
.
id
for
message_file
,
_
in
message_files
]
message_file_ids
=
[
message_file
.
id
for
message_file
,
_
in
message_files
]
except
ToolProviderCredentialValidationError
as
e
:
except
ToolProviderCredentialValidationError
as
e
:
error_response
=
f
"Please check your tool provider credentials"
error_response
=
"Please check your tool provider credentials"
except
(
except
(
ToolNotFoundError
,
ToolNotSupportedError
,
ToolProviderNotFoundError
ToolNotFoundError
,
ToolNotSupportedError
,
ToolProviderNotFoundError
)
as
e
:
)
as
e
:
...
@@ -473,7 +473,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -473,7 +473,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
next_iteration
=
agent_prompt_message
.
next_iteration
next_iteration
=
agent_prompt_message
.
next_iteration
if
not
isinstance
(
first_prompt
,
str
)
or
not
isinstance
(
next_iteration
,
str
):
if
not
isinstance
(
first_prompt
,
str
)
or
not
isinstance
(
next_iteration
,
str
):
raise
ValueError
(
f
"first_prompt or next_iteration is required in CoT agent mode"
)
raise
ValueError
(
"first_prompt or next_iteration is required in CoT agent mode"
)
# check instruction, tools, and tool_names slots
# check instruction, tools, and tool_names slots
if
not
first_prompt
.
find
(
"{{instruction}}"
)
>=
0
:
if
not
first_prompt
.
find
(
"{{instruction}}"
)
>=
0
:
...
...
api/core/features/assistant_fc_runner.py
View file @
14a19a3d
...
@@ -277,7 +277,7 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -277,7 +277,7 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
message_file_ids
.
append
(
message_file
.
id
)
message_file_ids
.
append
(
message_file
.
id
)
except
ToolProviderCredentialValidationError
as
e
:
except
ToolProviderCredentialValidationError
as
e
:
error_response
=
f
"Please check your tool provider credentials"
error_response
=
"Please check your tool provider credentials"
except
(
except
(
ToolNotFoundError
,
ToolNotSupportedError
,
ToolProviderNotFoundError
ToolNotFoundError
,
ToolNotSupportedError
,
ToolProviderNotFoundError
)
as
e
:
)
as
e
:
...
...
api/core/index/vector_index/vector_index.py
View file @
14a19a3d
...
@@ -26,7 +26,7 @@ class VectorIndex:
...
@@ -26,7 +26,7 @@ class VectorIndex:
vector_type
=
self
.
_dataset
.
index_struct_dict
[
'type'
]
vector_type
=
self
.
_dataset
.
index_struct_dict
[
'type'
]
if
not
vector_type
:
if
not
vector_type
:
raise
ValueError
(
f
"Vector store must be specified."
)
raise
ValueError
(
"Vector store must be specified."
)
if
vector_type
==
"weaviate"
:
if
vector_type
==
"weaviate"
:
from
core.index.vector_index.weaviate_vector_index
import
WeaviateConfig
,
WeaviateVectorIndex
from
core.index.vector_index.weaviate_vector_index
import
WeaviateConfig
,
WeaviateVectorIndex
...
...
api/core/model_manager.py
View file @
14a19a3d
...
@@ -63,7 +63,7 @@ class ModelInstance:
...
@@ -63,7 +63,7 @@ class ModelInstance:
:return: full response or stream response chunk generator result
:return: full response or stream response chunk generator result
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
LargeLanguageModel
):
if
not
isinstance
(
self
.
model_type_instance
,
LargeLanguageModel
):
raise
Exception
(
f
"Model type instance is not LargeLanguageModel"
)
raise
Exception
(
"Model type instance is not LargeLanguageModel"
)
self
.
model_type_instance
=
cast
(
LargeLanguageModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
LargeLanguageModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
@@ -88,7 +88,7 @@ class ModelInstance:
...
@@ -88,7 +88,7 @@ class ModelInstance:
:return: embeddings result
:return: embeddings result
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
TextEmbeddingModel
):
if
not
isinstance
(
self
.
model_type_instance
,
TextEmbeddingModel
):
raise
Exception
(
f
"Model type instance is not TextEmbeddingModel"
)
raise
Exception
(
"Model type instance is not TextEmbeddingModel"
)
self
.
model_type_instance
=
cast
(
TextEmbeddingModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
TextEmbeddingModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
@@ -112,7 +112,7 @@ class ModelInstance:
...
@@ -112,7 +112,7 @@ class ModelInstance:
:return: rerank result
:return: rerank result
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
RerankModel
):
if
not
isinstance
(
self
.
model_type_instance
,
RerankModel
):
raise
Exception
(
f
"Model type instance is not RerankModel"
)
raise
Exception
(
"Model type instance is not RerankModel"
)
self
.
model_type_instance
=
cast
(
RerankModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
RerankModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
@@ -135,7 +135,7 @@ class ModelInstance:
...
@@ -135,7 +135,7 @@ class ModelInstance:
:return: false if text is safe, true otherwise
:return: false if text is safe, true otherwise
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
ModerationModel
):
if
not
isinstance
(
self
.
model_type_instance
,
ModerationModel
):
raise
Exception
(
f
"Model type instance is not ModerationModel"
)
raise
Exception
(
"Model type instance is not ModerationModel"
)
self
.
model_type_instance
=
cast
(
ModerationModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
ModerationModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
@@ -155,7 +155,7 @@ class ModelInstance:
...
@@ -155,7 +155,7 @@ class ModelInstance:
:return: text for given audio file
:return: text for given audio file
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
Speech2TextModel
):
if
not
isinstance
(
self
.
model_type_instance
,
Speech2TextModel
):
raise
Exception
(
f
"Model type instance is not Speech2TextModel"
)
raise
Exception
(
"Model type instance is not Speech2TextModel"
)
self
.
model_type_instance
=
cast
(
Speech2TextModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
Speech2TextModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
@@ -176,7 +176,7 @@ class ModelInstance:
...
@@ -176,7 +176,7 @@ class ModelInstance:
:return: text for given audio file
:return: text for given audio file
"""
"""
if
not
isinstance
(
self
.
model_type_instance
,
TTSModel
):
if
not
isinstance
(
self
.
model_type_instance
,
TTSModel
):
raise
Exception
(
f
"Model type instance is not TTSModel"
)
raise
Exception
(
"Model type instance is not TTSModel"
)
self
.
model_type_instance
=
cast
(
TTSModel
,
self
.
model_type_instance
)
self
.
model_type_instance
=
cast
(
TTSModel
,
self
.
model_type_instance
)
return
self
.
model_type_instance
.
invoke
(
return
self
.
model_type_instance
.
invoke
(
...
...
api/core/model_runtime/callbacks/logging_callback.py
View file @
14a19a3d
...
@@ -30,7 +30,7 @@ class LoggingCallback(Callback):
...
@@ -30,7 +30,7 @@ class LoggingCallback(Callback):
"""
"""
self
.
print_text
(
"
\n
[on_llm_before_invoke]
\n
"
,
color
=
'blue'
)
self
.
print_text
(
"
\n
[on_llm_before_invoke]
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"Model: {model}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"Model: {model}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"Parameters:
\n
"
,
color
=
'blue'
)
self
.
print_text
(
"Parameters:
\n
"
,
color
=
'blue'
)
for
key
,
value
in
model_parameters
.
items
():
for
key
,
value
in
model_parameters
.
items
():
self
.
print_text
(
f
"
\t
{key}: {value}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"
\t
{key}: {value}
\n
"
,
color
=
'blue'
)
...
@@ -38,7 +38,7 @@ class LoggingCallback(Callback):
...
@@ -38,7 +38,7 @@ class LoggingCallback(Callback):
self
.
print_text
(
f
"
\t
stop: {stop}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"
\t
stop: {stop}
\n
"
,
color
=
'blue'
)
if
tools
:
if
tools
:
self
.
print_text
(
f
"
\t
Tools:
\n
"
,
color
=
'blue'
)
self
.
print_text
(
"
\t
Tools:
\n
"
,
color
=
'blue'
)
for
tool
in
tools
:
for
tool
in
tools
:
self
.
print_text
(
f
"
\t\t
{tool.name}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"
\t\t
{tool.name}
\n
"
,
color
=
'blue'
)
...
@@ -47,7 +47,7 @@ class LoggingCallback(Callback):
...
@@ -47,7 +47,7 @@ class LoggingCallback(Callback):
if
user
:
if
user
:
self
.
print_text
(
f
"User: {user}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"User: {user}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"Prompt messages:
\n
"
,
color
=
'blue'
)
self
.
print_text
(
"Prompt messages:
\n
"
,
color
=
'blue'
)
for
prompt_message
in
prompt_messages
:
for
prompt_message
in
prompt_messages
:
if
prompt_message
.
name
:
if
prompt_message
.
name
:
self
.
print_text
(
f
"
\t
name: {prompt_message.name}
\n
"
,
color
=
'blue'
)
self
.
print_text
(
f
"
\t
name: {prompt_message.name}
\n
"
,
color
=
'blue'
)
...
@@ -101,7 +101,7 @@ class LoggingCallback(Callback):
...
@@ -101,7 +101,7 @@ class LoggingCallback(Callback):
self
.
print_text
(
f
"Content: {result.message.content}
\n
"
,
color
=
'yellow'
)
self
.
print_text
(
f
"Content: {result.message.content}
\n
"
,
color
=
'yellow'
)
if
result
.
message
.
tool_calls
:
if
result
.
message
.
tool_calls
:
self
.
print_text
(
f
"Tool calls:
\n
"
,
color
=
'yellow'
)
self
.
print_text
(
"Tool calls:
\n
"
,
color
=
'yellow'
)
for
tool_call
in
result
.
message
.
tool_calls
:
for
tool_call
in
result
.
message
.
tool_calls
:
self
.
print_text
(
f
"
\t
{tool_call.id}
\n
"
,
color
=
'yellow'
)
self
.
print_text
(
f
"
\t
{tool_call.id}
\n
"
,
color
=
'yellow'
)
self
.
print_text
(
f
"
\t
{tool_call.function.name}
\n
"
,
color
=
'yellow'
)
self
.
print_text
(
f
"
\t
{tool_call.function.name}
\n
"
,
color
=
'yellow'
)
...
...
api/core/model_runtime/model_providers/baichuan/llm/llm.py
View file @
14a19a3d
...
@@ -110,7 +110,7 @@ class BaichuanLarguageModel(LargeLanguageModel):
...
@@ -110,7 +110,7 @@ class BaichuanLarguageModel(LargeLanguageModel):
stop
:
List
[
str
]
|
None
=
None
,
stream
:
bool
=
True
,
user
:
str
|
None
=
None
)
\
stop
:
List
[
str
]
|
None
=
None
,
stream
:
bool
=
True
,
user
:
str
|
None
=
None
)
\
->
LLMResult
|
Generator
:
->
LLMResult
|
Generator
:
if
tools
is
not
None
and
len
(
tools
)
>
0
:
if
tools
is
not
None
and
len
(
tools
)
>
0
:
raise
InvokeBadRequestError
(
f
"Baichuan model doesn't support tools"
)
raise
InvokeBadRequestError
(
"Baichuan model doesn't support tools"
)
instance
=
BaichuanModel
(
instance
=
BaichuanModel
(
api_key
=
credentials
[
'api_key'
],
api_key
=
credentials
[
'api_key'
],
...
...
api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py
View file @
14a19a3d
...
@@ -146,16 +146,16 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
...
@@ -146,16 +146,16 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
try
:
try
:
json_result
=
response
.
json
()
json_result
=
response
.
json
()
except
json
.
JSONDecodeError
as
e
:
except
json
.
JSONDecodeError
as
e
:
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: JSON decode error'
)
raise
CredentialsValidateFailedError
(
'Credentials validation failed: JSON decode error'
)
if
(
completion_type
is
LLMMode
.
CHAT
if
(
completion_type
is
LLMMode
.
CHAT
and
(
'object'
not
in
json_result
or
json_result
[
'object'
]
!=
'chat.completion'
)):
and
(
'object'
not
in
json_result
or
json_result
[
'object'
]
!=
'chat.completion'
)):
raise
CredentialsValidateFailedError
(
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: invalid response object, must be
\'
chat.completion
\'
'
)
'Credentials validation failed: invalid response object, must be
\'
chat.completion
\'
'
)
elif
(
completion_type
is
LLMMode
.
COMPLETION
elif
(
completion_type
is
LLMMode
.
COMPLETION
and
(
'object'
not
in
json_result
or
json_result
[
'object'
]
!=
'text_completion'
)):
and
(
'object'
not
in
json_result
or
json_result
[
'object'
]
!=
'text_completion'
)):
raise
CredentialsValidateFailedError
(
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: invalid response object, must be
\'
text_completion
\'
'
)
'Credentials validation failed: invalid response object, must be
\'
text_completion
\'
'
)
except
CredentialsValidateFailedError
:
except
CredentialsValidateFailedError
:
raise
raise
except
Exception
as
ex
:
except
Exception
as
ex
:
...
...
api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py
View file @
14a19a3d
...
@@ -179,11 +179,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
...
@@ -179,11 +179,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
try
:
try
:
json_result
=
response
.
json
()
json_result
=
response
.
json
()
except
json
.
JSONDecodeError
as
e
:
except
json
.
JSONDecodeError
as
e
:
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: JSON decode error'
)
raise
CredentialsValidateFailedError
(
'Credentials validation failed: JSON decode error'
)
if
'model'
not
in
json_result
:
if
'model'
not
in
json_result
:
raise
CredentialsValidateFailedError
(
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: invalid response'
)
'Credentials validation failed: invalid response'
)
except
CredentialsValidateFailedError
:
except
CredentialsValidateFailedError
:
raise
raise
except
Exception
as
ex
:
except
Exception
as
ex
:
...
...
api/core/model_runtime/model_providers/wenxin/llm/ernie_bot.py
View file @
14a19a3d
...
@@ -231,15 +231,15 @@ class ErnieBotModel(object):
...
@@ -231,15 +231,15 @@ class ErnieBotModel(object):
# so, we just disable function calling for now.
# so, we just disable function calling for now.
if
tools
is
not
None
and
len
(
tools
)
>
0
:
if
tools
is
not
None
and
len
(
tools
)
>
0
:
raise
BadRequestError
(
f
'function calling is not supported yet.'
)
raise
BadRequestError
(
'function calling is not supported yet.'
)
if
stop
is
not
None
:
if
stop
is
not
None
:
if
len
(
stop
)
>
4
:
if
len
(
stop
)
>
4
:
raise
BadRequestError
(
f
'stop list should not exceed 4 items.'
)
raise
BadRequestError
(
'stop list should not exceed 4 items.'
)
for
s
in
stop
:
for
s
in
stop
:
if
len
(
s
)
>
20
:
if
len
(
s
)
>
20
:
raise
BadRequestError
(
f
'stop item should not exceed 20 characters.'
)
raise
BadRequestError
(
'stop item should not exceed 20 characters.'
)
def
_build_request_body
(
self
,
model
:
str
,
messages
:
List
[
ErnieMessage
],
stream
:
bool
,
parameters
:
Dict
[
str
,
Any
],
def
_build_request_body
(
self
,
model
:
str
,
messages
:
List
[
ErnieMessage
],
stream
:
bool
,
parameters
:
Dict
[
str
,
Any
],
tools
:
List
[
PromptMessageTool
],
stop
:
List
[
str
],
user
:
str
)
->
Dict
[
str
,
Any
]:
tools
:
List
[
PromptMessageTool
],
stop
:
List
[
str
],
user
:
str
)
->
Dict
[
str
,
Any
]:
...
@@ -252,9 +252,9 @@ class ErnieBotModel(object):
...
@@ -252,9 +252,9 @@ class ErnieBotModel(object):
stop
:
List
[
str
],
user
:
str
)
\
stop
:
List
[
str
],
user
:
str
)
\
->
Dict
[
str
,
Any
]:
->
Dict
[
str
,
Any
]:
if
len
(
messages
)
%
2
==
0
:
if
len
(
messages
)
%
2
==
0
:
raise
BadRequestError
(
f
'The number of messages should be odd.'
)
raise
BadRequestError
(
'The number of messages should be odd.'
)
if
messages
[
0
]
.
role
==
'function'
:
if
messages
[
0
]
.
role
==
'function'
:
raise
BadRequestError
(
f
'The first message should be user message.'
)
raise
BadRequestError
(
'The first message should be user message.'
)
"""
"""
TODO: implement function calling
TODO: implement function calling
...
@@ -264,7 +264,7 @@ class ErnieBotModel(object):
...
@@ -264,7 +264,7 @@ class ErnieBotModel(object):
parameters
:
Dict
[
str
,
Any
],
stop
:
List
[
str
],
user
:
str
)
\
parameters
:
Dict
[
str
,
Any
],
stop
:
List
[
str
],
user
:
str
)
\
->
Dict
[
str
,
Any
]:
->
Dict
[
str
,
Any
]:
if
len
(
messages
)
==
0
:
if
len
(
messages
)
==
0
:
raise
BadRequestError
(
f
'The number of messages should not be zero.'
)
raise
BadRequestError
(
'The number of messages should not be zero.'
)
# check if the first element is system, shift it
# check if the first element is system, shift it
system_message
=
''
system_message
=
''
...
@@ -273,9 +273,9 @@ class ErnieBotModel(object):
...
@@ -273,9 +273,9 @@ class ErnieBotModel(object):
system_message
=
message
.
content
system_message
=
message
.
content
if
len
(
messages
)
%
2
==
0
:
if
len
(
messages
)
%
2
==
0
:
raise
BadRequestError
(
f
'The number of messages should be odd.'
)
raise
BadRequestError
(
'The number of messages should be odd.'
)
if
messages
[
0
]
.
role
!=
'user'
:
if
messages
[
0
]
.
role
!=
'user'
:
raise
BadRequestError
(
f
'The first message should be user message.'
)
raise
BadRequestError
(
'The first message should be user message.'
)
body
=
{
body
=
{
'messages'
:
[
message
.
to_dict
()
for
message
in
messages
],
'messages'
:
[
message
.
to_dict
()
for
message
in
messages
],
'stream'
:
stream
,
'stream'
:
stream
,
...
...
api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/_client.py
View file @
14a19a3d
...
@@ -37,7 +37,7 @@ class ZhipuAI(HttpClient):
...
@@ -37,7 +37,7 @@ class ZhipuAI(HttpClient):
if
base_url
is
None
:
if
base_url
is
None
:
base_url
=
os
.
environ
.
get
(
"ZHIPUAI_BASE_URL"
)
base_url
=
os
.
environ
.
get
(
"ZHIPUAI_BASE_URL"
)
if
base_url
is
None
:
if
base_url
is
None
:
base_url
=
f
"https://open.bigmodel.cn/api/paas/v4"
base_url
=
"https://open.bigmodel.cn/api/paas/v4"
from
.__version__
import
__version__
from
.__version__
import
__version__
super
()
.
__init__
(
super
()
.
__init__
(
version
=
__version__
,
version
=
__version__
,
...
...
api/core/prompt/output_parser/rule_config_generator.py
View file @
14a19a3d
...
@@ -19,11 +19,11 @@ class RuleConfigGeneratorOutputParser(BaseOutputParser):
...
@@ -19,11 +19,11 @@ class RuleConfigGeneratorOutputParser(BaseOutputParser):
raise
ValueError
(
"Expected 'prompt' to be a string."
)
raise
ValueError
(
"Expected 'prompt' to be a string."
)
if
not
isinstance
(
parsed
[
"variables"
],
list
):
if
not
isinstance
(
parsed
[
"variables"
],
list
):
raise
ValueError
(
raise
ValueError
(
f
"Expected 'variables' to be a list."
"Expected 'variables' to be a list."
)
)
if
not
isinstance
(
parsed
[
"opening_statement"
],
str
):
if
not
isinstance
(
parsed
[
"opening_statement"
],
str
):
raise
ValueError
(
raise
ValueError
(
f
"Expected 'opening_statement' to be a str."
"Expected 'opening_statement' to be a str."
)
)
return
parsed
return
parsed
except
Exception
as
e
:
except
Exception
as
e
:
...
...
api/core/tools/model/tool_model_manager.py
View file @
14a19a3d
...
@@ -39,13 +39,13 @@ class ToolModelManager:
...
@@ -39,13 +39,13 @@ class ToolModelManager:
)
)
if
not
model_instance
:
if
not
model_instance
:
raise
InvokeModelError
(
f
'Model not found'
)
raise
InvokeModelError
(
'Model not found'
)
llm_model
=
cast
(
LargeLanguageModel
,
model_instance
.
model_type_instance
)
llm_model
=
cast
(
LargeLanguageModel
,
model_instance
.
model_type_instance
)
schema
=
llm_model
.
get_model_schema
(
model_instance
.
model
,
model_instance
.
credentials
)
schema
=
llm_model
.
get_model_schema
(
model_instance
.
model
,
model_instance
.
credentials
)
if
not
schema
:
if
not
schema
:
raise
InvokeModelError
(
f
'No model schema found'
)
raise
InvokeModelError
(
'No model schema found'
)
max_tokens
=
schema
.
model_properties
.
get
(
ModelPropertyKey
.
CONTEXT_SIZE
,
None
)
max_tokens
=
schema
.
model_properties
.
get
(
ModelPropertyKey
.
CONTEXT_SIZE
,
None
)
if
max_tokens
is
None
:
if
max_tokens
is
None
:
...
@@ -69,7 +69,7 @@ class ToolModelManager:
...
@@ -69,7 +69,7 @@ class ToolModelManager:
)
)
if
not
model_instance
:
if
not
model_instance
:
raise
InvokeModelError
(
f
'Model not found'
)
raise
InvokeModelError
(
'Model not found'
)
llm_model
=
cast
(
LargeLanguageModel
,
model_instance
.
model_type_instance
)
llm_model
=
cast
(
LargeLanguageModel
,
model_instance
.
model_type_instance
)
...
@@ -156,7 +156,7 @@ class ToolModelManager:
...
@@ -156,7 +156,7 @@ class ToolModelManager:
except
InvokeConnectionError
as
e
:
except
InvokeConnectionError
as
e
:
raise
InvokeModelError
(
f
'Invoke connection error: {e}'
)
raise
InvokeModelError
(
f
'Invoke connection error: {e}'
)
except
InvokeAuthorizationError
as
e
:
except
InvokeAuthorizationError
as
e
:
raise
InvokeModelError
(
f
'Invoke authorization error'
)
raise
InvokeModelError
(
'Invoke authorization error'
)
except
InvokeServerUnavailableError
as
e
:
except
InvokeServerUnavailableError
as
e
:
raise
InvokeModelError
(
f
'Invoke server unavailable error: {e}'
)
raise
InvokeModelError
(
f
'Invoke server unavailable error: {e}'
)
except
Exception
as
e
:
except
Exception
as
e
:
...
...
api/core/tools/provider/builtin/yahoo/tools/analytics.py
View file @
14a19a3d
...
@@ -66,5 +66,5 @@ class YahooFinanceAnalyticsTool(BuiltinTool):
...
@@ -66,5 +66,5 @@ class YahooFinanceAnalyticsTool(BuiltinTool):
try
:
try
:
return
self
.
create_text_message
(
str
(
summary_df
.
to_dict
()))
return
self
.
create_text_message
(
str
(
summary_df
.
to_dict
()))
except
(
HTTPError
,
ReadTimeout
):
except
(
HTTPError
,
ReadTimeout
):
return
self
.
create_text_message
(
f
'There is a internet connection problem. Please try again later.'
)
return
self
.
create_text_message
(
'There is a internet connection problem. Please try again later.'
)
\ No newline at end of file
api/core/tools/provider/builtin/yahoo/tools/news.py
View file @
14a19a3d
...
@@ -21,7 +21,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
...
@@ -21,7 +21,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
try
:
try
:
return
self
.
run
(
ticker
=
query
,
user_id
=
user_id
)
return
self
.
run
(
ticker
=
query
,
user_id
=
user_id
)
except
(
HTTPError
,
ReadTimeout
):
except
(
HTTPError
,
ReadTimeout
):
return
self
.
create_text_message
(
f
'There is a internet connection problem. Please try again later.'
)
return
self
.
create_text_message
(
'There is a internet connection problem. Please try again later.'
)
def
run
(
self
,
ticker
:
str
,
user_id
:
str
)
->
ToolInvokeMessage
:
def
run
(
self
,
ticker
:
str
,
user_id
:
str
)
->
ToolInvokeMessage
:
company
=
yfinance
.
Ticker
(
ticker
)
company
=
yfinance
.
Ticker
(
ticker
)
...
...
api/core/tools/provider/builtin/yahoo/tools/ticker.py
View file @
14a19a3d
...
@@ -20,7 +20,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
...
@@ -20,7 +20,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
try
:
try
:
return
self
.
create_text_message
(
self
.
run
(
ticker
=
query
))
return
self
.
create_text_message
(
self
.
run
(
ticker
=
query
))
except
(
HTTPError
,
ReadTimeout
):
except
(
HTTPError
,
ReadTimeout
):
return
self
.
create_text_message
(
f
'There is a internet connection problem. Please try again later.'
)
return
self
.
create_text_message
(
'There is a internet connection problem. Please try again later.'
)
def
run
(
self
,
ticker
:
str
)
->
str
:
def
run
(
self
,
ticker
:
str
)
->
str
:
return
str
(
Ticker
(
ticker
)
.
info
)
return
str
(
Ticker
(
ticker
)
.
info
)
\ No newline at end of file
api/core/tools/tool/tool.py
View file @
14a19a3d
...
@@ -221,7 +221,7 @@ class Tool(BaseModel, ABC):
...
@@ -221,7 +221,7 @@ class Tool(BaseModel, ABC):
result
+=
f
"result link: {response.message}. please tell user to check it."
result
+=
f
"result link: {response.message}. please tell user to check it."
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE_LINK
or
\
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE_LINK
or
\
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE
:
response
.
type
==
ToolInvokeMessage
.
MessageType
.
IMAGE
:
result
+=
f
"image has been created and sent to user already, you should tell user to check it now."
result
+=
"image has been created and sent to user already, you should tell user to check it now."
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
BLOB
:
elif
response
.
type
==
ToolInvokeMessage
.
MessageType
.
BLOB
:
if
len
(
response
.
message
)
>
114
:
if
len
(
response
.
message
)
>
114
:
result
+=
str
(
response
.
message
[:
114
])
+
'...'
result
+=
str
(
response
.
message
[:
114
])
+
'...'
...
...
api/libs/helper.py
View file @
14a19a3d
...
@@ -101,7 +101,7 @@ class datetime_string(object):
...
@@ -101,7 +101,7 @@ class datetime_string(object):
datetime
.
strptime
(
value
,
self
.
format
)
datetime
.
strptime
(
value
,
self
.
format
)
except
ValueError
:
except
ValueError
:
error
=
(
'Invalid {arg}: {val}. {arg} must be conform to the format {format}'
error
=
(
'Invalid {arg}: {val}. {arg} must be conform to the format {format}'
.
format
(
arg
=
self
.
argument
,
val
=
value
,
lo
=
self
.
format
))
.
format
(
arg
=
self
.
argument
,
val
=
value
,
format
=
self
.
format
))
raise
ValueError
(
error
)
raise
ValueError
(
error
)
return
value
return
value
...
...
api/pyproject.toml
View file @
14a19a3d
...
@@ -11,8 +11,13 @@ line-length = 120
...
@@ -11,8 +11,13 @@ line-length = 120
[tool.ruff.lint]
[tool.ruff.lint]
ignore-init-module-imports
=
true
ignore-init-module-imports
=
true
select
=
[
select
=
[
"F
401"
,
# unused-import
"F
"
,
# pyflakes rules
"I001"
,
# unsorted-imports
"I001"
,
# unsorted-imports
"I002"
,
# missing-required-import
"I002"
,
# missing-required-import
"F811"
,
# redefined-while-unused
]
ignore
=
[
"F403"
,
# undefined-local-with-import-star
"F405"
,
# undefined-local-with-import-star-usage
"F821"
,
# undefined-name
"F841"
,
# unused-variable
]
]
api/services/dataset_service.py
View file @
14a19a3d
...
@@ -139,8 +139,8 @@ class DatasetService:
...
@@ -139,8 +139,8 @@ class DatasetService:
)
)
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ValueError
(
raise
ValueError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ValueError
(
f
"The dataset in unavailable, due to: "
raise
ValueError
(
f
"The dataset in unavailable, due to: "
f
"{ex.description}"
)
f
"{ex.description}"
)
...
@@ -176,8 +176,8 @@ class DatasetService:
...
@@ -176,8 +176,8 @@ class DatasetService:
filtered_data
[
'collection_binding_id'
]
=
dataset_collection_binding
.
id
filtered_data
[
'collection_binding_id'
]
=
dataset_collection_binding
.
id
except
LLMBadRequestError
:
except
LLMBadRequestError
:
raise
ValueError
(
raise
ValueError
(
f
"No Embedding Model available. Please configure a valid provider "
"No Embedding Model available. Please configure a valid provider "
f
"in the Settings -> Model Provider."
)
"in the Settings -> Model Provider."
)
except
ProviderTokenNotInitError
as
ex
:
except
ProviderTokenNotInitError
as
ex
:
raise
ValueError
(
ex
.
description
)
raise
ValueError
(
ex
.
description
)
...
...
api/services/tools_manage_service.py
View file @
14a19a3d
...
@@ -50,7 +50,7 @@ class ToolManageService:
...
@@ -50,7 +50,7 @@ class ToolManageService:
:param provider: the provider dict
:param provider: the provider dict
"""
"""
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
url_prefix
=
(
current_app
.
config
.
get
(
"CONSOLE_API_URL"
)
+
f
"/console/api/workspaces/current/tool-provider/builtin/"
)
+
"/console/api/workspaces/current/tool-provider/builtin/"
)
if
'icon'
in
provider
:
if
'icon'
in
provider
:
if
provider
[
'type'
]
==
UserToolProvider
.
ProviderType
.
BUILTIN
.
value
:
if
provider
[
'type'
]
==
UserToolProvider
.
ProviderType
.
BUILTIN
.
value
:
...
@@ -211,7 +211,7 @@ class ToolManageService:
...
@@ -211,7 +211,7 @@ class ToolManageService:
tool_bundles
,
schema_type
=
ToolManageService
.
convert_schema_to_tool_bundles
(
schema
,
extra_info
)
tool_bundles
,
schema_type
=
ToolManageService
.
convert_schema_to_tool_bundles
(
schema
,
extra_info
)
if
len
(
tool_bundles
)
>
10
:
if
len
(
tool_bundles
)
>
10
:
raise
ValueError
(
f
'the number of apis should be less than 10'
)
raise
ValueError
(
'the number of apis should be less than 10'
)
# create db provider
# create db provider
db_provider
=
ApiToolProvider
(
db_provider
=
ApiToolProvider
(
...
@@ -269,7 +269,7 @@ class ToolManageService:
...
@@ -269,7 +269,7 @@ class ToolManageService:
# try to parse schema, avoid SSRF attack
# try to parse schema, avoid SSRF attack
ToolManageService
.
parser_api_schema
(
schema
)
ToolManageService
.
parser_api_schema
(
schema
)
except
Exception
as
e
:
except
Exception
as
e
:
raise
ValueError
(
f
'invalid schema, please check the url you provided'
)
raise
ValueError
(
'invalid schema, please check the url you provided'
)
return
{
return
{
'schema'
:
schema
'schema'
:
schema
...
@@ -490,7 +490,7 @@ class ToolManageService:
...
@@ -490,7 +490,7 @@ class ToolManageService:
try
:
try
:
tool_bundles
,
_
=
ApiBasedToolSchemaParser
.
auto_parse_to_tool_bundle
(
schema
)
tool_bundles
,
_
=
ApiBasedToolSchemaParser
.
auto_parse_to_tool_bundle
(
schema
)
except
Exception
as
e
:
except
Exception
as
e
:
raise
ValueError
(
f
'invalid schema'
)
raise
ValueError
(
'invalid schema'
)
# get tool bundle
# get tool bundle
tool_bundle
=
next
(
filter
(
lambda
tb
:
tb
.
operation_id
==
tool_name
,
tool_bundles
),
None
)
tool_bundle
=
next
(
filter
(
lambda
tb
:
tb
.
operation_id
==
tool_name
,
tool_bundles
),
None
)
...
...
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