luo 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dbeb4a32f94e774291744f6a0ec7b796b5967fedb221ce9af3b0fd8cb62b72c
4
- data.tar.gz: 6fb5fcc54d3d85496ee7aba4d63d9044dd3f1817706d922c53624429fbcbf933
3
+ metadata.gz: 294891b56e33b9a8537542538325ad107f1cead832dc6f86e25f087fd9883fc7
4
+ data.tar.gz: 861361be7def0711a6525b1f99378f4a4217e876f236ddb1e628f6458efc53e1
5
5
  SHA512:
6
- metadata.gz: a85cd8874e6afb51dd24610f066903c94319bd758c1bef2e4f1b3d7dcc61767a5538186bfe823540e228de4392f5f70d1b6f37e7396dfad39b587b90f13bb875
7
- data.tar.gz: f0cd6516b6ae49c99129e45551f915f23d36800427b871815df5abc8340f5adc9478dd16e563966e14441c9b2d2fdc75549b212c81ddc001b26fe2c75f6c3877
6
+ metadata.gz: b35623a4f996d28253dac61a920bbb2ff4b6978f882eff9e514be33dd1fdcd46fe7f3d7d19f8f40c9069ed6605a6ce1f37753b84e61ad23c6a597cdac760ea8c
7
+ data.tar.gz: e665f6f8a38cfaeb001765e624e3e83071c9745723130eeb49fa087dc8eb3c7e06c05e31f973ecf251eb89e2dc19598bd6f79eb0a0426a2d7987eac78f3d615d
data/.idea/luo.iml CHANGED
@@ -49,21 +49,21 @@
49
49
  <option name="myRootTask">
50
50
  <RakeTaskImpl id="rake">
51
51
  <subtasks>
52
- <RakeTaskImpl description="Build luo-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
52
+ <RakeTaskImpl description="Build luo-0.1.4.gem into the pkg directory" fullCommand="build" id="build" />
53
53
  <RakeTaskImpl id="build">
54
54
  <subtasks>
55
- <RakeTaskImpl description="Generate SHA512 checksum if luo-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
55
+ <RakeTaskImpl description="Generate SHA512 checksum if luo-0.1.4.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
56
56
  </subtasks>
57
57
  </RakeTaskImpl>
58
58
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
59
59
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
60
- <RakeTaskImpl description="Build and install luo-0.1.0.gem into system gems" fullCommand="install" id="install" />
60
+ <RakeTaskImpl description="Build and install luo-0.1.4.gem into system gems" fullCommand="install" id="install" />
61
61
  <RakeTaskImpl id="install">
62
62
  <subtasks>
63
- <RakeTaskImpl description="Build and install luo-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
63
+ <RakeTaskImpl description="Build and install luo-0.1.4.gem into system gems without network access" fullCommand="install:local" id="local" />
64
64
  </subtasks>
65
65
  </RakeTaskImpl>
66
- <RakeTaskImpl description="Create tag v0.1.0 and build and push luo-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
66
+ <RakeTaskImpl description="Create tag v0.1.4 and build and push luo-0.1.4.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
67
67
  <RakeTaskImpl description="" fullCommand="default" id="default" />
68
68
  <RakeTaskImpl description="" fullCommand="release" id="release" />
69
69
  <RakeTaskImpl id="release">
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in luo.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luo (0.1.3)
4
+ luo (0.1.5)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  dry-configurable (~> 1.0, >= 1.0.1)
data/README.zh.md CHANGED
@@ -6,4 +6,26 @@
6
6
  gem install luo
