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
af2138e8
Unverified
Commit
af2138e8
authored
May 29, 2023
by
John Wang
Committed by
GitHub
May 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: json parse in router chain output (#243)
parent
091beffa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
llm_router_chain.py
api/core/chain/llm_router_chain.py
+8
-5
multi_dataset_router_chain.py
api/core/chain/multi_dataset_router_chain.py
+1
-1
No files found.
api/core/chain/llm_router_chain.py
View file @
af2138e8
...
@@ -84,13 +84,16 @@ class RouterOutputParser(BaseOutputParser[Dict[str, str]]):
...
@@ -84,13 +84,16 @@ class RouterOutputParser(BaseOutputParser[Dict[str, str]]):
def
parse_json_markdown
(
self
,
json_string
:
str
)
->
dict
:
def
parse_json_markdown
(
self
,
json_string
:
str
)
->
dict
:
# Remove the triple backticks if present
# Remove the triple backticks if present
json_string
=
json_string
.
replace
(
"```json"
,
""
)
.
replace
(
"```"
,
""
)
start_index
=
json_string
.
find
(
"```json"
)
end_index
=
json_string
.
find
(
"```"
,
start_index
+
len
(
"```json"
))
# Strip whitespace and newlines from the start and end
if
start_index
!=
-
1
and
end_index
!=
-
1
:
json_string
=
json_string
.
strip
()
extracted_content
=
json_string
[
start_index
+
len
(
"```json"
):
end_index
]
.
strip
()
# Parse the JSON string into a Python dictionary
# Parse the JSON string into a Python dictionary
parsed
=
json
.
loads
(
json_string
)
parsed
=
json
.
loads
(
extracted_content
)
else
:
raise
Exception
(
"Could not find JSON block in the output."
)
return
parsed
return
parsed
...
...
api/core/chain/multi_dataset_router_chain.py
View file @
af2138e8
...
@@ -90,7 +90,7 @@ class MultiDatasetRouterChain(Chain):
...
@@ -90,7 +90,7 @@ class MultiDatasetRouterChain(Chain):
callback_manager
=
llm_callback_manager
callback_manager
=
llm_callback_manager
)
)
destinations
=
[
f
"{d.id}: {d.description}"
for
d
in
datasets
]
destinations
=
[
"{}: {}"
.
format
(
d
.
id
,
d
.
description
.
replace
(
'
\n
'
,
' '
))
for
d
in
datasets
]
destinations_str
=
"
\n
"
.
join
(
destinations
)
destinations_str
=
"
\n
"
.
join
(
destinations
)
router_template
=
MULTI_PROMPT_ROUTER_TEMPLATE
.
format
(
router_template
=
MULTI_PROMPT_ROUTER_TEMPLATE
.
format
(
destinations
=
destinations_str
destinations
=
destinations_str
...
...
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