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
6d24a2cb
Unverified
Commit
6d24a2cb
authored
Jan 30, 2024
by
Yeuoly
Committed by
GitHub
Jan 30, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: api tool encoding (#2296)
parent
0a4dfaea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
api_tool.py
api/core/tools/tool/api_tool.py
+21
-2
parser.py
api/core/tools/utils/parser.py
+4
-0
tools_manage_service.py
api/services/tools_manage_service.py
+4
-4
No files found.
api/core/tools/tool/api_tool.py
View file @
6d24a2cb
...
...
@@ -8,6 +8,7 @@ from core.tools.errors import ToolProviderCredentialValidationError
import
httpx
import
requests
import
json
class
ApiTool
(
Tool
):
api_bundle
:
ApiBasedToolBundle
...
...
@@ -79,10 +80,28 @@ class ApiTool(Tool):
if
isinstance
(
response
,
httpx
.
Response
):
if
response
.
status_code
>=
400
:
raise
ToolProviderCredentialValidationError
(
f
"Request failed with status code {response.status_code}"
)
if
not
response
.
content
:
return
'Empty response from the tool, please check your parameters and try again.'
try
:
response
=
response
.
json
()
try
:
return
json
.
dumps
(
response
,
ensure_ascii
=
False
)
except
Exception
as
e
:
return
json
.
dumps
(
response
)
except
Exception
as
e
:
return
response
.
text
elif
isinstance
(
response
,
requests
.
Response
):
if
not
response
.
ok
:
raise
ToolProviderCredentialValidationError
(
f
"Request failed with status code {response.status_code}"
)
if
not
response
.
content
:
return
'Empty response from the tool, please check your parameters and try again.'
try
:
response
=
response
.
json
()
try
:
return
json
.
dumps
(
response
,
ensure_ascii
=
False
)
except
Exception
as
e
:
return
json
.
dumps
(
response
)
except
Exception
as
e
:
return
response
.
text
else
:
raise
ValueError
(
f
'Invalid response type {type(response)}'
)
...
...
api/core/tools/utils/parser.py
View file @
6d24a2cb
...
...
@@ -114,6 +114,10 @@ class ApiBasedToolSchemaParser:
if
count
>
1
:
warning
[
'duplicated_parameter'
]
=
f
'Parameter {name} is duplicated.'
# check if there is a operation id, use $path_$method as operation id if not
if
'operationId'
not
in
interface
[
'operation'
]:
interface
[
'operation'
][
'operationId'
]
=
f
'{interface["path"]}_{interface["method"]}'
bundles
.
append
(
ApiBasedToolBundle
(
server_url
=
server_url
+
interface
[
'path'
],
method
=
interface
[
'method'
],
...
...
api/services/tools_manage_service.py
View file @
6d24a2cb
...
...
@@ -485,10 +485,10 @@ class ToolManageService:
if
schema_type
not
in
[
member
.
value
for
member
in
ApiProviderSchemaType
]:
raise
ValueError
(
f
'invalid schema type {schema_type}'
)
if
schema_type
==
ApiProviderSchemaType
.
OPENAPI
.
value
:
tool_bundles
=
ApiBasedToolSchemaParser
.
parse_openapi_yaml
_to_tool_bundle
(
schema
)
e
ls
e
:
raise
ValueError
(
f
'invalid schema
type {schema_type}
'
)
try
:
tool_bundles
,
_
=
ApiBasedToolSchemaParser
.
auto_parse
_to_tool_bundle
(
schema
)
e
xcept
Exception
as
e
:
raise
ValueError
(
f
'invalid schema'
)
# get tool bundle
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