luogu 0.2.4 → 0.2.5

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: e2401b23417623ac4cf2c9aefcd245b6de3bd24fe2a15518f709b4f18babe06b
4
- data.tar.gz: 62ebbbc5608cbea4d3b68e50cec002d4a586c7af378eb5b7982aef84536d46ee
3
+ metadata.gz: 0e121e0329cf0f92c56754426facf7c5142941bdb859a19b3125cc9a53e30221
4
+ data.tar.gz: 0a8d2f4ae3b4599bbe60960dfaf6d5cfc8c6d21c5e9e69bd7e7432d30ec9c36f
5
5
  SHA512:
6
- metadata.gz: 969ee9c8d69a3632b0d09a6a880ada1b297876d95a4e305edcb7f91ef8e7ef05162e77db64c7535d0c443e37a590478c9b6b34e1337bac182bbdc3c33498a05e
7
- data.tar.gz: 938498297be75543a181b8a715868aedc339fd2747196fe969e0a475ba847c2f4dc6fff435fc9cc9b9ce6c8d944c610d3558969a54d25312b2ea25cf0ffbe74e
6
+ metadata.gz: 22d8dd554b0620536b9ac858ad6e5009da3bf5eb3bba502b10710f4f783ca0b8f392895805cb9ad6db3c2f567d7c95891dc2c26149e1be76f9493622427bf74e
7
+ data.tar.gz: 89be4a1d4d4525885fcdb77889c07365b1dd22f223f2de225c79ebb99b80126bd110cec51721c03110321ce239a0bbef4e262011f9b8822c0135383c27256a81
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luogu (0.2.2)
4
+ luogu (0.2.5)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  dry-configurable (~> 1.0, >= 1.0.1)
@@ -67,15 +67,24 @@ module Luogu
67
67
  @request_params.messages = messages
68
68
  response = provider.request.call(@request_params.to_h)
69
69
  unless response.code == 200
70
- logger.error response.body
71
- raise RequestError
70
+ logger.error response.body.to_s
71
+ raise RequestError, response.body.to_s
72
72
  end
73
- content = provider.parse.call(response)
73
+
74
+ begin
75
+ content = Luogu.wrap_array(provider.parse.call(response))
76
+ rescue => error
77
+ logger.error error.message
78
+ return "error! #{error.message}"
79
+ end
80
+
81
+
74
82
  logger.debug content
83
+
75
84
  if (answer = self.find_and_save_final_answer(content))
76
85
  logger.info "final answer: #{answer}"
77
86
  answer
78
- elsif content.is_a?(Array)
87
+ else
79
88
  run_agents(content, messages, run_agent_retries: run_agent_retries)
80
89
  end
81
90
  end
data/lib/luogu/init.rb CHANGED
@@ -9,6 +9,7 @@ require 'benchmark'
9
9
  require 'erb'
10
10
  require 'logger'
11
11
  require 'securerandom'
12
+ require 'shellwords'
12
13
 
13
14
  require "dry/cli"
14
15
  require 'dry-configurable'
@@ -31,6 +32,7 @@ require_relative 'openai'
31
32
  require_relative 'terminal'
32
33
 
33
34
  require_relative 'aiui'
35
+ require_relative 'utils'
34
36
 
35
37
  class String
36
38
  def cover_chinese
data/lib/luogu/openai.rb CHANGED
@@ -49,6 +49,8 @@ module Luogu::OpenAI
49
49
  else
50
50
  result_json
51
51
  end
52
+ rescue => e
53
+ raise e, "Input must be JSON and contain action and action_input."
52
54
  end
53
55
 
54
56
  def chat_response_handle(response)
@@ -12,14 +12,14 @@ RESPONSE FORMAT INSTRUCTIONS
12
12
  When responding to me please, please output a response in one of two formats:
13
13
 
14
14
  **Option 1:**
15
- Use this if you want humans to use the tools.
15
+ Use this if you want the human to use a tool.
16
16
  Markdown code snippet formatted in the following schema:
17
17
 
18
18
  ```json
19
- [{
19
+ {
20
20
  "action": string \ The action to take. Must be one of <%= @agents.map do |a| a.name end.join(', ') %>
21
21
  "action_input": string \ The input to the action
22
- }]
22
+ }
23
23
  ```
24
24
 
25
25
  **Option #2:**
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luogu
4
+ def println(message)
5
+ if system("which glow > /dev/null 2>&1")
6
+ system("echo #{Shellwords.escape(message)} | glow -")
7
+ else
8
+ puts message
9
+ end
10
+ end
11
+
12
+ def wrap_array(obj)
13
+ if obj.is_a?(Array)
14
+ obj
15
+ else
16
+ [obj]
17
+ end
18
+ end
19
+
20
+ module_function :println, :wrap_array
21
+ end
data/lib/luogu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Luogu
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luogu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-23 00:00:00.000000000 Z
11
+ date: 2023-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -131,6 +131,7 @@ files:
131
131
  - lib/luogu/templates/agent_system.md.erb
132
132
  - lib/luogu/templates/agent_tool_input.md.erb
133
133
  - lib/luogu/terminal.rb
134
+ - lib/luogu/utils.rb
134
135
  - lib/luogu/version.rb
135
136
  - luogu.gemspec
136
137
  - prompt.md