omniai-openai 1.6.3 → 1.7.0

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: dceac1ba096564c04a795101feeebde7e5014b901d6cb1dd479cc7701d38bd3c
4
- data.tar.gz: a1ef0a834eec86b0a5072811580259700b704abadedd29965b649b127f2aba50
3
+ metadata.gz: 41461329b48f40e24c8d2f69a58ece1a8e07726c7d45deda20c83fc58d6a1a54
4
+ data.tar.gz: 6699b15afe94e512ddec9c1919d74b121a2044f5d50c390fd7899f4498b7cf19
5
5
  SHA512:
6
- metadata.gz: 51e5373e55921c3768a1d245fd9e9b14b2c0e7a842088504ce51e9b23627df9df640b4fcbc633f34f89a53bc0079d4516fed4074c0ab445be1fb67d8ff008a49
7
- data.tar.gz: aebd0db9486e9df3ae9370e6c089bdd211f745bcb6146e457c80417325fc4004492050dcefa667284963379915030ac20c84dfeb8e831ce135542d2aa2a7eaec
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
+ ```
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.6.3'
5
+ VERSION = '1.7.0'
6
6
  end
7
7
  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.6.3
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-07-18 00:00:00.000000000 Z
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