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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/luogu/agent_runner.rb +13 -4
- data/lib/luogu/init.rb +2 -0
- data/lib/luogu/openai.rb +3 -1
- data/lib/luogu/templates/agent_input.md.erb +3 -3
- data/lib/luogu/utils.rb +21 -0
- data/lib/luogu/version.rb +1 -1
- 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: 0e121e0329cf0f92c56754426facf7c5142941bdb859a19b3125cc9a53e30221
|
4
|
+
data.tar.gz: 0a8d2f4ae3b4599bbe60960dfaf6d5cfc8c6d21c5e9e69bd7e7432d30ec9c36f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d8dd554b0620536b9ac858ad6e5009da3bf5eb3bba502b10710f4f783ca0b8f392895805cb9ad6db3c2f567d7c95891dc2c26149e1be76f9493622427bf74e
|
7
|
+
data.tar.gz: 89be4a1d4d4525885fcdb77889c07365b1dd22f223f2de225c79ebb99b80126bd110cec51721c03110321ce239a0bbef4e262011f9b8822c0135383c27256a81
|
data/Gemfile.lock
CHANGED
data/lib/luogu/agent_runner.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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,
|
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
|
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:**
|
data/lib/luogu/utils.rb
ADDED
@@ -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
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
|
+
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-
|
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
|