luo 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 168fa20c108843fd5b48bc0c3dd2771e3293712b3783069f93c41b60dd094cbe
4
- data.tar.gz: 374e6355534cb49ece0bd5a1fd521b9dea292fc9e461e29e9c8a15301e012892
3
+ metadata.gz: 8adf1591ea5c1117db3c1c08e5b9e89fdcd9b1ea37ee0406d5a5754d1c616061
4
+ data.tar.gz: '019cd793af192d18e8926d473ef5842bffeafb9d9c7d2dd9e5e47ed2acef05b9'
5
5
  SHA512:
6
- metadata.gz: dcbca395fbc33a663ae6e4349b7280ac7169473f0d4bd64bca1b43c72ccb871c080a3a2f6e105dbc39f7571e8b1749abae40da585e8a0aa93d59c91106828efd
7
- data.tar.gz: 9ed6651fec55cf76bab4901cfa50442cb63250c78b7efd4ab584191006870d6845f70a45f2ad674393b361a7ef94c6f4096307dceec573863f6dca47e31e1b11
6
+ metadata.gz: e92c4d58d37139ef46c2a5e2da322e9cee3b7969b8eb70dcbbcd6324ce8170b3d4b2515ae7cc934ae1fbaef885af1ee503f189566845f6cce56f734346e66ddd
7
+ data.tar.gz: dc91a333d4d8a906e0990c4dda46072c2a6b4afdb3d1f1eb26fdb2330f40ccf8444eb892ec22afbd3732db525ee4fc2b181df605313cbd3d454fb395d4bc3459
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luo (0.1.2)
4
+ luo (0.1.4)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  dry-configurable (~> 1.0, >= 1.0.1)
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
- context.final_result = instance_eval(&block)
24
- context.final_result
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
 
@@ -7,7 +7,8 @@ module Luo
7
7
 
8
8
  setting :language, default: "en"
9
9
 
10
- def initialize
10
+ def initialize(histories: nil)
11
+ context.histories = histories unless histories.nil?
11
12
  on_init
12
13
  end
13
14
 
@@ -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 ||= MemoryHistory.new
16
+ @histories ||= config.history_adapter.new
14
17
  end
15
18
 
16
19
  def histories=(histories)
@@ -26,6 +26,10 @@ module Luo
26
26
  @queue << element
27
27
  end
28
28
 
29
+ def clone
30
+ Marshal.load(Marshal.dump(self))
31
+ end
32
+
29
33
  def user(content)
30
34
  enqueue({role: "user", content: content})
31
35
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Luo
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -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
- context.response = @xinghuo.chat(context.messages)
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.match(/调用工具:(.*)/)&.captures&.first&.strip&.gsub(/[[:punct:]]/, '')
21
- agent = self.class.agents[agent_name]&.new(
22
- context: context,
23
- action_input: context.user_input,
24
- client: @xinghuo
25
- )
26
- answer = context.response.match(/最终回答:(.*)/)&.captures&.first&.strip
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.2
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-06 00:00:00.000000000 Z
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