luo 0.1.8 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +8 -0
- data/Gemfile.lock +1 -1
- data/README.zh.md +5 -0
- data/lib/luo/agent.rb +4 -2
- data/lib/luo/aiui.rb +1 -1
- data/lib/luo/cli.rb +10 -0
- data/lib/luo/open_ai.rb +2 -2
- data/lib/luo/version.rb +1 -1
- data/lib/luo/xinghuo.rb +2 -2
- data/lib/luo.rb +1 -0
- data/luo.gemspec +0 -1
- data/sig/luo/agent.rbs +4 -1
- data/sig/luo/agent_runner_context.rbs +3 -0
- data/sig/luo/client.rbs +5 -0
- data/sig/luo/open_ai.rbs +2 -0
- metadata +3 -2
- data/sample_/marqo.rb +0 -98
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1830a5e907eb9c92fe84162093cc7c46fa7f1970b07c58b120114dba73499e47
|
4
|
+
data.tar.gz: 609ec33cce3365b956494f1446983924a03c5341ed5be8d350575d3303a250a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef9266fbe51fa277369abbe012e531cd07df5b6141af538fb4f934fc591821530440d2ff58bef00accd7e9827bfbc24858f503a616bd765e24a2aea31e9e7bda
|
7
|
+
data.tar.gz: c2bf5ddf9f16d7640bd52c35f259fd86d4211f1a995890e3c2151cf2a097b8b54bb060be524b3d91bbd0d61fbf3cfe082366d2e6ad48b5c63d46a3a2aeceb0a4
|
data/Dockerfile
ADDED
data/Gemfile.lock
CHANGED
data/README.zh.md
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
是一款基于大模型的开发框架(面向产品经理),当前支持大模型提供商有: OpenAI、星火大模型。通过DSL能够快速创作并且测试大模型的效果。
|
3
3
|
|
4
4
|
## 安装
|
5
|
+
|
6
|
+
###
|
5
7
|
```
|
6
8
|
gem install luo
|
7
9
|
```
|
8
10
|
|
11
|
+
###
|
12
|
+
docker run --rm -it -v "$PWD:/workdir" luo_cli_cli -v
|
13
|
+
|
9
14
|
## 环境变量说明
|
10
15
|
```Bash
|
11
16
|
OPENAI_ACCESS_TOKEN= # OpenAI的访问令牌
|
data/lib/luo/agent.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Luo
|
4
4
|
class Agent
|
5
|
+
extend Dry::Initializer
|
6
|
+
|
5
7
|
attr_reader :context, :action_input, :client
|
6
8
|
def initialize(context: nil, action_input: nil, client: nil)
|
7
9
|
@context = context
|
@@ -27,7 +29,7 @@ module Luo
|
|
27
29
|
result = instance_eval(&block)
|
28
30
|
if result.nil?
|
29
31
|
messages = context.messages.to_a[0...-1] + [{role: :user, content: context.user_input}]
|
30
|
-
context.final_result = client
|
32
|
+
context.final_result = client&.chat(messages)
|
31
33
|
else
|
32
34
|
context.final_result = result
|
33
35
|
end
|
@@ -35,7 +37,7 @@ module Luo
|
|
35
37
|
end
|
36
38
|
|
37
39
|
alias_method :on_call_with_fallback, :on_call_with_final_result
|
38
|
-
|
40
|
+
|
39
41
|
def self.create_parameter_method(method_name, not_provided = Object.new, &block)
|
40
42
|
define_method(method_name.to_sym) do |content = not_provided|
|
41
43
|
if content === not_provided
|
data/lib/luo/aiui.rb
CHANGED
data/lib/luo/cli.rb
CHANGED
@@ -33,9 +33,19 @@ module Luo
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
class Run < Dry::CLI::Command
|
37
|
+
desc "Run Luo"
|
38
|
+
|
39
|
+
def call(*)
|
40
|
+
exec "ruby application.rb"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
register "version", Version, aliases: %w[v -v --version]
|
37
45
|
register "commit", Commit, aliases: ["c"]
|
38
46
|
register "init", Init, aliases: ["i"]
|
47
|
+
register "run", Run, aliases: ["r"]
|
48
|
+
|
39
49
|
end
|
40
50
|
|
41
51
|
end
|
data/lib/luo/open_ai.rb
CHANGED
@@ -48,13 +48,13 @@ module Luo
|
|
48
48
|
embeddings(params).body.dig("data").map { |v| v["embedding"] }
|
49
49
|
end
|
50
50
|
|
51
|
-
def chat(messages)
|
51
|
+
def chat(messages, temperature: nil)
|
52
52
|
if messages.is_a?(Messages)
|
53
53
|
messages = messages.to_a
|
54
54
|
end
|
55
55
|
params = PARAMS.call(
|
56
56
|
model: 'gpt-3.5-turbo',
|
57
|
-
temperature: config.temperature,
|
57
|
+
temperature: temperature || config.temperature,
|
58
58
|
messages: messages
|
59
59
|
)
|
60
60
|
return params.errors unless params.success?
|
data/lib/luo/version.rb
CHANGED
data/lib/luo/xinghuo.rb
CHANGED
@@ -30,7 +30,7 @@ module Luo
|
|
30
30
|
client.post('/external/ls_log/xf_completions', params.to_h)
|
31
31
|
end
|
32
32
|
|
33
|
-
def chat(messages)
|
33
|
+
def chat(messages, temperature: nil)
|
34
34
|
if messages.is_a?(Messages)
|
35
35
|
messages = messages.to_a
|
36
36
|
end
|
@@ -39,7 +39,7 @@ module Luo
|
|
39
39
|
domain: config.domain,
|
40
40
|
messages: messages,
|
41
41
|
max_tokens: config.max_tokens,
|
42
|
-
random_threshold: config.temperature,
|
42
|
+
random_threshold: temperature || config.temperature,
|
43
43
|
uid: config.uid.call
|
44
44
|
)
|
45
45
|
return params.errors unless params.success?
|
data/lib/luo.rb
CHANGED
data/luo.gemspec
CHANGED
@@ -37,7 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency 'dry-configurable', '~> 1.0', '>= 1.0.1'
|
38
38
|
spec.add_dependency 'dry-cli', '~> 1.0'
|
39
39
|
spec.add_dependency 'tty-markdown', '~> 0.7.2'
|
40
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
41
40
|
|
42
41
|
spec.add_development_dependency "rspec", '~> 3.12'
|
43
42
|
|
data/sig/luo/agent.rbs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Luo
|
2
2
|
class Agent
|
3
3
|
@action_input: untyped
|
4
|
-
@context: AgentRunnerContext
|
4
|
+
@context: AgentRunnerContext?
|
5
5
|
|
6
6
|
attr_reader self.agent_desc: String
|
7
7
|
attr_reader self.agent_name: String
|
@@ -9,6 +9,7 @@ module Luo
|
|
9
9
|
def self.on_call_with_final_result: -> untyped
|
10
10
|
|
11
11
|
attr_reader action_input: untyped
|
12
|
+
attr_reader client: _Client?
|
12
13
|
attr_reader context: AgentRunnerContext
|
13
14
|
|
14
15
|
def initialize: (AgentRunnerContext) -> untyped
|
@@ -19,5 +20,7 @@ module Luo
|
|
19
20
|
|
20
21
|
attr_reader input: String
|
21
22
|
attr_reader row_input: String?
|
23
|
+
|
24
|
+
def call: -> untyped
|
22
25
|
end
|
23
26
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Luo
|
2
2
|
class AgentRunnerContext
|
3
|
+
@client: untyped
|
3
4
|
@histories: MemoryHistory
|
4
5
|
|
5
6
|
@running_agents: Array[Agent]
|
@@ -14,6 +15,8 @@ module Luo
|
|
14
15
|
|
15
16
|
def client: -> untyped
|
16
17
|
|
18
|
+
def client=: -> untyped
|
19
|
+
|
17
20
|
def have_running_agents: -> Set[Agent]
|
18
21
|
|
19
22
|
def histories: -> MemoryHistory
|
data/sig/luo/client.rbs
ADDED
data/sig/luo/open_ai.rbs
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MJ
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- ".idea/modules.xml"
|
182
182
|
- ".idea/vcs.xml"
|
183
183
|
- ".rspec"
|
184
|
+
- Dockerfile
|
184
185
|
- Gemfile
|
185
186
|
- Gemfile.lock
|
186
187
|
- README.md
|
@@ -222,12 +223,12 @@ files:
|
|
222
223
|
- lib/luo/xinghuo.rb
|
223
224
|
- lib/luo/xinghuo_agent_runner.rb
|
224
225
|
- luo.gemspec
|
225
|
-
- sample_/marqo.rb
|
226
226
|
- sig/luo.rbs
|
227
227
|
- sig/luo/agent.rbs
|
228
228
|
- sig/luo/agent_runner_base.rbs
|
229
229
|
- sig/luo/agent_runner_context.rbs
|
230
230
|
- sig/luo/aiui.rbs
|
231
|
+
- sig/luo/client.rbs
|
231
232
|
- sig/luo/configurable.rbs
|
232
233
|
- sig/luo/env.rbs
|
233
234
|
- sig/luo/helpers.rbs
|
data/sample_/marqo.rb
DELETED
@@ -1,98 +0,0 @@
|
|
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
|