luo 0.1.25 → 0.2.0

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -3
  3. data/exe/luo +1 -1
  4. data/lib/luo/cli/init_app.rb +12 -0
  5. data/lib/luo/cli/init_base.rb +45 -0
  6. data/lib/luo/cli/init_notebook.rb +15 -0
  7. data/lib/luo/cli.rb +33 -49
  8. data/lib/luo/helpers.rb +8 -0
  9. data/lib/luo/{init_project.rb → init_project._rb} +1 -1
  10. data/lib/luo/marqo.rb +1 -1
  11. data/lib/luo/open_ai_agent_runner.rb +15 -4
  12. data/lib/luo/parser_markdown.rb +34 -0
  13. data/lib/luo/project_init.rb +9 -0
  14. data/lib/luo/prompt_template.rb +7 -3
  15. data/lib/luo/prompts.rb +30 -2
  16. data/lib/luo/version.rb +1 -1
  17. data/lib/luo/xinghuo.rb +9 -8
  18. data/lib/luo/xinghuo_agent_runner.rb +7 -3
  19. data/lib/luo.rb +24 -2
  20. data/luo.gemspec +2 -1
  21. data/sig/luo/prompt_template.rbs +1 -1
  22. data/{lib/luo/projects → templates}/application.rb +5 -1
  23. data/templates/prompts/luo_error.md.erb +8 -0
  24. metadata +48 -46
  25. data/.idea/.gitignore +0 -8
  26. data/.idea/dictionaries/mj.xml +0 -7
  27. data/.idea/inspectionProfiles/Project_Default.xml +0 -9
  28. data/.idea/luo.iml +0 -81
  29. data/.idea/misc.xml +0 -4
  30. data/.idea/modules.xml +0 -8
  31. data/.idea/vcs.xml +0 -6
  32. data/init.rb +0 -16
  33. data/lib/luo/templates/agent_input.md.erb +0 -39
  34. data/lib/luo/templates/agent_system.md.erb +0 -4
  35. data/lib/luo/templates/agent_tool_input.md.erb +0 -10
  36. data/lib/luo/templates/demo.md.erb +0 -1
  37. data/lib/luo/templates/luo_xinghuo_agent_tool_input.md.erb +0 -16
  38. data/lib/luo/templates/xinghuo_agent_input.md.erb +0 -10
  39. data/lib/luo/templates/xinghuo_response_error.md.erb +0 -10
  40. data/luo.ipynb +0 -84
  41. data/templates/luo_agent_input.md.erb +0 -39
  42. data/templates/luo_agent_system.md.erb +0 -4
  43. data/templates/luo_agent_tool_input.md.erb +0 -10
  44. data/templates/luo_commit.md.erb +0 -2
  45. data/templates/luo_xinghuo_agent_input.md.erb +0 -10
  46. data/templates/luo_xinghuo_agent_tool_input.md.erb +0 -16
  47. data/templates/luo_xinghuo_response_error.md.erb +0 -10
  48. data/templates/prompt.demo.erb +0 -1
  49. /data/{lib/luo/projects → templates}/env +0 -0
  50. /data/{lib/luo/projects → templates}/init.rb +0 -0
  51. /data/{lib/luo/projects → templates}/luo.ipynb +0 -0
  52. /data/{lib/luo/projects → templates}/prompts/agent_input.md.erb +0 -0
  53. /data/{lib/luo/projects → templates}/prompts/agent_system.md.erb +0 -0
  54. /data/{lib/luo/projects → templates}/prompts/agent_tool_input.md.erb +0 -0
  55. /data/{lib/luo/templates → templates/prompts}/luo_commit.md.erb +0 -0
  56. /data/{lib/luo/projects → templates}/prompts/xinghuo_agent_input.md.erb +0 -0
  57. /data/{lib/luo/projects → templates}/prompts/xinghuo_response_error.md.erb +0 -0
  58. /data/{lib/luo/projects → templates}/test.yml +0 -0
  59. /data/{lib/luo/projects → templates}/time_agent.rb +0 -0
  60. /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: 12601aff9972b8acace601e1fd79ed219577d8063379f0c2c8677c6af24a731b
4
- data.tar.gz: ae7ccf1bed46c7ff1eeea7328a034b6557674f4fc1c2df5135ead23f4eb5fa70
3
+ metadata.gz: 2357d89c3ae18e5aef8a31e53226a971d7738b121c07840bad3af6c1763f116b
4
+ data.tar.gz: b9bb7e8c1db63268c8cba723eb0c27cbd3bdc111fe487811204c887d5795d592
5
5
  SHA512:
6
- metadata.gz: 79bf668ce8fbef426bc81409e159401a9eb301d38dadb9e3b5af21dd913477e47ef873cab930caebdc51e50ef84c2976d1bf43cb8e82db7746ad66df6deaddc0
7
- data.tar.gz: c6d75bba67f02b51c4a99e38a9651687534e947cb0bed38b49534691d5c5a1a23e8a7ee80ba328bd579f21a72c12acec825858c986949cdb0fe95577daa97989
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.1.25)
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
@@ -4,4 +4,4 @@
4
4
  require "bundler/setup"
5
5
  require "luo"
6
6
 
