Skip to content
代码片段 群组 项目
未验证 提交 807370eb 编辑于 作者: Mark Chao's avatar Mark Chao 提交者: GitLab
浏览文件

Log LLM ReAct turn count

上级 c8dd1f09
No related branches found
No related tags found
无相关合并请求
...@@ -33,7 +33,7 @@ def initialize(user_input:, tools:, context:, response_handler:, stream_response ...@@ -33,7 +33,7 @@ def initialize(user_input:, tools:, context:, response_handler:, stream_response
end end
def execute def execute
MAX_ITERATIONS.times do MAX_ITERATIONS.times do |i|
events = step_forward events = step_forward
raise EmptyEventsError if events.empty? raise EmptyEventsError if events.empty?
...@@ -42,7 +42,11 @@ def execute ...@@ -42,7 +42,11 @@ def execute
process_tool_action(events) || process_tool_action(events) ||
process_unknown(events) process_unknown(events)
return answer if answer next unless answer
log_info(message: "ReAct turn", react_turn: i, event_name: 'react_turn', ai_component: 'duo_chat')
return answer
end end
raise ExhaustedLoopError raise ExhaustedLoopError
......
...@@ -37,6 +37,7 @@ module Logger ...@@ -37,6 +37,7 @@ module Logger
Attribute.new(:picked_tool, String), Attribute.new(:picked_tool, String),
Attribute.new(:allowed, String), Attribute.new(:allowed, String),
Attribute.new(:tool_name, String), Attribute.new(:tool_name, String),
Attribute.new(:react_turn, Integer),
Attribute.new(:ai_event, String), Attribute.new(:ai_event, String),
Attribute.new(:params, String), Attribute.new(:params, String),
Attribute.new(:status, Integer), Attribute.new(:status, Integer),
......
...@@ -107,6 +107,9 @@ ...@@ -107,6 +107,9 @@
end end
it "streams final answer" do it "streams final answer" do
expect(agent).to receive(:log_info).with(
message: "ReAct turn", react_turn: 0, event_name: 'react_turn', ai_component: 'duo_chat')
expect(stream_response_service_double).to receive(:execute).with( expect(stream_response_service_double).to receive(:execute).with(
response: first_response_double, response: first_response_double,
options: { chunk_id: 1 } options: { chunk_id: 1 }
...@@ -144,6 +147,9 @@ ...@@ -144,6 +147,9 @@
end end
it "returns tool answer" do it "returns tool answer" do
expect(agent).to receive(:log_info).with(
message: "ReAct turn", react_turn: 0, event_name: 'react_turn', ai_component: 'duo_chat')
expect(answer.is_final?).to be_truthy expect(answer.is_final?).to be_truthy
expect(answer.content).to include("tool answer") expect(answer.content).to include("tool answer")
end end
...@@ -220,6 +226,9 @@ ...@@ -220,6 +226,9 @@
end end
it "returns unknown answer as is" do it "returns unknown answer as is" do
expect(agent).to receive(:log_info).with(
message: "ReAct turn", react_turn: 0, event_name: 'react_turn', ai_component: 'duo_chat')
expect(answer.content).to include('foo') expect(answer.content).to include('foo')
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册