luo 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/luo/agent.rb +7 -2
- data/lib/luo/agent_runner_base.rb +2 -1
- data/lib/luo/agent_runner_context.rb +4 -1
- data/lib/luo/memory_history.rb +4 -0
- data/lib/luo/templates/luo_xinghuo_agent_input.md.erb +4 -4
- data/lib/luo/templates/luo_xinghuo_response_error.md.erb +10 -0
- data/lib/luo/version.rb +1 -1
- data/lib/luo/xinghuo_agent_runner.rb +20 -12
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8adf1591ea5c1117db3c1c08e5b9e89fdcd9b1ea37ee0406d5a5754d1c616061
|
4
|
+
data.tar.gz: '019cd793af192d18e8926d473ef5842bffeafb9d9c7d2dd9e5e47ed2acef05b9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e92c4d58d37139ef46c2a5e2da322e9cee3b7969b8eb70dcbbcd6324ce8170b3d4b2515ae7cc934ae1fbaef885af1ee503f189566845f6cce56f734346e66ddd
|
7
|
+
data.tar.gz: dc91a333d4d8a906e0990c4dda46072c2a6b4afdb3d1f1eb26fdb2330f40ccf8444eb892ec22afbd3732db525ee4fc2b181df605313cbd3d454fb395d4bc3459
|
data/Gemfile.lock
CHANGED
data/lib/luo/agent.rb
CHANGED
@@ -20,8 +20,13 @@ module Luo
|
|
20
20
|
|
21
21
|
def on_call_with_final_result(&block)
|
22
22
|
define_method(:call) do
|
23
|
-
|
24
|
-
|
23
|
+
result = instance_eval(&block)
|
24
|
+
if result.nil?
|
25
|
+
messages = context.messages.to_a[0...-1] + [{role: :user, content: context.user_input}]
|
26
|
+
context.final_result = client.chat(messages)
|
27
|
+
else
|
28
|
+
context.final_result = result
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Luo
|
4
4
|
class AgentRunnerContext
|
5
|
+
include Configurable
|
6
|
+
setting :history_adapter, default: MemoryHistory
|
7
|
+
|
5
8
|
attr_accessor :user_input, :action_input, :response, :agent_results, :final_result, :messages, :retries
|
6
9
|
|
7
10
|
def initialize
|
@@ -10,7 +13,7 @@ module Luo
|
|
10
13
|
end
|
11
14
|
|
12
15
|
def histories
|
13
|
-
@histories ||=
|
16
|
+
@histories ||= config.history_adapter.new
|
14
17
|
end
|
15
18
|
|
16
19
|
def histories=(histories)
|
data/lib/luo/memory_history.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
根据问题选择合适的工具。
|
2
|
+
你可以使用以下工具:
|
2
3
|
<% agents.values.each do |agent| -%>
|
3
4
|
- <%= agent.agent_name %>:<%= agent.agent_desc %>
|
4
5
|
<% end -%>
|
5
|
-
|
6
|
+
问题是:<%= last_user_input %>
|
7
|
+
现在我应该选择什么工具呢?请用以下格式回答:
|
6
8
|
```
|
7
9
|
调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
|
8
|
-
最终回答:你要回答的内容是什么?
|
9
10
|
```
|
10
|
-
我的问题:<%= last_user_input %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
输出的格式错误,根据问题选择合适的工具。
|
2
|
+
你可以使用以下工具:
|
3
|
+
<% agents.values.each do |agent| -%>
|
4
|
+
- <%= agent.agent_name %>:<%= agent.agent_desc %>
|
5
|
+
<% end -%>
|
6
|
+
刚刚的问题:<%= last_user_input %>
|
7
|
+
现在我应该选择什么工具呢?请用以下格式回答:
|
8
|
+
```
|
9
|
+
调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
|
10
|
+
```
|
data/lib/luo/version.rb
CHANGED
@@ -13,22 +13,30 @@ module Luo
|
|
13
13
|
on_request do
|
14
14
|
context.messages = Messages.create(history: context.histories)
|
15
15
|
.user(prompt: Luo::Prompts.luo_xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
|
16
|
-
|
16
|
+
response = @xinghuo.chat(context.messages)
|
17
|
+
if response.split("\n").select { |line| line.size >1 }.size > 1
|
18
|
+
message = Messages.create(history: context.histories)
|
19
|
+
.user(prompt: Luo::Prompts.luo_xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
|
20
|
+
.assistant(text: response)
|
21
|
+
.user(prompt: Luo::Prompts.luo_xinghuo_response_error, context: {agents: self.class.agents, last_user_input: context.user_input})
|
22
|
+
context.response = @xinghuo.chat(message)
|
23
|
+
else
|
24
|
+
context.response = response
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
on_result do
|
20
|
-
agent_name = context.response.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if agent_name.nil? && !answer.nil? && agent.nil?
|
29
|
-
context.final_result = answer
|
30
|
-
else
|
29
|
+
agent_name = context.response.scan(/调用工具(.*)/).flatten.reject(&:empty?).map(&:to_s)&.last&.gsub(/[[:punct:]]/, '')
|
30
|
+
if self.class.agents.include?(agent_name)
|
31
|
+
agent = self.class.agents[agent_name]&.new(
|
32
|
+
context: context,
|
33
|
+
action_input: context.user_input,
|
34
|
+
client: @xinghuo
|
35
|
+
)
|
31
36
|
add_agent(agent)
|
37
|
+
else
|
38
|
+
messages = Messages.create(history: context.histories).user(text: context.user_input)
|
39
|
+
context.final_result = @xinghuo.chat(messages)
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MJ
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -208,6 +208,7 @@ files:
|
|
208
208
|
- lib/luo/templates/luo_commit.md.erb
|
209
209
|
- lib/luo/templates/luo_xinghuo_agent_input.md.erb
|
210
210
|
- lib/luo/templates/luo_xinghuo_agent_tool_input.md.erb
|
211
|
+
- lib/luo/templates/luo_xinghuo_response_error.md.erb
|
211
212
|
- lib/luo/templates/prompt.demo.erb
|
212
213
|
- lib/luo/version.rb
|
213
214
|
- lib/luo/xinghuo.rb
|