7
- Dry::CLI.new(Luo::CLI::Commands).call
7
+ Luo::CLI::APP.start
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luo
4
+ module CLI
5
+ class InitApp < InitBase
6
+ def copy_app
7
+ say "Copying App...", :green
8
+ copy_file "application.rb", "app.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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
- module Commands
6
- extend Dry::CLI::Registry
5
+ class APP < Thor
7
6
 
8
- class Version < Dry::CLI::Command
9
- desc "Print version"
7
+ map %w[--version -v] => :__print_version
8
+ map 'c' => :commit
10
9
 
11
- def call(*)
12
- puts Luo::VERSION
13
- end
10
+ desc "--version, -v", "print the version"
11
+ def __print_version
12
+ puts "Luo version #{Luo::VERSION}"
14
13
  end
15
14
 
16
- class Init < Dry::CLI::Command
17
- desc "Init Luo Project"
18
-
19
- def call(*)
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
- exec "git commit -m '#{response}'"
20
+ else
21
+ response = Xinghuo.new.chat(messages)
33
22
  end
23
+ exec "git commit -m '#{response}'"
34
24
  end
35
25
 
36
- class Run < Dry::CLI::Command
37
- desc "Run Luo"
38
-
39
- def call(*)
40
- exec "jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root"
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
- class Bundle < Dry::CLI::Command
45
- desc "Bundle with Luo"
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
- class Exec < Dry::CLI::Command
53
- desc "Exec with Luo"
54
- argument :task, type: :string, required: true
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
- def call(task: ,**)
57
- exec task
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
@@ -18,5 +18,13 @@ module Luo
18
18
  yield(data)
19
19
  end
20
20
  end
21
+
22
+ def gem_exists?(gem_name)
23
+ Gem::Specification.find_by_name(gem_name)
24
+ true
25
+ rescue Gem::LoadError
26
+ false
27
+ end
28
+
21
29
  end
22
30
  end
@@ -13,7 +13,7 @@ module Luo
13
13
  unless File.exist?('Gemfile')
14
14
  gemfile = <<-GEMFILE.gsub(/^ */, '')
15
15
  source 'https://rubygems.org'
16
- gem 'luo', '~> #{version}'
16
+ gem 'luo'
17
17
  gem 'iruby'
18
18
  gem 'pry'
19
19
  GEMFILE
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: ENV.fetch('OPENAI_REQUEST_RETRIES', 3).to_i
8
+ setting :retries, default: 3
9
9
 
10
10
  include HttpClient.init_client(headers: { 'X-API-KEY' => config.x_api_key })
11
11
 
@@ -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: Luo::Prompts.agent_system)
17
- .user(prompt: Luo::Prompts.agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
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
- actions = JSON.parse(context.response)
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: Luo::Prompts.agent_tool_input,
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luo
4
+ class ProjectInit
5
+ def initialize(app_type: "notebook")
6
+ @app_type = app_type
7
+ end
8
+ end
9
+ end
@@ -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
- @template = ERB.new(File.read(@file_path), trim_mode: '-')
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(File.dirname(__FILE__), 'templates', file_name)
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__}/templates"
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
- Dir.glob("#{dir_path}/*.md.erb") do |file|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Luo
4
- VERSION = "0.1.25"
4
+ VERSION = "0.2.0"
5
5
  end
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('XINGHUO_ACCESS_TOKEN')
8
- setting :retries, default: ENV.fetch('XINGHUO_REQUEST_RETRIES', 3).to_i
9
- setting :host, default: ENV.fetch('XINGHUO_HOST', 'https://integration-api.iflyos.cn/')
10
- setting :history_limit, default: ENV.fetch('XINGHUO_LIMIT_HISTORY', '6').to_i * 2
11
- setting :temperature, default: ENV.fetch('XINGHUO_TEMPERATURE', 0).to_i
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('/external/ls_log/xf_completions', params.to_h)
31
+ client.post('/v1/spark/completions', params.to_h)
31
32
  end
32
33
 
33
- def chat(messages, temperature: nil)
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: temperature || config.temperature,
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: Luo::Prompts.xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
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: Luo::Prompts.xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
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: Luo::Prompts.xinghuo_response_error, context: {agents: self.class.agents, last_user_input: context.user_input})
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/load'
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
 
@@ -1,6 +1,6 @@
1
1
  module Luo
2
2
  class PromptTemplate
3
- @file_path: string
3
+ @file_path: String?
4
4
  @template: ERB
5
5
 
6
6
  def self.create: -> PromptTemplate
@@ -1,4 +1,8 @@
1
- require_relative 'init'
1
+ require 'luo'
2
+
3
+ Luo.app_setup do |loader|
4
+ loader.push_dir(File.join(__dir__, 'agents'))
5
+ end
2
6
 
3
7
  class Runner < XinghuoAgentRunner
4
8
  register WeatherAgent
@@ -0,0 +1,8 @@
1
+ 下面是一个基于ruby thor实现的命令行工具,
2
+ 用户调的命令:
3
+ <%= command %>
4
+ 发生了下面的错误:
5
+ <%= error %>
6
+
7
+ --------------------
8
+ 用中文给用户提示信息,并且说明如何解决问题, 最好给出正确的命令示例