7
7
  ```
8
8
 
9
- ## 使用
9
+ ## 环境变量说明
10
+ ```Bash
11
+ OPENAI_ACCESS_TOKEN= # OpenAI的访问令牌
12
+ OPENAI_TEMPERATURE= # OpenAI的温度
13
+ OPENAI_LIMIT_HISTORY= # OpenAI的历史限制
14
+ AIUI_APP_KEY= # AIUI的AppKey
15
+ AIUI_APP_ID= # AIUI的AppId
16
+ XINGHUO_ACCESS_TOKEN= # 星火大模型的访问令牌
17
+ ```
18
+ 可以写在项目中的.env也可以放到系统环境变量中。
19
+
20
+ ## 使用
21
+
22
+ ### Hello World
23
+
24
+
25
+ ## 补充资源
26
+ 1. 基于embedding的知识库对话机器人:https://github.com/ankane/neighbor#openai-embeddings
27
+ ```ruby
28
+ def fetch_embeddings(input)
29
+ Luo::OpenAI.new.create_embeddings(input)
30
+ end
31
+ ```
data/lib/luo/agent.rb CHANGED
@@ -14,14 +14,23 @@ module Luo
14
14
  end
15
15
 
16
16
  class << self
17
+
18
+ # Agent 运行被调用时会调用 on_call 方法,注意如果 on_call 方法返回 nil,那么最终结果就会是 nil
17
19
  def on_call(&block)
18
20
  define_method(:call, &block)
19
21
  end
20
22
 
23
+ # Agent 运行被调用时会调用 on_call_with_final_result 方法,
24
+ # 注意如果 on_call_with_final_result 方法返回 nil,那么最终结果就会是调用一次大模型来获取结果
21
25
  def on_call_with_final_result(&block)
22
26
  define_method(:call) do
23
- context.final_result = instance_eval(&block)
24
- context.final_result
27
+ result = instance_eval(&block)
28
+ if result.nil?
29
+ messages = context.messages.to_a[0...-1] + [{role: :user, content: context.user_input}]
30
+ context.final_result = client.chat(messages)
31
+ else
32
+ context.final_result = result
33
+ end
25
34
  end
26
35
  end
27
36
 
@@ -7,7 +7,8 @@ module Luo
7
7
 
8
8
  setting :language, default: "en"
9
9
 
10
- def initialize
10
+ def initialize(histories: nil)
11
+ context.histories = histories unless histories.nil?
11
12
  on_init
12
13
  end
13
14
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Luo
4
4
  class AgentRunnerContext
5
+ include Configurable
6
+ setting :history_adapter, default: MemoryHistory
7
+
5
8
  attr_accessor :user_input, :action_input, :response, :agent_results, :final_result, :messages, :retries
6
9
 
7
10
  def initialize
@@ -10,7 +13,7 @@ module Luo
10
13
  end
11
14
 
12
15
  def histories
13
- @histories ||= MemoryHistory.new
16
+ @histories ||= config.history_adapter.new
14
17
  end
15
18
 
16
19
  def histories=(histories)
data/lib/luo/cli.rb CHANGED
@@ -13,6 +13,14 @@ module Luo
13
13
  end
14
14
  end
15
15
 
16
+ class Init < Dry::CLI::Command
17
+ desc "Init Luo Project"
18
+
19
+ def call(*)
20
+ Luo::InitProject.run
21
+ end
22
+ end
23
+
16
24
  class Commit < Dry::CLI::Command
17
25
  desc "Commit with Luo"
18
26
 
@@ -27,6 +35,7 @@ module Luo
27
35
 
28
36
  register "version", Version, aliases: %w[v -v --version]
29
37
  register "commit", Commit, aliases: ["c"]
38
+ register "init", Init, aliases: ["i"]
30
39
  end
31
40
 
32
41
  end
@@ -0,0 +1,64 @@
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
+ unless File.exist?('Gemfile')
13
+ File.open('Gemfile', 'w') do |file|
14
+ file.puts("source 'https://rubygems.org'")
15
+ file.puts("gem 'luo', '~> 0.1.5'")
16
+ end
17
+ end
18
+ end
19
+
20
+ def create_templates
21
+ puts "create templates directory"
22
+ unless File.directory?('templates')
23
+ FileUtils.cp_r(File.join(__dir__, 'templates', '.'), 'templates')
24
+ end
25
+ end
26
+
27
+ def create_agent_directory
28
+ puts "create agent directory"
29
+ FileUtils.mkdir_p('agents')
30
+ end
31
+
32
+ def create_application
33
+ puts "create application"
34
+ copy_file('init.rb', 'init.rb')
35
+ copy_file('application.rb', 'application.rb')
36
+ copy_file('env', '.env')
37
+ copy_file('time_agent.rb', 'agents/time_agent.rb')
38
+ copy_file('weather_agent.rb', 'agents/weather_agent.rb')
39
+ copy_file("test.yml", "test.yml")
40
+ end
41
+
42
+ def copy_file(file_name, target_file_name)
43
+ puts "copy #{file_name} to #{target_file_name}"
44
+ unless File.exist?(target_file_name)
45
+ FileUtils.copy_file(project_template_file(file_name), target_file_name)
46
+ end
47
+ end
48
+
49
+ def run()
50
+ create_bundle_file
51
+ create_templates
52
+ create_agent_directory
53
+ create_application
54
+
55
+ Helpers.print_md """
56
+ ## Luo Project Initialized
57
+ You can now run `bundle install` to install the dependencies
58
+ and edit .env to add your API key.
59
+ and `bundle exec ruby application.rb` to run the project.
60
+ """
61
+ end
62
+
63
+ end
64
+ end
data/lib/luo/loader.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luo
4
+ module Loader
5
+ extend self
6
+
7
+ def loader
8
+ @loader ||= Zeitwerk::Loader.new
9
+ end
10
+
11
+ def push_dir(path)
12
+ loader.push_dir(path)
13
+ end
14
+
15
+ def setup
16
+ loader.setup
17
+ end
18
+
19
+ end
20
+ end
@@ -26,6 +26,10 @@ module Luo
26
26
  @queue << element
27
27
  end
28
28
 
29
+ def clone
30
+ Marshal.load(Marshal.dump(self))
31
+ end
32
+
29
33
  def user(content)
30
34
  enqueue({role: "user", content: content})
31
35
  end
data/lib/luo/open_ai.rb CHANGED
@@ -26,10 +26,28 @@ module Luo
26
26
  optional(:user).maybe(:string)
27
27
  end
28
28
 
29
+ EMBEDDING_PARAMS = Dry::Schema.Params do
30
+ required(:input).filled(:array)
31
+ required(:model).filled(:string)
32
+ end
33
+
29
34
  def chat_completions(params)
30
35
  client.post('/v1/chat/completions', params.to_h)
31
36
  end
32
37
 
38
+ def embeddings(params)
39
+ client.post('/v1/embeddings', params.to_h)
40
+ end
41
+
42
+ def create_embeddings(text, model: 'text-embedding-ada-002')
43
+ if text.is_a?(String)
44
+ text = [text]
45
+ end
46
+ params = EMBEDDING_PARAMS.call(input: text, model: model)
47
+ return params.errors unless params.success?
48
+ embeddings(params).body.dig("data").map { |v| v["embedding"] }
49
+ end
50
+
33
51
  def chat(messages)
34
52
  if messages.is_a?(Messages)
35
53
  messages = messages.to_a
@@ -0,0 +1,33 @@
1
+ require_relative 'init'
2
+
3
+ class Runner < XinghuoAgentRunner
4
+ register WeatherAgent
5
+ register TimeAgent
6
+ register XinghuoFinalAgent
7
+ end
8
+
9
+ def run_test
10
+ runner = Runner.new
11
+
12
+ Helpers.load_test('test.yml') do |input|
13
+ context = runner.call(input)
14
+ Helpers.print_md <<~MD
15
+ ## Input:
16
+ #{input}
17
+
18
+ ## Response:
19
+ #{context.response}
20
+
21
+ ## Final Result:
22
+ #{context.final_result}
23
+
24
+ ## History:
25
+ ```ruby
26
+ #{context.histories.to_a}
27
+ ```
28
+ MD
29
+ puts "\n\n\n"
30
+ end
31
+ end
32
+
33
+ run_test
@@ -0,0 +1,6 @@
1
+ OPENAI_ACCESS_TOKEN= # OpenAI的访问令牌
2
+ OPENAI_TEMPERATURE=0 # OpenAI的温度
3
+ OPENAI_LIMIT_HISTORY=6 # OpenAI的历史记录长度
4
+ AIUI_APP_KEY= # AIUI的AppKey
5
+ AIUI_APP_ID= # AIUI的AppID
6
+ XINGHUO_ACCESS_TOKEN= # 星火的访问令牌
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ Bundler.require
5
+
6
+ require 'luo'
7
+ include Luo
8
+
9
+ Loader.push_dir(File.join(__dir__, 'agents'))
10
+ Loader.setup
@@ -0,0 +1,58 @@
1
+ - 明天天气怎么样
2
+ - 现在几点了
3
+ - 罗纳尔多是谁
4
+ - 他和齐达内谁厉害
5
+ - 人类是如何形成的?
6
+ - 什么是黑洞?
7
+ - 大熊猫为什么会濒临灭绝?
8
+ - 贝多芬是哪个国家的音乐家?
9
+ - 为什么月亮总是看起来一样的大小?
10
+ - 人体内有多少种细胞?
11
+ - 什么是DNA?
12
+ - 金属是什么?
13
+ - 什么是人工智能?
14
+ - 为什么有些人会打鼾?
15
+ - 蜜蜂为什么会蜇人?
16
+ - 为什么海水是咸的?
17
+ - 火车是谁发明的?
18
+ - 什么是网络?
19
+ - 为什么飞机能在空中飞行?
20
+ - 什么是核能?
21
+ - 什么是量子力学?
22
+ - 人类的祖先是什么?
23
+ - 为什么大象会有长鼻子?
24
+ - 什么是太阳系?
25
+ - 为什么猫咪会喜欢吃鱼?
26
+ - 什么是磁力?
27
+ - 为什么火车轮子是圆的?
28
+ - 什么是太阳能?
29
+ - 为什么花草会开花?
30
+ - 什么是地震?
31
+ - 为什么水会从高处流向低处?
32
+ - 什么是蓝牙?
33
+ - 为什么人们需要睡觉?
34
+ - 什么是太空?
35
+ - 为什么狗会汪汪叫?
36
+ - 什么是电磁波?
37
+ - 为什么鲸鱼会唱歌?
38
+ - 什么是原子?
39
+ - 为什么猴子会摘桃子?
40
+ - 什么是核武器?
41
+ - 为什么海豚会跳出水面?
42
+ - 什么是平面几何?
43
+ - 为什么大象会喷水?
44
+ - 什么是相对论?
45
+ - 为什么鸟儿会飞?
46
+ - 什么是导弹?
47
+ - 为什么鱼会游泳?
48
+ - 什么是机器学习?
49
+ - 为什么鸟儿会唱歌?
50
+ - 什么是宇宙?
51
+ - 为什么鹿角会长出来?
52
+ - 什么是热力学?
53
+ - 为什么鹦鹉会模仿人说话?
54
+ - 什么是黑科技?
55
+ - 为什么植物需要光合作用?
56
+ - 什么是气候变化?
57
+ - 为什么鱼会吐泡泡?
58
+ - 什么是爆炸?
@@ -0,0 +1,11 @@
1
+ class TimeAgent < Agent
2
+ agent_name '时间查询'
3
+ agent_desc '查询当前时间'
4
+
5
+ on_call_with_final_result do
6
+ Helpers.print_md "** call aiui time **"
7
+ messages = Luo::Messages.create.user(text: context.user_input)
8
+ response = Luo::AIUI.new.chat(messages)
9
+ response&.dig("text")
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WeatherAgent < Agent
4
+ agent_name '天气查询'
5
+ agent_desc '查询城市的天气情况,穿衣指数,空气质量等'
6
+
7
+ on_call_with_final_result do
8
+ Helpers.print_md "** call aiui weather **"
9
+ messages = Luo::Messages.create.user(text: context.user_input)
10
+ response = Luo::AIUI.new.chat(messages)
11
+ response&.dig("text")
12
+ end
13
+ end
@@ -1,10 +1,10 @@
1
- 在回答的我的问题的时候,你可以使用以下工具:
1
+ 根据问题选择合适的工具。
2
+ 你可以使用以下工具:
2
3
  <% agents.values.each do |agent| -%>
3
4
  - <%= agent.agent_name %>:<%= agent.agent_desc %>
4
5
  <% end -%>
5
- 请用以下格式回答问题
6
+ 问题是:<%= last_user_input %>
7
+ 现在我应该选择什么工具呢?请用以下格式回答:
6
8
  ```
