luo 0.1.24 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/exe/luo +1 -1
- data/lib/luo/cli/init_app.rb +12 -0
- data/lib/luo/cli/init_base.rb +45 -0
- data/lib/luo/cli/init_notebook.rb +15 -0
- data/lib/luo/cli.rb +33 -49
- data/lib/luo/helpers.rb +8 -0
- data/lib/luo/{init_project.rb → init_project._rb} +1 -1
- data/lib/luo/marqo.rb +1 -1
- data/lib/luo/open_ai.rb +2 -1
- data/lib/luo/open_ai_agent_runner.rb +15 -4
- data/lib/luo/parser_markdown.rb +34 -0
- data/lib/luo/project_init.rb +9 -0
- data/lib/luo/prompt_template.rb +7 -3
- data/lib/luo/prompts.rb +30 -2
- data/lib/luo/version.rb +1 -1
- data/lib/luo/xinghuo.rb +9 -8
- data/lib/luo/xinghuo_agent_runner.rb +7 -3
- data/lib/luo.rb +24 -2
- data/luo.gemspec +2 -1
- data/sig/luo/prompt_template.rbs +1 -1
- data/{lib/luo/projects → templates}/application.rb +5 -1
- data/{lib/luo/projects → templates}/env +2 -1
- data/templates/prompts/luo_error.md.erb +8 -0
- metadata +48 -46
- data/.idea/.gitignore +0 -8
- data/.idea/dictionaries/mj.xml +0 -7
- data/.idea/inspectionProfiles/Project_Default.xml +0 -9
- data/.idea/luo.iml +0 -81
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/init.rb +0 -16
- data/lib/luo/templates/agent_input.md.erb +0 -39
- data/lib/luo/templates/agent_system.md.erb +0 -4
- data/lib/luo/templates/agent_tool_input.md.erb +0 -10
- data/lib/luo/templates/demo.md.erb +0 -1
- data/lib/luo/templates/luo_xinghuo_agent_tool_input.md.erb +0 -16
- data/lib/luo/templates/xinghuo_agent_input.md.erb +0 -10
- data/lib/luo/templates/xinghuo_response_error.md.erb +0 -10
- data/luo.ipynb +0 -84
- data/templates/luo_agent_input.md.erb +0 -39
- data/templates/luo_agent_system.md.erb +0 -4
- data/templates/luo_agent_tool_input.md.erb +0 -10
- data/templates/luo_commit.md.erb +0 -2
- data/templates/luo_xinghuo_agent_input.md.erb +0 -10
- data/templates/luo_xinghuo_agent_tool_input.md.erb +0 -16
- data/templates/luo_xinghuo_response_error.md.erb +0 -10
- data/templates/prompt.demo.erb +0 -1
- /data/{lib/luo/projects → templates}/init.rb +0 -0
- /data/{lib/luo/projects → templates}/luo.ipynb +0 -0
- /data/{lib/luo/projects → templates}/prompts/agent_input.md.erb +0 -0
- /data/{lib/luo/projects → templates}/prompts/agent_system.md.erb +0 -0
- /data/{lib/luo/projects → templates}/prompts/agent_tool_input.md.erb +0 -0
- /data/{lib/luo/templates → templates/prompts}/luo_commit.md.erb +0 -0
- /data/{lib/luo/projects → templates}/prompts/xinghuo_agent_input.md.erb +0 -0
- /data/{lib/luo/projects → templates}/prompts/xinghuo_response_error.md.erb +0 -0
- /data/{lib/luo/projects → templates}/test.yml +0 -0
- /data/{lib/luo/projects → templates}/time_agent.rb +0 -0
- /data/{lib/luo/projects → templates}/weather_agent.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2357d89c3ae18e5aef8a31e53226a971d7738b121c07840bad3af6c1763f116b
|
4
|
+
data.tar.gz: b9bb7e8c1db63268c8cba723eb0c27cbd3bdc111fe487811204c887d5795d592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2efc0ca521f10ce965a0ba49f9b4265a1277c493ce54a77cdcb87dcc3501c51ac1408a7ee692cb31dee56aed4652504032a95955e20bb19f5cfa64565d286fb
|
7
|
+
data.tar.gz: 15e7e45e309805cd021dbc10fa58d65770859b76eb0872305d5b92bb115b9185185ebd44592a4c3f2ccfd0bbe05df46c77293469d78f70ddb4ed1bf1843ad946
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
luo (0.
|
4
|
+
luo (0.2.0)
|
5
5
|
dotenv (~> 2.8, >= 2.8.1)
|
6
|
-
dry-cli (~> 1.0)
|
7
6
|
dry-configurable (~> 1.0, >= 1.0.1)
|
8
7
|
dry-schema (~> 1.13, >= 1.13.1)
|
9
8
|
faraday (~> 2.7, >= 2.7.4)
|
10
9
|
faraday-retry (~> 2.1)
|
10
|
+
redcarpet (~> 3.6)
|
11
|
+
thor (~> 1.2, >= 1.2.2)
|
11
12
|
tty-markdown (~> 0.7.2)
|
12
13
|
zeitwerk (~> 2.6, >= 2.6.8)
|
13
14
|
|
@@ -17,7 +18,6 @@ GEM
|
|
17
18
|
concurrent-ruby (1.2.2)
|
18
19
|
diff-lcs (1.5.0)
|
19
20
|
dotenv (2.8.1)
|
20
|
-
dry-cli (1.0.0)
|
21
21
|
dry-configurable (1.0.1)
|
22
22
|
dry-core (~> 1.0, < 2)
|
23
23
|
zeitwerk (~> 2.6)
|
@@ -55,6 +55,7 @@ GEM
|
|
55
55
|
pastel (0.8.0)
|
56
56
|
tty-color (~> 0.5)
|
57
57
|
rake (13.0.6)
|
58
|
+
redcarpet (3.6.0)
|
58
59
|
rexml (3.2.5)
|
59
60
|
rouge (4.1.0)
|
60
61
|
rspec (3.12.0)
|
@@ -76,6 +77,7 @@ GEM
|
|
76
77
|
unicode-display_width (>= 1.5, < 3.0)
|
77
78
|
unicode_utils (~> 1.4)
|
78
79
|
strings-ansi (0.2.0)
|
80
|
+
thor (1.2.2)
|
79
81
|
tty-color (0.6.0)
|
80
82
|
tty-markdown (0.7.2)
|
81
83
|
kramdown (>= 1.16.2, < 3.0)
|
data/exe/luo
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Luo
|
4
|
+
module CLI
|
5
|
+
class InitBase < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
def create_dirtories
|
8
|
+
say "Creating directories...", :green
|
9
|
+
empty_directory("prompts")
|
10
|
+
empty_directory("agents")
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_files
|
14
|
+
say "Copying OpenAI Prompts...", :green
|
15
|
+
copy_file "prompts/agent_input.md.erb", "prompts/agent_input.md.erb"
|
16
|
+
copy_file "prompts/agent_system.md.erb", "prompts/agent_system.md.erb"
|
17
|
+
copy_file "prompts/agent_tool_input.md.erb", "prompts/agent_tool_input.md.erb"
|
18
|
+
|
19
|
+
say "Copying Xinghuo Prompts...", :green
|
20
|
+
copy_file "prompts/xinghuo_agent_input.md.erb", "prompts/xinghuo_agent_input.md.erb"
|
21
|
+
copy_file "prompts/xinghuo_response_error.md.erb", "prompts/xinghuo_response_error.md.erb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_agents
|
25
|
+
say "Copying Agents Demo...", :green
|
26
|
+
copy_file "time_agent.rb", "agents/time_agent.rb"
|
27
|
+
copy_file "weather_agent.rb", "agents/weather_agent.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
def copy_env
|
31
|
+
say "Copying luo.env...", :green
|
32
|
+
copy_file "env", "luo.env"
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_test_file
|
36
|
+
say "Copying test file...", :green
|
37
|
+
copy_file "test.yml", "test.yml"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.source_root
|
41
|
+
Pathname.new(File.join(__dir__, "../../../templates")).expand_path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Luo
|
4
|
+
module CLI
|
5
|
+
class InitNotebook < InitBase
|
6
|
+
|
7
|
+
desc "Initialize a notebook project"
|
8
|
+
def copy_notebook
|
9
|
+
say "Copying Notebook...", :green
|
10
|
+
copy_file "luo.ipynb", "luo.ipynb"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/luo/cli.rb
CHANGED
@@ -2,70 +2,54 @@
|
|
2
2
|
|
3
3
|
module Luo
|
4
4
|
module CLI
|
5
|
-
|
6
|
-
extend Dry::CLI::Registry
|
5
|
+
class APP < Thor
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
map %w[--version -v] => :__print_version
|
8
|
+
map 'c' => :commit
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
desc "--version, -v", "print the version"
|
11
|
+
def __print_version
|
12
|
+
puts "Luo version #{Luo::VERSION}"
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Luo::InitProject.run
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Commit < Dry::CLI::Command
|
25
|
-
desc "Commit with Luo"
|
26
|
-
|
27
|
-
argument :message, desc: "Commit message", required: true, type: :string
|
28
|
-
|
29
|
-
def call(message:, **)
|
30
|
-
messages = Messages.create.system(prompt: Luo::Prompts.luo_commit, context: {commit: message}).to_a
|
15
|
+
desc "commit <message>", "git commit with luo"
|
16
|
+
def commit(message)
|
17
|
+
messages = Messages.create.user(prompt: Luo::Prompts.luo_commit, context: {commit: message}).to_a
|
18
|
+
if ENV["LUO_LLM_MODE"] == "openai"
|
31
19
|
response = OpenAI.new.chat(messages)
|
32
|
-
|
20
|
+
else
|
21
|
+
response = Xinghuo.new.chat(messages)
|
33
22
|
end
|
23
|
+
exec "git commit -m '#{response}'"
|
34
24
|
end
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
desc "init", "initialize luo"
|
27
|
+
option :type, aliases: "-t", default: "notebook", desc: "type of luo project", enum: %w[notebook app]
|
28
|
+
def init
|
29
|
+
if options[:type] == "notebook"
|
30
|
+
invoke InitNotebook
|
31
|
+
elsif options[:type] == "app"
|
32
|
+
invoke InitApp
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def call(*)
|
48
|
-
exec "bundle install"
|
49
|
-
end
|
50
|
-
end
|
36
|
+
def self.exit_on_failure?
|
37
|
+
if $! && $!.is_a?(Thor::Error)
|
51
38
|
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
command = "luo " + ARGV.join(' ')
|
40
|
+
messages = Messages.create.user(prompt: Luo::Prompts.luo_error, context: {error: $!.message, command: command}).to_a
|
41
|
+
if ENV["LUO_LLM_MODE"] == "openai"
|
42
|
+
response = OpenAI.new.chat(messages)
|
43
|
+
else
|
44
|
+
response = Xinghuo.new.chat(messages)
|
45
|
+
end
|
55
46
|
|
56
|
-
|
57
|
-
|
47
|
+
shell = Thor::Shell::Color.new
|
48
|
+
shell.say "\n #{response}", :green
|
58
49
|
end
|
50
|
+
true
|
59
51
|
end
|
60
52
|
|
61
|
-
register "version", Version, aliases: %w[v -v --version]
|
62
|
-
register "commit", Commit, aliases: ["c"]
|
63
|
-
register "init", Init, aliases: ["i"]
|
64
|
-
register "run", Run, aliases: ["r"]
|
65
|
-
register "bundle", Bundle, aliases: ["b"]
|
66
|
-
register "exec", Exec, aliases: ["e"]
|
67
|
-
|
68
53
|
end
|
69
|
-
|
70
54
|
end
|
71
|
-
end
|
55
|
+
end
|
data/lib/luo/helpers.rb
CHANGED
data/lib/luo/marqo.rb
CHANGED
@@ -5,7 +5,7 @@ module Luo
|
|
5
5
|
include Configurable
|
6
6
|
setting :host, default: "http://localhost:8882"
|
7
7
|
setting :x_api_key, default: nil
|
8
|
-
setting :retries, default:
|
8
|
+
setting :retries, default: 3
|
9
9
|
|
10
10
|
include HttpClient.init_client(headers: { 'X-API-KEY' => config.x_api_key })
|
11
11
|
|
data/lib/luo/open_ai.rb
CHANGED
@@ -8,6 +8,7 @@ module Luo
|
|
8
8
|
setting :retries, default: ENV.fetch('OPENAI_REQUEST_RETRIES', 3).to_i
|
9
9
|
setting :host, default: ENV.fetch('OPENAI_HOST', 'https://api.openai.com')
|
10
10
|
setting :temperature, default: ENV.fetch('OPENAI_TEMPERATURE', 1).to_i
|
11
|
+
setting :model, default: ENV.fetch('OPENAI_CHAT_MODEL', 'gpt-3.5-turbo')
|
11
12
|
|
12
13
|
include HttpClient.init_client
|
13
14
|
|
@@ -53,7 +54,7 @@ module Luo
|
|
53
54
|
messages = messages.to_a
|
54
55
|
end
|
55
56
|
params = PARAMS.call(
|
56
|
-
model:
|
57
|
+
model: config.model,
|
57
58
|
temperature: temperature || config.temperature,
|
58
59
|
messages: messages
|
59
60
|
)
|
@@ -6,6 +6,11 @@ module Luo
|
|
6
6
|
include Configurable
|
7
7
|
|
8
8
|
setting :retires, default: 3
|
9
|
+
setting :prompts do
|
10
|
+
setting :input, default: Luo::Prompts.agent_input
|
11
|
+
setting :system, default: Luo::Prompts.agent_system
|
12
|
+
setting :tool_input, default: Luo::Prompts.agent_tool_input
|
13
|
+
end
|
9
14
|
|
10
15
|
on_init do
|
11
16
|
@openai = OpenAI.new
|
@@ -13,13 +18,19 @@ module Luo
|
|
13
18
|
|
14
19
|
on_request do
|
15
20
|
context.messages = Messages.create(history: context.histories)
|
16
|
-
.system(prompt:
|
17
|
-
.user(prompt:
|
21
|
+
.system(prompt: config.prompts.system)
|
22
|
+
.user(prompt: config.prompts.input, context: {agents: self.class.agents, last_user_input: context.user_input})
|
18
23
|
context.response = @openai.chat(context.messages)
|
19
24
|
end
|
20
25
|
|
26
|
+
##
|
27
|
+
# TODO: 用markdown解析库来解析response
|
21
28
|
on_result do
|
22
|
-
|
29
|
+
begin
|
30
|
+
actions = JSON.parse(context.response)
|
31
|
+
rescue JSON::ParserError => e
|
32
|
+
actions = JSON.parse ParserMarkdown.new(context.response).code
|
33
|
+
end
|
23
34
|
actions = [actions] if actions.is_a?(Hash)
|
24
35
|
actions.each do |action|
|
25
36
|
agent = self.class.agents[action['action']]&.new(
|
@@ -39,7 +50,7 @@ module Luo
|
|
39
50
|
after_run do
|
40
51
|
if context.retries < config.retires && context.final_result.nil?
|
41
52
|
context.messages = context.messages.assistant(
|
42
|
-
prompt:
|
53
|
+
prompt: config.prompts.tool_input,
|
43
54
|
context: {
|
44
55
|
tools_response: context.agent_results
|
45
56
|
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Luo
|
4
|
+
class ParserMarkdown
|
5
|
+
def initialize(text)
|
6
|
+
@renderer = CustomRenderer.new
|
7
|
+
@markdown = Redcarpet::Markdown.new(@renderer, fenced_code_blocks: true)
|
8
|
+
@text = text
|
9
|
+
|
10
|
+
parse @text
|
11
|
+
end
|
12
|
+
|
13
|
+
def code
|
14
|
+
@renderer.code
|
15
|
+
end
|
16
|
+
|
17
|
+
def language
|
18
|
+
@renderer.language
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse(text)
|
22
|
+
@markdown.render(text)
|
23
|
+
end
|
24
|
+
|
25
|
+
class CustomRenderer < Redcarpet::Render::HTML
|
26
|
+
attr_reader :code, :language
|
27
|
+
|
28
|
+
def block_code(code, language)
|
29
|
+
@code = code
|
30
|
+
@language = language
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/luo/prompt_template.rb
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
module Luo
|
4
4
|
class PromptTemplate
|
5
|
-
def initialize(file_path)
|
5
|
+
def initialize(file_path = nil, text: nil)
|
6
6
|
@file_path = file_path
|
7
|
-
|
7
|
+
if text.nil? && !@file_path.nil?
|
8
|
+
@template = ERB.new(File.read(@file_path), trim_mode: '-')
|
9
|
+
else
|
10
|
+
@template = ERB.new(text, trim_mode: '-')
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def render(data = {})
|
@@ -31,7 +35,7 @@ module Luo
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def load_template(file_name)
|
34
|
-
self.new File.join(
|
38
|
+
self.new File.join(__dir__, '../../templates', 'prompts', file_name)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
data/lib/luo/prompts.rb
CHANGED
@@ -4,7 +4,7 @@ module Luo
|
|
4
4
|
module Prompts
|
5
5
|
extend Dry::Configurable
|
6
6
|
|
7
|
-
setting :gem_templates_dir, default: "#{__dir__}/
|
7
|
+
setting :gem_templates_dir, default: "#{__dir__}/../../templates/prompts"
|
8
8
|
setting :prompts_dir, default: "#{Dir.pwd}/prompts"
|
9
9
|
|
10
10
|
extend self
|
@@ -15,7 +15,8 @@ module Luo
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def define_templates_in_dir(dir_path)
|
18
|
-
|
18
|
+
path = Pathname.new(dir_path).expand_path.join("*.md.erb").to_s
|
19
|
+
Dir.glob(path) do |file|
|
19
20
|
template_name = File.basename(file, '.md.erb').to_sym
|
20
21
|
define_template(template_name, file)
|
21
22
|
end
|
@@ -28,6 +29,33 @@ module Luo
|
|
28
29
|
end
|
29
30
|
|
30
31
|
define_templates
|
32
|
+
|
33
|
+
def method_missing(method_name, *args, &block)
|
34
|
+
template_file = template_file_path(method_name)
|
35
|
+
if template_file
|
36
|
+
define_template(method_name, template_file)
|
37
|
+
send(method_name)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def respond_to_missing?(method_name, include_private = false)
|
44
|
+
template_file_path(method_name) || super
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def template_file_path(template_name)
|
50
|
+
gem_template_file = "#{config.gem_templates_dir}/#{template_name}.md.erb"
|
51
|
+
prompts_template_file = "#{config.prompts_dir}/#{template_name}.md.erb"
|
52
|
+
|
53
|
+
return prompts_template_file if File.exist?(prompts_template_file)
|
54
|
+
return gem_template_file if File.exist?(gem_template_file)
|
55
|
+
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
31
59
|
end
|
32
60
|
end
|
33
61
|
|
data/lib/luo/version.rb
CHANGED
data/lib/luo/xinghuo.rb
CHANGED
@@ -4,11 +4,11 @@ module Luo
|
|
4
4
|
class Xinghuo
|
5
5
|
include Configurable
|
6
6
|
|
7
|
-
setting :access_token, default: ENV.fetch('
|
8
|
-
setting :retries, default: ENV.fetch('
|
9
|
-
setting :host, default: ENV.fetch('
|
10
|
-
setting :history_limit, default: ENV.fetch('
|
11
|
-
setting :
|
7
|
+
setting :access_token, default: ENV.fetch('LISTENAI_ACCESS_TOKEN')
|
8
|
+
setting :retries, default: ENV.fetch('LISTENAI_REQUEST_RETRIES', 3).to_i
|
9
|
+
setting :host, default: ENV.fetch('LISTENAI_HOST', 'https://api.listenai.com')
|
10
|
+
setting :history_limit, default: ENV.fetch('LISTENAI_LIMIT_HISTORY', '6').to_i * 2
|
11
|
+
setting :random_threshold, default: ENV.fetch('LISTENAI_TEMPERATURE', 0).to_i
|
12
12
|
setting :auditing, default: 'default'
|
13
13
|
setting :domain, default: 'general'
|
14
14
|
setting :max_tokens, default: 1024
|
@@ -22,15 +22,16 @@ module Luo
|
|
22
22
|
optional(:domain).maybe(:string)
|
23
23
|
optional(:max_tokens).maybe(:integer)
|
24
24
|
optional(:random_threshold).maybe(:float)
|
25
|
+
optional(:uid).maybe(:string)
|
25
26
|
end
|
26
27
|
|
27
28
|
# header uid max length is 32 todo
|
28
29
|
|
29
30
|
def request_chat(params)
|
30
|
-
client.post('/
|
31
|
+
client.post('/v1/spark/completions', params.to_h)
|
31
32
|
end
|
32
33
|
|
33
|
-
def chat(messages,
|
34
|
+
def chat(messages, random_threshold: nil)
|
34
35
|
if messages.is_a?(Messages)
|
35
36
|
messages = messages.to_a
|
36
37
|
end
|
@@ -39,7 +40,7 @@ module Luo
|
|
39
40
|
domain: config.domain,
|
40
41
|
messages: messages,
|
41
42
|
max_tokens: config.max_tokens,
|
42
|
-
random_threshold:
|
43
|
+
random_threshold: random_threshold || config.random_threshold,
|
43
44
|
uid: config.uid.call
|
44
45
|
)
|
45
46
|
return params.errors unless params.success?
|
@@ -5,6 +5,10 @@ module Luo
|
|
5
5
|
include Configurable
|
6
6
|
|
7
7
|
setting :retires, default: 3
|
8
|
+
setting :prompts do
|
9
|
+
setting :input, default: Luo::Prompts.xinghuo_agent_input
|
10
|
+
setting :response_error, default: Luo::Prompts.xinghuo_response_error
|
11
|
+
end
|
8
12
|
|
9
13
|
on_init do
|
10
14
|
@xinghuo = Xinghuo.new
|
@@ -12,13 +16,13 @@ module Luo
|
|
12
16
|
|
13
17
|
on_request do
|
14
18
|
context.messages = Messages.create(history: context.histories)
|
15
|
-
.user(prompt:
|
19
|
+
.user(prompt: config.prompts.input, context: {agents: self.class.agents, last_user_input: context.user_input})
|
16
20
|
response = @xinghuo.chat(context.messages)
|
17
21
|
if response.split("\n").select { |line| line.size >1 }.size > 1
|
18
22
|
message = Messages.create(history: context.histories)
|
19
|
-
.user(prompt:
|
23
|
+
.user(prompt: config.prompts.input, context: {agents: self.class.agents, last_user_input: context.user_input})
|
20
24
|
.assistant(text: response)
|
21
|
-
.user(prompt:
|
25
|
+
.user(prompt: config.prompts.response_error, context: {agents: self.class.agents, last_user_input: context.user_input})
|
22
26
|
context.response = @xinghuo.chat(message)
|
23
27
|
else
|
24
28
|
context.response = response
|
data/lib/luo.rb
CHANGED
@@ -3,18 +3,19 @@
|
|
3
3
|
# require_relative "luo/version"
|
4
4
|
|
5
5
|
require 'erb'
|
6
|
-
require 'dotenv
|
6
|
+
require 'dotenv'
|
7
7
|
require 'json'
|
8
8
|
require 'faraday'
|
9
9
|
require 'faraday/retry'
|
10
10
|
require 'dry-configurable'
|
11
11
|
require 'dry-schema'
|
12
|
-
require 'dry/cli'
|
13
12
|
require 'yaml'
|
14
13
|
require 'tty-markdown'
|
15
14
|
require 'fileutils'
|
16
15
|
require 'dry-initializer'
|
17
16
|
require 'uri'
|
17
|
+
require 'redcarpet'
|
18
|
+
require 'thor'
|
18
19
|
|
19
20
|
require "zeitwerk"
|
20
21
|
loader = Zeitwerk::Loader.for_gem
|
@@ -27,4 +28,25 @@ loader.setup
|
|
27
28
|
module Luo
|
28
29
|
class Error < StandardError; end
|
29
30
|
# Your code goes here...
|
31
|
+
|
32
|
+
module_eval do
|
33
|
+
Dotenv.load('luo.env', '.env')
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.app_setup(&block)
|
37
|
+
include Luo
|
38
|
+
block.call(Loader) if block_given?
|
39
|
+
Loader.setup
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.notebook_setup(&block)
|
43
|
+
include Luo
|
44
|
+
block.call(Loader) if block_given?
|
45
|
+
Loader.setup
|
46
|
+
if Helpers.gem_exists?('pry')
|
47
|
+
require 'pry'
|
48
|
+
IRuby::Kernel.instance.switch_backend!(:pry)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
30
52
|
end
|
data/luo.gemspec
CHANGED
@@ -35,8 +35,9 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency 'faraday-retry', '~> 2.1'
|
36
36
|
spec.add_dependency 'dry-schema', '~> 1.13', '>= 1.13.1'
|
37
37
|
spec.add_dependency 'dry-configurable', '~> 1.0', '>= 1.0.1'
|
38
|
-
spec.add_dependency 'dry-cli', '~> 1.0'
|
39
38
|
spec.add_dependency 'tty-markdown', '~> 0.7.2'
|
39
|
+
spec.add_dependency 'redcarpet', '~> 3.6'
|
40
|
+
spec.add_dependency 'thor', '~> 1.2', '>= 1.2.2'
|
40
41
|
|
41
42
|
spec.add_development_dependency "rspec", '~> 3.12'
|
42
43
|
|
data/sig/luo/prompt_template.rbs
CHANGED