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
48d5628f
Unverified
Commit
48d5628f
authored
Jan 24, 2024
by
Yeuoly
Committed by
GitHub
Jan 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: CoT runner (#2157)
parent
c8fb619d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
15 deletions
+18
-15
assistant_cot_runner.py
api/core/features/assistant_cot_runner.py
+12
-9
youtube.yaml
api/core/tools/provider/builtin/youtube/youtube.yaml
+6
-6
No files found.
api/core/features/assistant_cot_runner.py
View file @
48d5628f
...
@@ -19,8 +19,6 @@ from core.features.assistant_base_runner import BaseAssistantApplicationRunner
...
@@ -19,8 +19,6 @@ from core.features.assistant_base_runner import BaseAssistantApplicationRunner
from
models.model
import
Conversation
,
Message
from
models.model
import
Conversation
,
Message
logger
=
logging
.
getLogger
(
__name__
)
class
AssistantCotApplicationRunner
(
BaseAssistantApplicationRunner
):
class
AssistantCotApplicationRunner
(
BaseAssistantApplicationRunner
):
def
run
(
self
,
model_instance
:
ModelInstance
,
def
run
(
self
,
model_instance
:
ModelInstance
,
conversation
:
Conversation
,
conversation
:
Conversation
,
...
@@ -93,6 +91,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -93,6 +91,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
prompt_messages_tools
=
[]
prompt_messages_tools
=
[]
message_file_ids
=
[]
message_file_ids
=
[]
agent_thought
=
self
.
create_agent_thought
(
agent_thought
=
self
.
create_agent_thought
(
message_id
=
message
.
id
,
message_id
=
message
.
id
,
message
=
''
,
message
=
''
,
...
@@ -100,7 +99,9 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -100,7 +99,9 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
tool_input
=
''
,
tool_input
=
''
,
messages_ids
=
message_file_ids
messages_ids
=
message_file_ids
)
)
self
.
queue_manager
.
publish_agent_thought
(
agent_thought
,
PublishFrom
.
APPLICATION_MANAGER
)
if
iteration_step
>
1
:
self
.
queue_manager
.
publish_agent_thought
(
agent_thought
,
PublishFrom
.
APPLICATION_MANAGER
)
# update prompt messages
# update prompt messages
prompt_messages
=
self
.
_originze_cot_prompt_messages
(
prompt_messages
=
self
.
_originze_cot_prompt_messages
(
...
@@ -137,7 +138,11 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -137,7 +138,11 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
# get llm usage
# get llm usage
if
llm_result
.
usage
:
if
llm_result
.
usage
:
increse_usage
(
llm_usage
,
llm_result
.
usage
)
increse_usage
(
llm_usage
,
llm_result
.
usage
)
# publish agent thought if it's first iteration
if
iteration_step
==
1
:
self
.
queue_manager
.
publish_agent_thought
(
agent_thought
,
PublishFrom
.
APPLICATION_MANAGER
)
self
.
save_agent_thought
(
agent_thought
=
agent_thought
,
self
.
save_agent_thought
(
agent_thought
=
agent_thought
,
tool_name
=
scratchpad
.
action
.
action_name
if
scratchpad
.
action
else
''
,
tool_name
=
scratchpad
.
action
.
action_name
if
scratchpad
.
action
else
''
,
tool_input
=
scratchpad
.
action
.
action_input
if
scratchpad
.
action
else
''
,
tool_input
=
scratchpad
.
action
.
action_input
if
scratchpad
.
action
else
''
,
...
@@ -187,7 +192,6 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -187,7 +192,6 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
tool_call_args
=
scratchpad
.
action
.
action_input
tool_call_args
=
scratchpad
.
action
.
action_input
tool_instance
=
tool_instances
.
get
(
tool_call_name
)
tool_instance
=
tool_instances
.
get
(
tool_call_name
)
if
not
tool_instance
:
if
not
tool_instance
:
logger
.
error
(
f
"failed to find tool instance: {tool_call_name}"
)
answer
=
f
"there is not a tool named {tool_call_name}"
answer
=
f
"there is not a tool named {tool_call_name}"
self
.
save_agent_thought
(
agent_thought
=
agent_thought
,
self
.
save_agent_thought
(
agent_thought
=
agent_thought
,
tool_name
=
''
,
tool_name
=
''
,
...
@@ -237,7 +241,6 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -237,7 +241,6 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
if
error_response
:
if
error_response
:
observation
=
error_response
observation
=
error_response
logger
.
error
(
error_response
)
else
:
else
:
observation
=
self
.
_convert_tool_response_to_str
(
tool_response
)
observation
=
self
.
_convert_tool_response_to_str
(
tool_response
)
...
@@ -543,13 +546,13 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
...
@@ -543,13 +546,13 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
# add assistant message
# add assistant message
if
len
(
agent_scratchpad
)
>
0
:
if
len
(
agent_scratchpad
)
>
0
:
prompt_messages
.
append
(
AssistantPromptMessage
(
prompt_messages
.
append
(
AssistantPromptMessage
(
content
=
(
agent_scratchpad
[
-
1
]
.
thought
or
''
)
+
"
\n
"
+
(
agent_scratchpad
[
-
1
]
.
observation
or
''
)
content
=
(
agent_scratchpad
[
-
1
]
.
thought
or
''
)
))
))
# add user message
# add user message
if
len
(
agent_scratchpad
)
>
0
:
if
len
(
agent_scratchpad
)
>
0
:
prompt_messages
.
append
(
UserPromptMessage
(
prompt_messages
.
append
(
UserPromptMessage
(
content
=
input
,
content
=
(
agent_scratchpad
[
-
1
]
.
observation
or
''
)
,
))
))
return
prompt_messages
return
prompt_messages
...
...
api/core/tools/provider/builtin/youtube/youtube.yaml
View file @
48d5628f
...
@@ -2,13 +2,13 @@ identity:
...
@@ -2,13 +2,13 @@ identity:
author
:
Dify
author
:
Dify
name
:
youtube
name
:
youtube
label
:
label
:
en_US
:
You
t
ube
en_US
:
You
T
ube
zh_Hans
:
You
t
ube
zh_Hans
:
You
T
ube
pt_BR
:
You
t
ube
pt_BR
:
You
T
ube
description
:
description
:
en_US
:
You
t
ube
en_US
:
You
T
ube
zh_Hans
:
You
t
ube(油管)是全球最大的视频分享网站,用户可以在上面上传、观看和分享视频。
zh_Hans
:
You
T
ube(油管)是全球最大的视频分享网站,用户可以在上面上传、观看和分享视频。
pt_BR
:
You
t
ube é o maior site de compartilhamento de vídeos do mundo, onde os usuários podem fazer upload, assistir e compartilhar vídeos.
pt_BR
:
You
T
ube é o maior site de compartilhamento de vídeos do mundo, onde os usuários podem fazer upload, assistir e compartilhar vídeos.
icon
:
icon.png
icon
:
icon.png
credentials_for_provider
:
credentials_for_provider
:
google_api_key
:
google_api_key
:
...
...
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