7
9
  调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
8
- 最终回答:你要回答的内容是什么?
9
10
  ```
10
- 我的问题:<%= last_user_input %>
@@ -0,0 +1,10 @@
1
+ 输出的格式错误,根据问题选择合适的工具。
2
+ 你可以使用以下工具:
3
+ <% agents.values.each do |agent| -%>
4
+ - <%= agent.agent_name %>:<%= agent.agent_desc %>
5
+ <% end -%>
6
+ 刚刚的问题:<%= last_user_input %>
7
+ 现在我应该选择什么工具呢?请用以下格式回答:
8
+ ```
9
+ 调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
10
+ ```
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.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -13,22 +13,30 @@ module Luo
13
13
  on_request do
14
14
  context.messages = Messages.create(history: context.histories)
15
15
  .user(prompt: Luo::Prompts.luo_xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
16
- context.response = @xinghuo.chat(context.messages)
16
+ response = @xinghuo.chat(context.messages)
17
+ if response.split("\n").select { |line| line.size >1 }.size > 1
18
+ message = Messages.create(history: context.histories)
19
+ .user(prompt: Luo::Prompts.luo_xinghuo_agent_input, context: {agents: self.class.agents, last_user_input: context.user_input})
20
+ .assistant(text: response)
21
+ .user(prompt: Luo::Prompts.luo_xinghuo_response_error, context: {agents: self.class.agents, last_user_input: context.user_input})
22
+ context.response = @xinghuo.chat(message)
23
+ else
24
+ context.response = response
25
+ end
17
26
  end
18
27
 
19
28
  on_result do
20
- agent_name = context.response.match(/调用工具:(.*)/)&.captures&.last&.strip&.gsub(/[[:punct:]]/, '')
21
- agent = self.class.agents[agent_name]&.new(
22
- context: context,
23
- action_input: context.user_input,
24
- client: @xinghuo
25
- )
26
- answer = context.response.match(/最终回答:(.*)/)&.captures&.first&.strip
27
-
28
- if agent_name.nil? && !answer.nil? && agent.nil?
29
- context.final_result = answer
30
- else
29
+ agent_name = context.response.scan(/调用工具(.*)/).flatten.reject(&:empty?).map(&:to_s)&.last&.gsub(/[[:punct:]]/, '')
30
+ if self.class.agents.include?(agent_name)
31
+ agent = self.class.agents[agent_name]&.new(
32
+ context: context,
33
+ action_input: context.user_input,
34
+ client: @xinghuo
35
+ )
31
36
  add_agent(agent)
37
+ else
38
+ messages = Messages.create(history: context.histories).user(text: context.user_input)
39
+ context.final_result = @xinghuo.chat(messages)
32
40
  end
33
41
  end
34
42
 
data/lib/luo.rb CHANGED
@@ -12,6 +12,7 @@ require 'dry-schema'
12
12
  require 'dry/cli'
13
13
  require 'yaml'
14
14
  require 'tty-markdown'
15
+ require 'fileutils'
15
16
 
16
17
  require "zeitwerk"
17
18
  loader = Zeitwerk::Loader.for_gem
data/sample_/marqo.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'httparty'
2
+
3
+ class Marqo
4
+ include HTTParty
5
+
6
+ base_uri ENV.fetch('MARQO_URL')
7
+
8
+ class SearchResult < RecursiveOpenStruct
9
+ end
10
+
11
+ # TODO: Add a way to pass in auth
12
+ def initialize(auth = { username: 'admin', password: 'admin' })
13
+ @auth = auth
14
+ end
15
+
16
+ def store(index:, doc:, id:, non_tensor_fields: [])
17
+ return if ENV['MARQO_URL'].blank?
18
+ puts
19
+ puts "🧠🧠🧠 INDEX: #{index} 🧠🧠🧠"
20
+ puts "🧠🧠🧠 DOC: #{doc} 🧠🧠🧠"
21
+ puts "🧠🧠🧠 ID: #{id} 🧠🧠🧠"
22
+ puts "🧠🧠🧠 NON TENSOR FIELDS: #{non_tensor_fields} 🧠🧠🧠"
23
+ puts
24
+ options = {
25
+ headers: { 'Content-Type' => 'application/json' },
26
+ body: [doc.merge({_id: id})].to_json
27
+ }
28
+ url = "/indexes/#{index.to_s.parameterize}/documents"
29
+ if non_tensor_fields.any?
30
+ field_array = non_tensor_fields.map { |f| "non_tensor_fields=#{f}" }
31
+ url += "?#{field_array.join("&")}"
32
+ end
33
+ self.class.post(url, options).then do |response|
34
+ puts response
35
+ response.dig("items",0,"_id")
36
+ end
37
+ end
38
+
39
+ def search(index_name, query, filter: nil, limit: 5)
40
+ puts
41
+ puts "🔍🔍🔍 #{index_name} 🔍🔍🔍"
42
+ puts "🔍🔍🔍 #{query} 🔍🔍🔍"
43
+ puts "🔍🔍🔍 #{filter} 🔍🔍🔍"
44
+ puts
45
+ options = {
46
+ basic_auth: @auth,
47
+ headers: { 'Content-Type' => 'application/json' },
48
+ body: {
49
+ q: query,
50
+ filter: filter,
51
+ searchMethod: "TENSOR",
52
+ limit: limit
53
+ }.to_json
54
+ }
55
+ response = self.class.post("/indexes/#{index_name.to_s.parameterize}/search", options)
56
+ SearchResult.new(response, recurse_over_arrays: true)
57
+ end
58
+
59
+ def lexsearch(index_name, attributes, query)
60
+ options = {
61
+ basic_auth: @auth,
62
+ headers: { 'Content-Type' => 'application/json' },
63
+ body: {
64
+ q: query,
65
+ searchableAttributes: attributes,
66
+ searchMethod: "LEXICAL"
67
+ }.to_json
68
+ }
69
+ SearchResult.new(self.class.post("/indexes/#{index_name.to_s.parameterize}/search", options))
70
+ end
71
+
72
+ def delete(index_name, id_or_ids)
73
+ options = {
74
+ basic_auth: @auth,
75
+ headers: { 'Content-Type' => 'application/json' },
76
+ body: [id].flatten.to_json
77
+ }
78
+ self.class.post("/indexes/#{index_name.to_s.parameterize}/documents/delete-batch", options)
79
+ end
80
+
81
+ def remove(index_name)
82
+ options = {
83
+ basic_auth: @auth,
84
+ headers: { 'Content-Type' => 'application/json' }
85
+ }
86
+ self.class.delete("/indexes/#{index_name.to_s.parameterize}", options)
87
+ end
88
+
89
+ def self.client
90
+ @client ||= new
91
+ end
92
+
93
+ private
94
+
95
+ def wrap(result)
96
+ RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
97
+ end
98
+ end
data/sig/luo/agent.rbs CHANGED
@@ -6,6 +6,8 @@ module Luo
6
6
  attr_reader self.agent_desc: String
7
7
  attr_reader self.agent_name: String
8
8
 
9
+ def self.on_call_with_final_result: -> untyped
10
+
9
11
  attr_reader action_input: untyped
10
12
  attr_reader context: AgentRunnerContext
11
13
 
data/sig/luo/open_ai.rbs CHANGED
@@ -1,11 +1,16 @@
1
1
  module Luo
2
2
  class OpenAI
3
3
  ACCESS_TOKEN: String
4
+ EMBEDDING_PARAMS: untyped
4
5
  HOST: String
5
6
  PARAMS: untyped
6
7
 
7
8
  def chat: -> untyped
8
9
 
9
10
  def chat_completions: -> untyped
11
+
12
+ def create_embedding: -> untyped
13
+
14
+ def embeddings: -> untyped
10
15
  end
11
16
  end
@@ -0,0 +1,39 @@
1
+ TOOLS
2
+ ------
3
+ Assistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:
4
+
5
+ <% agents.values.each do |agent| -%>
6
+ > <%= agent.agent_name %>: <%= agent.agent_desc %>
7
+ <% end -%>
8
+
9
+ RESPONSE FORMAT INSTRUCTIONS
10
+ ----------------------------
11
+
12
+ When responding to me please, please output a response in one of two formats:
13
+
14
+ **Option 1:**
15
+ Use this if you want humans to use the tools.
16
+ Markdown code snippet formatted in the following schema:
17
+
18
+ ```json
19
+ [{
20
+ "action": string \ The action to take. Must be one of <%= agents.values.map do |a| a.agent_name end.join(', ') %>
21
+ "action_input": string \ The input to the action
22
+ }]
23
+ ```
24
+
25
+ **Option #2:**
26
+ Use this if you want to respond directly to the human. Markdown code snippet formatted in the following schema:
27
+
28
+ ```json
29
+ {
30
+ "action": "Final Answer",
31
+ "action_input": string \ You should put what you want to return to use here <%= Luo::AgentRunnerBase.language_info %>
32
+ }
33
+ ```
34
+
35
+ USER'S INPUT
36
+ --------------------
37
+ Here is the user's input (Remember to respond to a single or multiple actions with a json blob of markdown code snippets, and NOTHING else):
38
+
39
+ <%= last_user_input %>
@@ -0,0 +1,4 @@
1
+ Assistant is a large language model trained by OpenAI.
2
+ Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.
3
+ Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.
4
+ Overall, Assistant is a powerful system that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
@@ -0,0 +1,10 @@
1
+ TOOL RESPONSE:
2
+ ---------------------
3
+ <% tools_response.each do |r| -%>
4
+ > <%= r[:agent_name] %>: <%= r[:agent_response] %>
5
+ <% end -%>
6
+
7
+ USER'S INPUT
8
+ --------------------
9
+
10
+ Okay, so what is the response to my last comment? If using information obtained from the tools you must mention it explicitly without mentioning the tool names - I have forgotten all TOOL RESPONSES! Remember to respond to a single or multiple actions with a json blob of markdown code snippets, and NOTHING else.
@@ -0,0 +1,2 @@
1
+ 你是一个git专家,我给你中文的commit,你提供合适的英文commit,然后我再提交到github上。
2
+ 我的提交说明是:<%= commit %>
@@ -0,0 +1,10 @@
1
+ 根据问题选择合适的工具。
2
+ 你可以使用以下工具:
3
+ <% agents.values.each do |agent| -%>
4
+ - <%= agent.agent_name %>:<%= agent.agent_desc %>
5
+ <% end -%>
6
+ 问题是:<%= last_user_input %>
7
+ 现在我应该选择什么工具呢?请用以下格式回答:
8
+ ```
9
+ 调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
10
+ ```
@@ -0,0 +1,16 @@
1
+ 工具返回结果:
2
+ <% @tools_response.each do |r| -%>
3
+ > <%= r[:name] %>:<%= r[:response] %>
4
+ <% end -%>
5
+
6
+ 刚才的问题是:<%= @last_user_input %>
7
+ 结合工具的输出和你的思考。
8
+
9
+ 当你知道答案,用以下格式回答:
10
+ 最终答案: 返回给用户的内容放在这里
11
+
12
+ 当你需要使用工具,用以下格式回答:
13
+ 工具调用: 如果工具 <%= @agents.values.map do |a| a.agent_name end.join(', ') %> 中有适合的那么输入合适的工具名,没有则输入无。
14
+ 工具输入: 工具要求的输入, 如果不用输入或者工具要求不输入直接输入无。
15
+
16
+ 你只能选择其中一种格式,那么你的答案是什么呢?
@@ -0,0 +1,10 @@
1
+ 输出的格式错误,根据问题选择合适的工具。
2
+ 你可以使用以下工具:
3
+ <% agents.values.each do |agent| -%>
4
+ - <%= agent.agent_name %>:<%= agent.agent_desc %>
5
+ <% end -%>
6
+ 刚刚的问题:<%= last_user_input %>
7
+ 现在我应该选择什么工具呢?请用以下格式回答:
8
+ ```
9
+ 调用工具:你要选择的工具是什么?只能在<%= agents.values.map do |a| a.agent_name end.join(',') %>中选择一个
10
+ ```
@@ -0,0 +1 @@
1
+ <%= text %>
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.1.3
4
+ version: 0.1.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-05-06 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -196,10 +196,18 @@ files:
196
196
  - lib/luo/configurable.rb
197
197
  - lib/luo/helpers.rb
198
198
  - lib/luo/http_client.rb
199
+ - lib/luo/init_project.rb
200
+ - lib/luo/loader.rb
199
201
  - lib/luo/memory_history.rb
200
202
  - lib/luo/messages.rb
201
203
  - lib/luo/open_ai.rb
202
204
  - lib/luo/open_ai_agent_runner.rb
205
+ - lib/luo/projects/application.rb
206
+ - lib/luo/projects/env
207
+ - lib/luo/projects/init.rb
208
+ - lib/luo/projects/test.yml
209
+ - lib/luo/projects/time_agent.rb
210
+ - lib/luo/projects/weather_agent.rb
203
211
  - lib/luo/prompt_template.rb
204
212
  - lib/luo/prompts.rb
205
213
  - lib/luo/templates/luo_agent_input.md.erb
@@ -208,11 +216,13 @@ files:
208
216
  - lib/luo/templates/luo_commit.md.erb
209
217
  - lib/luo/templates/luo_xinghuo_agent_input.md.erb
210
218
  - lib/luo/templates/luo_xinghuo_agent_tool_input.md.erb
219
+ - lib/luo/templates/luo_xinghuo_response_error.md.erb
211
220
  - lib/luo/templates/prompt.demo.erb
212
221
  - lib/luo/version.rb
213
222
  - lib/luo/xinghuo.rb
214
223
  - lib/luo/xinghuo_agent_runner.rb
215
224
  - luo.gemspec
225
+ - sample_/marqo.rb
216
226
  - sig/luo.rbs
217
227
  - sig/luo/agent.rbs
218
228
  - sig/luo/agent_runner_base.rbs
@@ -228,6 +238,14 @@ files:
228
238
  - sig/luo/prompt_template.rbs
229
239
  - sig/luo/prompts.rbs
230
240
  - sig/luo/xinghuo.rbs
241
+ - templates/luo_agent_input.md.erb
242
+ - templates/luo_agent_system.md.erb
243
+ - templates/luo_agent_tool_input.md.erb
244
+ - templates/luo_commit.md.erb
245
+ - templates/luo_xinghuo_agent_input.md.erb
246
+ - templates/luo_xinghuo_agent_tool_input.md.erb
247
+ - templates/luo_xinghuo_response_error.md.erb
248
+ - templates/prompt.demo.erb
231
249
  homepage: https://github.com/mjason/luo
232
250
  licenses: []
233
251
  metadata: