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
aa13b8db
Commit
aa13b8db
authored
Jul 17, 2023
by
John Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: agent parse error
parent
afd8996b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
agent_loop_gather_callback_handler.py
...re/callback_handler/agent_loop_gather_callback_handler.py
+11
-6
orchestrator_rule_parser.py
api/core/orchestrator_rule_parser.py
+1
-2
app_model_config_service.py
api/services/app_model_config_service.py
+1
-1
No files found.
api/core/callback_handler/agent_loop_gather_callback_handler.py
View file @
aa13b8db
...
...
@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Union, Optional
from
langchain.agents
import
openai_functions_agent
,
openai_functions_multi_agent
from
langchain.callbacks.base
import
BaseCallbackHandler
from
langchain.schema
import
AgentAction
,
AgentFinish
,
LLMResult
from
langchain.schema
import
AgentAction
,
AgentFinish
,
LLMResult
,
ChatGeneration
from
core.callback_handler.entity.agent_loop
import
AgentLoop
from
core.conversation_message_task
import
ConversationMessageTask
...
...
@@ -66,12 +66,17 @@ class AgentLoopGatherCallbackHandler(BaseCallbackHandler):
if
self
.
_current_loop
and
self
.
_current_loop
.
status
==
'llm_started'
:
self
.
_current_loop
.
status
=
'llm_end'
self
.
_current_loop
.
prompt_tokens
=
response
.
llm_output
[
'token_usage'
][
'prompt_tokens'
]
completion_message
=
response
.
generations
[
0
][
0
]
.
message
if
'function_call'
in
completion_message
.
additional_kwargs
:
self
.
_current_loop
.
completion
\
=
json
.
dumps
({
'function_call'
:
completion_message
.
additional_kwargs
[
'function_call'
]})
completion_generation
=
response
.
generations
[
0
][
0
]
if
isinstance
(
completion_generation
,
ChatGeneration
):
completion_message
=
completion_generation
.
message
if
'function_call'
in
completion_message
.
additional_kwargs
:
self
.
_current_loop
.
completion
\
=
json
.
dumps
({
'function_call'
:
completion_message
.
additional_kwargs
[
'function_call'
]})
else
:
self
.
_current_loop
.
completion
=
response
.
generations
[
0
][
0
]
.
text
else
:
self
.
_current_loop
.
completion
=
response
.
generations
[
0
][
0
]
.
text
self
.
_current_loop
.
completion
=
completion_generation
.
text
self
.
_current_loop
.
completion_tokens
=
response
.
llm_output
[
'token_usage'
][
'completion_tokens'
]
def
on_llm_error
(
...
...
api/core/orchestrator_rule_parser.py
View file @
aa13b8db
...
...
@@ -30,7 +30,6 @@ class OrchestratorRuleParser:
def
__init__
(
self
,
tenant_id
:
str
,
app_model_config
:
AppModelConfig
):
self
.
tenant_id
=
tenant_id
self
.
app_model_config
=
app_model_config
self
.
agent_summary_model_name
=
"gpt-3.5-turbo-16k"
def
to_agent_executor
(
self
,
conversation_message_task
:
ConversationMessageTask
,
memory
:
Optional
[
BaseChatMemory
],
rest_tokens
:
int
,
chain_callback
:
MainChainGatherCallbackHandler
)
\
...
...
@@ -71,7 +70,7 @@ class OrchestratorRuleParser:
summary_llm
=
LLMBuilder
.
to_llm
(
tenant_id
=
self
.
tenant_id
,
model_name
=
self
.
agent_summary
_model_name
,
model_name
=
agent
_model_name
,
temperature
=
0
,
max_tokens
=
500
,
callbacks
=
[
DifyStdOutCallbackHandler
()]
...
...
api/services/app_model_config_service.py
View file @
aa13b8db
...
...
@@ -316,7 +316,7 @@ class AppModelConfigService:
if
"strategy"
not
in
config
[
"agent_mode"
]
or
not
config
[
"agent_mode"
][
"strategy"
]:
config
[
"agent_mode"
][
"strategy"
]
=
PlanningStrategy
.
ROUTER
.
value
if
config
[
"agent_mode"
][
"strategy"
]
not
in
PlanningStrategy
.
__members__
:
if
config
[
"agent_mode"
][
"strategy"
]
not
in
[
member
.
value
for
member
in
list
(
PlanningStrategy
.
__members__
.
values
())]
:
raise
ValueError
(
"strategy in agent_mode must be in the specified strategy list"
)
if
"tools"
not
in
config
[
"agent_mode"
]
or
not
config
[
"agent_mode"
][
"tools"
]:
...
...
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