luo 0.2.1 → 0.2.3
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/luo/error_handle.rb +35 -0
- data/lib/luo/helpers.rb +1 -10
- data/lib/luo/version.rb +1 -1
- data/lib/luo.rb +2 -0
- data/templates/prompts/luo_error_analyze.md.erb +9 -0
- metadata +5 -4
- data/lib/luo/init_project._rb +0 -71
- /data/templates/{NoteBookGemfile → NotebookGemfile} +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 12b18554758f8e56d6ed51c06479d5a7adb5307281ba070f55bbf7b8aeff7f39
         | 
| 4 | 
            +
              data.tar.gz: e60117cc08d28b7e0be2e256bba326b727ef823e3cc050cadcf71bc2aa85b5ca
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ce08dc5d0136f7eff5939601544608caa4c5d8b06ba170fd56df3c69f393a96f6ea925254eb06f1cae545b3b2ed82367dedc5fbbc21d2c37e691c3f331507097
         | 
| 7 | 
            +
              data.tar.gz: 203eb46cb4602bcbeaa985981322a95d682bff93c5f9382f38ba96af425233e31f7f8981f3d3e509543ef224d7916a63c6711d8e1c28a2800c065c06a72db75b
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Luo
         | 
| 4 | 
            +
              module ErrorHandle
         | 
| 5 | 
            +
                def raise(err, *args)
         | 
| 6 | 
            +
                  Luo::ErrorHandle.gpt_error_analyze(err)
         | 
| 7 | 
            +
                  super
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def fail(*args)
         | 
| 11 | 
            +
                  raise(*args)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def gpt_error_analyze(error)
         | 
| 15 | 
            +
                  if error
         | 
| 16 | 
            +
                    error_message = error.message
         | 
| 17 | 
            +
                    backtrace = error.backtrace
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    context = {
         | 
| 20 | 
            +
                      message: error_message,
         | 
| 21 | 
            +
                      backtrace: backtrace
         | 
| 22 | 
            +
                    }
         | 
| 23 | 
            +
                    Helpers.display_md(" **你的代码出错了!正在使用 ChatGPT 分析错误原因,请稍后 ... **")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    messages = Messages.create
         | 
| 26 | 
            +
                                       .system(text: "你是一个ruby专家,根据用户的输入,你需要分析出错误的原因,然后给出解决方案。")
         | 
| 27 | 
            +
                                       .user(prompt: Prompts.luo_error_analyze, context: context)
         | 
| 28 | 
            +
                    response = OpenAI.new.chat(messages)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    Helpers.display_md(response)
         | 
| 31 | 
            +
                    puts "\n"
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
    
        data/lib/luo/helpers.rb
    CHANGED
    
    | @@ -20,16 +20,7 @@ module Luo | |
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 22 | 
             
                def display_md(text)
         | 
| 23 | 
            -
                   | 
| 24 | 
            -
                    raise "Please install iruby gem first."
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  if gem_exists?('rouge')
         | 
| 28 | 
            -
                    renderer = HTMLwithRouge.new
         | 
| 29 | 
            -
                  else
         | 
| 30 | 
            -
                    renderer = Redcarpet::Render::HTML.new
         | 
| 31 | 
            -
                  end
         | 
| 32 | 
            -
             | 
| 23 | 
            +
                  renderer = HTMLwithRouge.new
         | 
