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
2dfb3e95
Unverified
Commit
2dfb3e95
authored
Aug 16, 2023
by
takatost
Committed by
GitHub
Aug 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: optimize error record in agent (#869)
parent
f207e180
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
14 deletions
+35
-14
multi_dataset_router_agent.py
api/core/agent/agent/multi_dataset_router_agent.py
+5
-1
openai_function_call.py
api/core/agent/agent/openai_function_call.py
+7
-3
openai_multi_function_call.py
api/core/agent/agent/openai_multi_function_call.py
+7
-3
structed_multi_dataset_router_agent.py
api/core/agent/agent/structed_multi_dataset_router_agent.py
+6
-1
structured_chat.py
api/core/agent/agent/structured_chat.py
+6
-2
agent_loop_gather_callback_handler.py
...re/callback_handler/agent_loop_gather_callback_handler.py
+2
-2
dataset_tool_callback_handler.py
api/core/callback_handler/dataset_tool_callback_handler.py
+1
-1
main_chain_gather_callback_handler.py
...re/callback_handler/main_chain_gather_callback_handler.py
+1
-1
No files found.
api/core/agent/agent/multi_dataset_router_agent.py
View file @
2dfb3e95
...
...
@@ -59,7 +59,11 @@ class MultiDatasetRouterAgent(OpenAIFunctionsAgent):
_
,
observation
=
intermediate_steps
[
-
1
]
return
AgentFinish
(
return_values
=
{
"output"
:
observation
},
log
=
observation
)
return
super
()
.
plan
(
intermediate_steps
,
callbacks
,
**
kwargs
)
try
:
return
super
()
.
plan
(
intermediate_steps
,
callbacks
,
**
kwargs
)
except
Exception
as
e
:
new_exception
=
self
.
model_instance
.
handle_exceptions
(
e
)
raise
new_exception
async
def
aplan
(
self
,
...
...
api/core/agent/agent/openai_function_call.py
View file @
2dfb3e95
...
...
@@ -50,9 +50,13 @@ class AutoSummarizingOpenAIFunctionCallAgent(OpenAIFunctionsAgent, OpenAIFunctio
prompt
=
self
.
prompt
.
format_prompt
(
input
=
query
,
agent_scratchpad
=
[])
messages
=
prompt
.
to_messages
()
predicted_message
=
self
.
llm
.
predict_messages
(
messages
,
functions
=
self
.
functions
,
callbacks
=
None
)
try
:
predicted_message
=
self
.
llm
.
predict_messages
(
messages
,
functions
=
self
.
functions
,
callbacks
=
None
)
except
Exception
as
e
:
new_exception
=
self
.
model_instance
.
handle_exceptions
(
e
)
raise
new_exception
function_call
=
predicted_message
.
additional_kwargs
.
get
(
"function_call"
,
{})
...
...
api/core/agent/agent/openai_multi_function_call.py
View file @
2dfb3e95
...
...
@@ -50,9 +50,13 @@ class AutoSummarizingOpenMultiAIFunctionCallAgent(OpenAIMultiFunctionsAgent, Ope
prompt
=
self
.
prompt
.
format_prompt
(
input
=
query
,
agent_scratchpad
=
[])
messages
=
prompt
.
to_messages
()
predicted_message
=
self
.
llm
.
predict_messages
(
messages
,
functions
=
self
.
functions
,
callbacks
=
None
)
try
:
predicted_message
=
self
.
llm
.
predict_messages
(
messages
,
functions
=
self
.
functions
,
callbacks
=
None
)
except
Exception
as
e
:
new_exception
=
self
.
model_instance
.
handle_exceptions
(
e
)
raise
new_exception
function_call
=
predicted_message
.
additional_kwargs
.
get
(
"function_call"
,
{})
...
...
api/core/agent/agent/structed_multi_dataset_router_agent.py
View file @
2dfb3e95
...
...
@@ -94,7 +94,12 @@ class StructuredMultiDatasetRouterAgent(StructuredChatAgent):
return
AgentFinish
(
return_values
=
{
"output"
:
rst
},
log
=
rst
)
full_inputs
=
self
.
get_full_inputs
(
intermediate_steps
,
**
kwargs
)
full_output
=
self
.
llm_chain
.
predict
(
callbacks
=
callbacks
,
**
full_inputs
)
try
:
full_output
=
self
.
llm_chain
.
predict
(
callbacks
=
callbacks
,
**
full_inputs
)
except
Exception
as
e
:
new_exception
=
self
.
model_instance
.
handle_exceptions
(
e
)
raise
new_exception
try
:
return
self
.
output_parser
.
parse
(
full_output
)
...
...
api/core/agent/agent/structured_chat.py
View file @
2dfb3e95
...
...
@@ -89,8 +89,8 @@ class AutoSummarizingStructuredChatAgent(StructuredChatAgent, CalcTokenMixin):
Action specifying what tool to use.
"""
full_inputs
=
self
.
get_full_inputs
(
intermediate_steps
,
**
kwargs
)
prompts
,
_
=
self
.
llm_chain
.
prep_prompts
(
input_list
=
[
self
.
llm_chain
.
prep_inputs
(
full_inputs
)])
messages
=
[]
if
prompts
:
messages
=
prompts
[
0
]
.
to_messages
()
...
...
@@ -99,7 +99,11 @@ class AutoSummarizingStructuredChatAgent(StructuredChatAgent, CalcTokenMixin):
if
rest_tokens
<
0
:
full_inputs
=
self
.
summarize_messages
(
intermediate_steps
,
**
kwargs
)
full_output
=
self
.
llm_chain
.
predict
(
callbacks
=
callbacks
,
**
full_inputs
)
try
:
full_output
=
self
.
llm_chain
.
predict
(
callbacks
=
callbacks
,
**
full_inputs
)
except
Exception
as
e
:
new_exception
=
self
.
model_instance
.
handle_exceptions
(
e
)
raise
new_exception
try
:
return
self
.
output_parser
.
parse
(
full_output
)
...
...
api/core/callback_handler/agent_loop_gather_callback_handler.py
View file @
2dfb3e95
...
...
@@ -85,7 +85,7 @@ class AgentLoopGatherCallbackHandler(BaseCallbackHandler):
def
on_llm_error
(
self
,
error
:
Union
[
Exception
,
KeyboardInterrupt
],
**
kwargs
:
Any
)
->
None
:
logging
.
exception
(
error
)
logging
.
debug
(
"Agent on_llm_error:
%
s"
,
error
)
self
.
_agent_loops
=
[]
self
.
_current_loop
=
None
self
.
_message_agent_thought
=
None
...
...
@@ -164,7 +164,7 @@ class AgentLoopGatherCallbackHandler(BaseCallbackHandler):
self
,
error
:
Union
[
Exception
,
KeyboardInterrupt
],
**
kwargs
:
Any
)
->
None
:
"""Do nothing."""
logging
.
exception
(
error
)
logging
.
debug
(
"Agent on_tool_error:
%
s"
,
error
)
self
.
_agent_loops
=
[]
self
.
_current_loop
=
None
self
.
_message_agent_thought
=
None
...
...
api/core/callback_handler/dataset_tool_callback_handler.py
View file @
2dfb3e95
...
...
@@ -68,4 +68,4 @@ class DatasetToolCallbackHandler(BaseCallbackHandler):
self
,
error
:
Union
[
Exception
,
KeyboardInterrupt
],
**
kwargs
:
Any
)
->
None
:
"""Do nothing."""
logging
.
exception
(
error
)
logging
.
debug
(
"Dataset tool on_llm_error:
%
s"
,
error
)
api/core/callback_handler/main_chain_gather_callback_handler.py
View file @
2dfb3e95
...
...
@@ -72,5 +72,5 @@ class MainChainGatherCallbackHandler(BaseCallbackHandler):
def
on_chain_error
(
self
,
error
:
Union
[
Exception
,
KeyboardInterrupt
],
**
kwargs
:
Any
)
->
None
:
logging
.
exception
(
error
)
logging
.
debug
(
"Dataset tool on_chain_error:
%
s"
,
error
)
self
.
clear_chain_results
()
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