luogu 0.2.3 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a148eff2b580b1fc02bf9a71ffbef28bcfbe54752bc73c877ea17ed19cf301c4
4
- data.tar.gz: edeb9d2d566292180ad9cc29c172a2e7545c1656dd3791258780adf8a0587571
3
+ metadata.gz: 0e121e0329cf0f92c56754426facf7c5142941bdb859a19b3125cc9a53e30221
4
+ data.tar.gz: 0a8d2f4ae3b4599bbe60960dfaf6d5cfc8c6d21c5e9e69bd7e7432d30ec9c36f
5
5
  SHA512:
6
- metadata.gz: 3fd79fb77f48a73cd6e64194cd2826e23ad27c18d7904c0a737c0b2340bc080a33e65271f005f91a6182eed36f77ccb08c15efd4f93c43588b3ac6800af2e48c
7
- data.tar.gz: 4f3fbb7674ae5dd9ddf3df8979ccbea102552527eba4090309cf6a0265d4022701e1338d91fa8dba4283acc9bede24398365ad8dddc4e4efe606e0b28e9b3e9f
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)
@@ -80,7 +82,7 @@ module Luogu::OpenAI
80
82
  @system = {}
81
83
  end
82
84
 
83
- def system(text: nil, file_: nil)
85
+ def system(text: nil, file: nil)
84
86
  data = text || File.read(file)
85
87
  @system = {role: "system", content: data}
86
88
  self
@@ -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.3"
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.3
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