luo 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/luo/version.rb +1 -1
- data/lib/luo/xinghuo.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4569a6fd6ae87797597f59bc73f8c1b6ac8d805f3410ecc716ffc7e1ddf428c1
|
4
|
+
data.tar.gz: 9695305bfe27cec9708fbc6fea8d1b000ff8450b17befdaa1a0c822da815f157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 281fca6621c8aaccc3c21559c4a0e8ef80738fdf648bb5db68fd639b3692bb4a5f5890c5ad20b94dab9159ae27a5569b99c1a3cf1408603af5894be76f315586
|
7
|
+
data.tar.gz: 80a2b4894e507b1874e21ba0928bc8b5c16cc88fda9870e5ee2c8b333dd1dcc0e2d80c3d5f954ce6abf8f35b56f93127d1aad1ebca34278c7d7427241429c904
|
data/Gemfile.lock
CHANGED
data/lib/luo/version.rb
CHANGED
data/lib/luo/xinghuo.rb
CHANGED
@@ -26,12 +26,31 @@ module Luo
|
|
26
26
|
optional(:stream).maybe(:bool)
|
27
27
|
end
|
28
28
|
|
29
|
+
EMBEDDING_PARAMS = Dry::Schema.Params do
|
30
|
+
required(:input).filled(:string)
|
31
|
+
end
|
32
|
+
|
29
33
|
# header uid max length is 32 todo
|
30
34
|
|
31
35
|
def request_chat(params, &block)
|
32
36
|
client.post('/v1/spark/completions', params.to_h, &block)
|
33
37
|
end
|
34
38
|
|
39
|
+
def embedding(params)
|
40
|
+
client.post('/v1/embedding', params.to_h)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_embedding(text, model: 'text-embedding-ada-002')
|
44
|
+
params = EMBEDDING_PARAMS.call(input: text)
|
45
|
+
return params.errors unless params.success?
|
46
|
+
response = embedding(params)
|
47
|
+
if response.success?
|
48
|
+
response.body.dig("data")
|
49
|
+
else
|
50
|
+
raise "create_embeddings failed: #{response.body}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
35
54
|
def chat(messages, random_threshold: nil, &block)
|
36
55
|
if messages.is_a?(Messages)
|
37
56
|
messages = messages.to_a
|