| 33 24 | 
             
                  markdown = Redcarpet::Markdown.new(renderer,
         | 
| 34 25 | 
             
                                                     autolink: true,
         | 
| 35 26 | 
             
                                                     tables: true,
         | 
    
        data/lib/luo/version.rb
    CHANGED
    
    
    
        data/lib/luo.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: luo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - MJ
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-05- | 
| 11 | 
            +
            date: 2023-05-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: zeitwerk
         | 
| @@ -233,9 +233,9 @@ files: | |
| 233 233 | 
             
            - lib/luo/cli/init_base.rb
         | 
| 234 234 | 
             
            - lib/luo/cli/init_notebook.rb
         | 
| 235 235 | 
             
            - lib/luo/configurable.rb
         | 
| 236 | 
            +
            - lib/luo/error_handle.rb
         | 
| 236 237 | 
             
            - lib/luo/helpers.rb
         | 
| 237 238 | 
             
            - lib/luo/http_client.rb
         | 
| 238 | 
            -
            - lib/luo/init_project._rb
         | 
| 239 239 | 
             
            - lib/luo/loader.rb
         | 
| 240 240 | 
             
            - lib/luo/marqo.rb
         | 
| 241 241 | 
             
            - lib/luo/memory_history.rb
         | 
| @@ -269,7 +269,7 @@ files: | |
| 269 269 | 
             
            - sig/luo/prompts.rbs
         | 
| 270 270 | 
             
            - sig/luo/xinghuo.rbs
         | 
| 271 271 | 
             
            - templates/AppGemfile
         | 
| 272 | 
            -
            - templates/ | 
| 272 | 
            +
            - templates/NotebookGemfile
         | 
| 273 273 | 
             
            - templates/application.rb
         | 
| 274 274 | 
             
            - templates/env
         | 
| 275 275 | 
             
            - templates/init.rb
         | 
| @@ -279,6 +279,7 @@ files: | |
| 279 279 | 
             
            - templates/prompts/agent_tool_input.md.erb
         | 
| 280 280 | 
             
            - templates/prompts/luo_commit.md.erb
         | 
| 281 281 | 
             
            - templates/prompts/luo_error.md.erb
         | 
| 282 | 
            +
            - templates/prompts/luo_error_analyze.md.erb
         | 
| 282 283 | 
             
            - templates/prompts/xinghuo_agent_input.md.erb
         | 
| 283 284 | 
             
            - templates/prompts/xinghuo_response_error.md.erb
         | 
| 284 285 | 
             
            - templates/test.yml
         | 
    
        data/lib/luo/init_project._rb
    DELETED
    
    | @@ -1,71 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Luo
         | 
| 4 | 
            -
              module InitProject
         | 
| 5 | 
            -
                extend self
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                def project_template_file(name)
         | 
| 8 | 
            -
                  File.join(File.dirname(__FILE__), 'projects', name)
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
                def create_bundle_file()
         | 
| 11 | 
            -
                  puts "create Gemfile"
         | 
| 12 | 
            -
                  version = Luo::VERSION
         | 
| 13 | 
            -
                  unless File.exist?('Gemfile')
         | 
| 14 | 
            -
                    gemfile = <<-GEMFILE.gsub(/^ */, '')
         | 
| 15 | 
            -
                    source 'https://rubygems.org'
         | 
| 16 | 
            -
                    gem 'luo'
         | 
| 17 | 
            -
                    gem 'iruby'
         | 
| 18 | 
            -
                    gem 'pry'
         | 
| 19 | 
            -
                    GEMFILE
         | 
| 20 | 
            -
                    File.open('Gemfile', 'w') do |file|
         | 
| 21 | 
            -
                      file.puts(gemfile)
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def create_templates
         | 
| 27 | 
            -
                  puts "create templates directory"
         | 
| 28 | 
            -
                  unless File.directory?('templates')
         | 
| 29 | 
            -
                    FileUtils.cp_r(File.join(__dir__, 'projects', 'prompts'), 'prompts')
         | 
| 30 | 
            -
                  end
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def create_agent_directory
         | 
| 34 | 
            -
                  puts "create agent directory"
         | 
| 35 | 
            -
                  FileUtils.mkdir_p('agents')
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                def create_application
         | 
| 39 | 
            -
                  puts "create application"
         | 
| 40 | 
            -
                  copy_file('init.rb', 'init.rb')
         | 
| 41 | 
            -
                  copy_file('application.rb', 'app.rb')
         | 
| 42 | 
            -
                  copy_file('env', '.env')
         | 
| 43 | 
            -
                  copy_file('time_agent.rb', 'agents/time_agent.rb')
         | 
| 44 | 
            -
                  copy_file('weather_agent.rb', 'agents/weather_agent.rb')
         | 
| 45 | 
            -
                  copy_file('luo.ipynb', 'luo.ipynb')
         | 
| 46 | 
            -
                  copy_file("test.yml", "test.yml")
         | 
| 47 | 
            -
                end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                def copy_file(file_name, target_file_name)
         | 
| 50 | 
            -
                  puts "copy #{file_name} to #{target_file_name}"
         | 
| 51 | 
            -
                  unless File.exist?(target_file_name)
         | 
| 52 | 
            -
                    FileUtils.copy_file(project_template_file(file_name), target_file_name)
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                def run()
         | 
| 57 | 
            -
                  create_bundle_file
         | 
| 58 | 
            -
                  create_templates
         | 
| 59 | 
            -
                  create_agent_directory
         | 
| 60 | 
            -
                  create_application
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  Helpers.print_md """
         | 
| 63 | 
            -
                  ## Luo Project Initialized
         | 
| 64 | 
            -
                  You can now run `bundle install` to install the dependencies
         | 
| 65 | 
            -
                  and edit .env to add your API key.
         | 
| 66 | 
            -
                  and `bundle exec ruby application.rb` to run the project.
         | 
| 67 | 
            -
                  """
         | 
| 68 | 
            -
                end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              end
         | 
| 71 | 
            -
            end
         | 
| 
            File without changes
         |