luo 0.1.21 → 0.1.23

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: 0f0041ac90d5a47bfaa129bc877e38a350e0bdf757a6ea8d1da945ec2af83864
4
- data.tar.gz: fafb2c21415dbe6a5fbcf1ab21477e9ef580b3122ea35c3f333d2bb1a370555b
3
+ metadata.gz: 86dbccd9a0a001b6dde132666ad444d748417dd4eeedf1a9b150160a0609e93c
4
+ data.tar.gz: 638296ce0a26c8471b6a005e74b897221415aa392fb65f47585a75898801992e
5
5
  SHA512:
6
- metadata.gz: db9272f29f87859e3c364240b7ec586966ffe230ae951c56d6457f64c929e1eedacd4176cde01c6fc33489bea169bad26756d39640802ce41441c86629e02db5
7
- data.tar.gz: 6b279cdfb131e7042ec94ea9b12f09c7bf3012ad782d0cd8a84b98ec197470ef78bb03776c046f3ab54d7f6382cd4e5a3825288224ef6f80fc9ac8dd720a16b8
6
+ metadata.gz: 8838f0489d34c03b8927d60fb9d527ab0653d1ce00d35b2f8fd5020f4183d6abfda24e7ef8fa81517dff8b31410817d9e0b813ac5507bff4d1aaa63809583e2d
7
+ data.tar.gz: 045d43cc7a1f0d2bb41e68ea36d5e07ce2b5da84c46daadef05054fb9a73269bbbe13b458ac9242c53075ca42f37bc0717a37fe792165c87eca60da71c1d9596
@@ -0,0 +1,7 @@
1
+ <component name="ProjectDictionaryState">
2
+ <dictionary name="mj">
3
+ <words>
4
+ <w>marqo</w>
5
+ </words>
6
+ </dictionary>
7
+ </component>
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luo (0.1.19)
4
+ luo (0.1.22)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  dry-configurable (~> 1.0, >= 1.0.1)
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Luo
4
4
  module HttpClient
5
- def self.init_client
5
+ def self.init_client(options={})
6
6
  Module.new do
7
7
  define_method :client do
