omniai-openai 1.6.3 → 1.7.0
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/README.md +9 -0
- data/lib/omniai/openai/client.rb +8 -0
- data/lib/omniai/openai/embed.rb +40 -0
- data/lib/omniai/openai/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41461329b48f40e24c8d2f69a58ece1a8e07726c7d45deda20c83fc58d6a1a54
|
4
|
+
data.tar.gz: 6699b15afe94e512ddec9c1919d74b121a2044f5d50c390fd7899f4498b7cf19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c30e7ded2ee30804f3cc6b9d1dcb2ca62c52d7454fe722caedf518d96f019183a73265d81803a526453b3b6044c210260b6c0ef4c8e0909fead982ebe59ae3bb
|
7
|
+
data.tar.gz: f99a44a88ad1c564101cb9caff9d57e33214d93c5716cad13ab0fabc3792bf3196f693ec3783eaeadfef121db785ff5d38d1c7ebd6b32d5b2f1150c10ec2687f
|
data/README.md
CHANGED
@@ -441,3 +441,12 @@ run.status # 'cancelled' / 'failed' / 'completed' / 'expired'
|
|
441
441
|
thread = client.threads.find(id: 'thread_...')
|
442
442
|
run = thread.runs.cancel!(id: 'run_...')
|
443
443
|
```
|
444
|
+
|
445
|
+
### Embed
|
446
|
+
|
447
|
+
Text can be converted into a vector embedding for similarity comparison usage via:
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
response = client.embed('The quick brown fox jumps over a lazy dog.')
|
451
|
+
response.embedding # [0.0, ...]
|
452
|
+
```
|
data/lib/omniai/openai/client.rb
CHANGED
@@ -77,6 +77,14 @@ module OmniAI
|
|
77
77
|
Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self, &)
|
78
78
|
end
|
79
79
|
|
80
|
+
# @raise [OmniAI::Error]
|
81
|
+
#
|
82
|
+
# @param input [String, Array<String>, Array<Integer>] required
|
83
|
+
# @param model [String] optional
|
84
|
+
def embed(input, model: Embed::DEFAULT_MODEL)
|
85
|
+
Embed.process!(input, model:, client: self)
|
86
|
+
end
|
87
|
+
|
80
88
|
# @raise [OmniAI::Error]
|
81
89
|
#
|
82
90
|
# @param path [String]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
module OpenAI
|
5
|
+
# An OpenAI embed implementation.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# input = "..."
|
10
|
+
# response = OmniAI::OpenAI::Embed.process!(input, client: client)
|
11
|
+
# response.embedding [0.0, ...]
|
12
|
+
class Embed < OmniAI::Embed
|
13
|
+
module Model
|
14
|
+
SMALL = 'text-embedding-3-small'
|
15
|
+
LARGE = 'text-embedding-3-large'
|
16
|
+
ADA = 'text-embedding-ada-002'
|
17
|
+
end
|
18
|
+
|
19
|
+
DEFAULT_MODEL = Model::LARGE
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
# @return [Hash]
|
24
|
+
def payload
|
25
|
+
{ model: @model, input: arrayify(@input) }
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
def path
|
30
|
+
"/#{OmniAI::OpenAI::Client::VERSION}/embeddings"
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [Object] value
|
34
|
+
# @return [Array]
|
35
|
+
def arrayify(value)
|
36
|
+
value.is_a?(Array) ? value : [value]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/omniai/openai/chat.rb
|
68
68
|
- lib/omniai/openai/client.rb
|
69
69
|
- lib/omniai/openai/config.rb
|
70
|
+
- lib/omniai/openai/embed.rb
|
70
71
|
- lib/omniai/openai/file.rb
|
71
72
|
- lib/omniai/openai/files.rb
|
72
73
|
- lib/omniai/openai/speak.rb
|