omniai-openai 1.6.2 → 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: 99efbb2cd49fcc32c8c4934ad0081b18b0e6eba09056b5418e9040d1c62a649a
4
- data.tar.gz: 44bebce8f96c0203a3a9a64d5f1661e5c247dbb1030eff85c75cdc641fc72534
3
+ metadata.gz: 41461329b48f40e24c8d2f69a58ece1a8e07726c7d45deda20c83fc58d6a1a54
4
+ data.tar.gz: 6699b15afe94e512ddec9c1919d74b121a2044f5d50c390fd7899f4498b7cf19
5
5
  SHA512:
6
- metadata.gz: 22ca0c4580a73126a7e5fee444b52da77d4dbbac6442d04d9ff848bc0f1b5eb00acc249f9db6671fdf0474ec273adf0cc57f5edc8ca0e90792686b40e574a692
7
- data.tar.gz: 49ab6aec6a2d795c052a9cd3a546061028367e5d18a0e60281525c02d6e9a62e6fad12733d914c4bf2326c154738a7cb8857611dbf945986f0db49924649fceb
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
+ ```
@@ -16,6 +16,7 @@ module OmniAI
16
16
 
17
17
  module Model
18
18
  GPT_4O = 'gpt-4o'
19
+ GPT_4O_MINI = 'gpt-4o-mini'
19
20
  GPT_4 = 'gpt-4'
20
21
  GPT_4_TURBO = 'gpt-4-turbo'
21
22
  GPT_3_5_TURBO = 'gpt-3.5-turbo'
@@ -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.2'
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.2
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