8
- @client ||= Faraday.new(self.class.config.host) { |conn|
8
+ @client ||= Faraday.new(self.class.config.host, options) { |conn|
9
9
  conn.request :authorization, 'Bearer', self.class.config.access_token if self.class.config.respond_to?(:access_token) && !self.class.config.access_token.nil?
10
10
  conn.request :retry, max: (self.class.config.retries || 3), interval: 0.05,
11
11
  interval_randomness: 0.5, backoff_factor: 2,
data/lib/luo/marqo.rb ADDED
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luo
4
+ class Marqo
5
+ include Configurable
6
+ setting :host, default: "http://localhost:8882"
7
+ setting :x_api_key, default: nil
8
+ setting :retries, default: ENV.fetch('OPENAI_REQUEST_RETRIES', 3).to_i
9
+
10
+ include HttpClient.init_client(headers: { 'X-API-KEY' => config.x_api_key })
11
+
12
+ SEARCH_PARAMS = Dry::Schema.Params do
13
+ required(:q).filled(:string)
14
+ optional(:limit).maybe(:integer)
15
+ optional(:offset).maybe(:integer)
16
+ optional(:filter).maybe(:string)
17
+ optional(:searchableAttributes).maybe(:array)
18
+ optional(:showHighlights).maybe(:bool)
19
+ optional(:searchMethod).value(included_in?: %w[TENSOR LEXICAL])
20
+ optional(:attributesToRetrieve).maybe(:array)
21
+ optional(:reRanker).maybe(:string)
22
+ optional(:boost).maybe(:hash)
23
+ optional(:image_download_headers).maybe(:hash)
24
+ optional(:context).maybe(:hash)
25
+ optional(:scoreModifiers).maybe(:hash)
26
+ optional(:modelAuth).maybe(:hash)
27
+ end
28
+
29
+ def index(index_name)
30
+ @index_name = index_name
31
+ self
32
+ end
33
+
34
+ ##
35
+ # 添加文档到向量数据库
36
+ def add_documents(hash, non_tensor_fields: nil)
37
+ client.post("/indexes/#{@index_name}/documents") do |req|
38
+ req.params[:non_tensor_fields] = non_tensor_fields unless non_tensor_fields.nil?
39
+ req.body = hash
40
+ end
41
+ end
42
+
43
+ def refresh
44
+ client.post("/indexes/#{@index_name}/refresh")
45
+ end
46
+
47
+ def search(params)
48
+ params = SEARCH_PARAMS.call(params)
49
+ return params.errors unless params.success?
50
+ client.post("/indexes/#{@index_name}/search", params.to_h)
51
+ end
52
+
53
+ def delete(id_or_ids)
54
+ id_or_ids = [id_or_ids] if id_or_ids.is_a?(String)
55
+ client.post("/indexes/#{@index_name}/documents/delete-batch", id_or_ids)
56
+ end
57
+
58
+ def remove
59
+ client.delete("/indexes/#{@index_name}")
60
+ end
61
+ end
62
+ end
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.21"
4
+ VERSION = "0.1.23"
5
5
  end
data/lib/luo.rb CHANGED
@@ -14,6 +14,7 @@ require 'yaml'
14
14
  require 'tty-markdown'
15
15
  require 'fileutils'
16
16
  require 'dry-initializer'
17
+ require 'uri'
17
18
 
18
19
  require "zeitwerk"
19
20
  loader = Zeitwerk::Loader.for_gem
data/luo.ps1 ADDED
@@ -0,0 +1,31 @@
1
+ function Get-ScriptRoot {
2
+ $result = $PSScriptRoot
3
+ if ($result.Length -eq 0) {
4
+ $result = split-path -parent $MyInvocation.MyCommand.Definition
5
+ }
6
+ return $result
7
+ }
8
+
9
+ function Set-LuoPath {
10
+ $test_path = ([System.Environment]::GetEnvironmentVariable('PATH') | findstr (Get-ScriptRoot)).Length
11
+ if ($test_path -eq 0) {
12
+ [System.Environment]::SetEnvironmentVariable('PATH', "${Env:PATH};" + (Get-ScriptRoot))
13
+ $Env:PATH += ";" + (Get-ScriptRoot)
14
+ Write-Host "=== PATH set for Luo ==="
15
+ }
16
+ }
17
+
18
+ Set-LuoPath
19
+
20
+ if ($args[0] -eq "update") {
21
+ Write-Host "Pulling the latest Docker image..."
22
+ docker pull ghcr.io/mjason/luo:latest
23
+ }
24
+
25
+ Write-Host "Running the Docker container..."
26
+
27
+ docker run --rm -it `
28
+ -p 8888:8888 `
29
+ -v "${PWD}:/workdir" `
30
+ ghcr.io/mjason/luo:latest `
31
+ $args
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.21
4
+ version: 0.1.23
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-12 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -175,6 +175,7 @@ extensions: []
175
175
  extra_rdoc_files: []
176
176
  files:
177
177
  - ".idea/.gitignore"
178
+ - ".idea/dictionaries/mj.xml"
178
179
  - ".idea/inspectionProfiles/Project_Default.xml"
179
180
  - ".idea/luo.iml"
180
181
  - ".idea/misc.xml"
@@ -201,6 +202,7 @@ files:
201
202
  - lib/luo/http_client.rb
202
203
  - lib/luo/init_project.rb
203
204
  - lib/luo/loader.rb
205
+ - lib/luo/marqo.rb
204
206
  - lib/luo/memory_history.rb
205
207
  - lib/luo/messages.rb
206
208
  - lib/luo/open_ai.rb
@@ -233,6 +235,7 @@ files:
233
235
  - luo
234
236
  - luo.gemspec
235
237
  - luo.ipynb
238
+ - luo.ps1
236
239
  - sig/luo.rbs
237
240
  - sig/luo/agent.rbs
238
241
  - sig/luo/agent_runner_base.rbs