openai.rb 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a36b209f6540c340ca79cfa0e245d373db12c20b1d33f4fdd418c56bfa33961d
4
- data.tar.gz: a30abc667ce81ffa59ec3a65c260193554cff814d03805921f745ec9140f2942
3
+ metadata.gz: 7504d7c806b7add3642cac52f2dede494dfd4b7ed13b4990001e7dbcf6fc3229
4
+ data.tar.gz: a128b968928677a1153fb59dae4a25f4138ca5517579183b9c40032ff5eb607b
5
5
  SHA512:
6
- metadata.gz: 0aacdfd81c1a7bbd88c2fceed1e9c3aaf38f7cc948467b45a2c3e607d5eaf6bafa084ba2a8accd08aa7430c67b08df4da810ef2e07349359b601258c9f14c550
7
- data.tar.gz: c6c89ccafded9440f5a472afbcee736307e7f2daa4f82b2028515cec86cd22a224e3006bd1d858c7faa7b495e7d889691c4af76ea4720972b50022890b01d18a
6
+ metadata.gz: 1d1fa68746301c4ebe256e2c97f66f3616bb34e082df040feead4ce9281569dc804c2e0bc32a78e720a3bad5fe0646fbef263699130823424dc869f34615e6db
7
+ data.tar.gz: b1f24c37e0fe70344c4eac77e9943d84740e33544a8cd1eb934f167da737a25a14682aa7297327258d8f5947fc668423a45310bcb7120930fddae0e31ca94451
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  http_version: ['~> 4.4', '~> 5.1']
11
- ruby_version: ['2.7.8']
11
+ ruby_version: ['3.2.2']
12
12
 
13
13
  steps:
14
14
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
1
4
  Metrics/AbcSize:
2
5
  Enabled: false
3
6
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.7
1
+ 3.2.2
data/Gemfile CHANGED
@@ -15,8 +15,8 @@ group :lint do
15
15
  gem 'rubocop-rspec', '~> 2.11.1'
16
16
  end
17
17
 
18
- gem 'pry', '~> 0.13.1'
19
- gem 'pry-byebug', '3.9.0'
18
+ gem 'pry'
19
+ gem 'pry-byebug'
20
20
 
21
21
  gem 'dotenv', '~> 2.8'
22
22
 
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ PATH
8
8
  http (>= 4.4, < 6.0)
9
9
  ice_nine (~> 0.11.x)
10
10
  memoizable (~> 0.4.2)
11
- tiktoken_ruby (~> 0.0.3)
11
+ tiktoken_ruby (~> 0.0.6)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  adamantium (0.2.0)
18
18
  ice_nine (~> 0.11.0)
19
19
  memoizable (~> 0.4.0)
20
- addressable (2.8.2)
20
+ addressable (2.8.5)
21
21
  public_suffix (>= 2.0.2, < 6.0)
22
22
  anima (0.3.2)
23
23
  abstract_type (~> 0.0.7)
@@ -34,7 +34,7 @@ GEM
34
34
  unf (>= 0.0.5, < 1.0.0)
35
35
  dotenv (2.8.1)
36
36
  equalizer (0.0.11)
37
- ffi (1.15.5)
37
+ ffi (1.16.3)
38
38
  ffi-compiler (1.0.1)
39
39
  ffi (>= 1.0.0)
40
40
  rake
@@ -53,34 +53,36 @@ GEM
53
53
  memoizable (0.4.2)
54
54
  thread_safe (~> 0.3, >= 0.3.1)
55
55
  method_source (1.0.0)
56
- parallel (1.22.1)
57
- parser (3.2.2.0)
56
+ parallel (1.23.0)
57
+ parser (3.2.2.4)
58
58
  ast (~> 2.4.1)
59
- pry (0.13.1)
59
+ racc
60
+ pry (0.14.2)
60
61
  coderay (~> 1.1)
61
62
  method_source (~> 1.0)
62
- pry-byebug (3.9.0)
63
+ pry-byebug (3.10.1)
63
64
  byebug (~> 11.0)
64
- pry (~> 0.13.0)
65
- public_suffix (5.0.1)
65
+ pry (>= 0.13, < 0.15)
66
+ public_suffix (5.0.3)
67
+ racc (1.7.1)
66
68
  rainbow (3.1.1)
67
69
  rake (13.0.6)
68
- rb_sys (0.9.70)
69
- regexp_parser (2.7.0)
70
- rexml (3.2.5)
70
+ rb_sys (0.9.82)
71
+ regexp_parser (2.8.2)
72
+ rexml (3.2.6)
71
73
  rspec (3.12.0)
72
74
  rspec-core (~> 3.12.0)
73
75
  rspec-expectations (~> 3.12.0)
74
76
  rspec-mocks (~> 3.12.0)
75
- rspec-core (3.12.1)
77
+ rspec-core (3.12.2)
76
78
  rspec-support (~> 3.12.0)
77
- rspec-expectations (3.12.2)
79
+ rspec-expectations (3.12.3)
78
80
  diff-lcs (>= 1.2.0, < 2.0)
79
81
  rspec-support (~> 3.12.0)
80
- rspec-mocks (3.12.5)
82
+ rspec-mocks (3.12.6)
81
83
  diff-lcs (>= 1.2.0, < 2.0)
82
84
  rspec-support (~> 3.12.0)
83
- rspec-support (3.12.0)
85
+ rspec-support (3.12.1)
84
86
  rubocop (1.31.2)
85
87
  json (~> 2.3)
86
88
  parallel (~> 1.10)
@@ -91,18 +93,20 @@ GEM
91
93
  rubocop-ast (>= 1.18.0, < 2.0)
92
94
  ruby-progressbar (~> 1.7)
93
95
  unicode-display_width (>= 1.4.0, < 3.0)
94
- rubocop-ast (1.28.0)
96
+ rubocop-ast (1.29.0)
95
97
  parser (>= 3.2.1.0)
96
98
  rubocop-rspec (2.11.1)
97
99
  rubocop (~> 1.19)
98
100
  ruby-progressbar (1.13.0)
99
101
  slop (4.10.1)
100
102
  thread_safe (0.3.6)
101
- tiktoken_ruby (0.0.4)
103
+ tiktoken_ruby (0.0.6)
104
+ rb_sys (~> 0.9.68)
105
+ tiktoken_ruby (0.0.6-arm64-darwin)
102
106
  unf (0.1.4)
103
107
  unf_ext
104
108
  unf_ext (0.0.8.2)
105
- unicode-display_width (2.4.2)
109
+ unicode-display_width (2.5.0)
106
110
 
107
111
  PLATFORMS
108
112
  arm64-darwin-21
@@ -112,8 +116,8 @@ DEPENDENCIES
112
116
  dotenv (~> 2.8)
113
117
  http (~> 4.4)
114
118
  openai.rb!
115
- pry (~> 0.13.1)
116
- pry-byebug (= 3.9.0)
119
+ pry
120
+ pry-byebug
117
121
  rb_sys (~> 0.9.70)
118
122
  rspec (~> 3.12)
119
123
  rubocop (~> 1.31.1)
@@ -121,7 +125,7 @@ DEPENDENCIES
121
125
  slop (~> 4.10)
122
126
 
123
127
  RUBY VERSION
124
- ruby 2.7.7p221
128
+ ruby 3.2.2p53
125
129
 
126
130
  BUNDLED WITH
127
131
  2.3.9
@@ -6,7 +6,7 @@ class OpenAI
6
6
  include Concord.new(:client, :cache)
7
7
 
8
8
  def get(route)
9
- read_cache_or_apply(verb: :get, route: route) do
9
+ read_cache_or_apply(verb: :get, route:) do
10
10
  client.get(route)
11
11
  end
12
12
  end
@@ -18,13 +18,13 @@ class OpenAI
18
18
  end
19
19
 
20
20
  def post(route, **body)
21
- read_cache_or_apply(verb: :post, route: route, body: body, format: :json) do
21
+ read_cache_or_apply(verb: :post, route:, body:, format: :json) do
22
22
  client.post(route, **body)
23
23
  end
24
24
  end
25
25
 
26
26
  def post_form_multipart(route, **body)
27
- read_cache_or_apply(verb: :post, route: route, body: body, format: :form) do
27
+ read_cache_or_apply(verb: :post, route:, body:, format: :form) do
28
28
  client.post_form_multipart(route, **body)
29
29
  end
30
30
  end
@@ -49,11 +49,11 @@ class OpenAI
49
49
 
50
50
  def cache_target(verb:, route:, body: nil, format: nil)
51
51
  Target.new(
52
- verb: verb,
52
+ verb:,
53
53
  api_key: client.api_key,
54
- route: route,
55
- body: body,
56
- format: format
54
+ route:,
55
+ body:,
56
+ format:
57
57
  )
58
58
  end
59
59
 
@@ -31,7 +31,7 @@ class OpenAI
31
31
  chunk_response_type: full_response_type,
32
32
  **kwargs
33
33
  )
34
- payload = kwargs.merge(stream: stream)
34
+ payload = kwargs.merge(stream:)
35
35
 
36
36
  raise 'Streaming responses require a block' if stream && !block_given?
37
37
  raise 'Non-streaming responses do not support blocks' if !stream && block_given?
@@ -54,7 +54,7 @@ class OpenAI
54
54
  def create(model:, **kwargs, &block)
55
55
  create_and_maybe_stream(
56
56
  '/v1/completions',
57
- model: model,
57
+ model:,
58
58
  full_response_type: Response::Completion,
59
59
  **kwargs,
60
60
  &block
@@ -66,8 +66,8 @@ class OpenAI
66
66
  def create(model:, messages:, **kwargs, &block)
67
67
  create_and_maybe_stream(
68
68
  '/v1/chat/completions',
69
- model: model,
70
- messages: messages,
69
+ model:,
70
+ messages:,
71
71
  full_response_type: Response::ChatCompletion,
72
72
  chunk_response_type: Response::ChatCompletionChunk,
73
73
  **kwargs,
@@ -79,7 +79,7 @@ class OpenAI
79
79
  class Embedding < Resource
80
80
  def create(model:, input:, **kwargs)
81
81
  Response::Embedding.from_json(
82
- post('/v1/embeddings', model: model, input: input, **kwargs)
82
+ post('/v1/embeddings', model:, input:, **kwargs)
83
83
  )
84
84
  end
85
85
  end
@@ -99,7 +99,7 @@ class OpenAI
99
99
  class Moderation < Resource
100
100
  def create(input:, model:)
101
101
  Response::Moderation.from_json(
102
- post('/v1/moderations', input: input, model: model)
102
+ post('/v1/moderations', input:, model:)
103
103
  )
104
104
  end
105
105
  end
@@ -107,7 +107,7 @@ class OpenAI
107
107
  class Edit < Resource
108
108
  def create(model:, instruction:, **kwargs)
109
109
  Response::Edit.from_json(
110
- post('/v1/edits', model: model, instruction: instruction, **kwargs)
110
+ post('/v1/edits', model:, instruction:, **kwargs)
111
111
  )
112
112
  end
113
113
  end
@@ -115,7 +115,7 @@ class OpenAI
115
115
  class File < Resource
116
116
  def create(file:, purpose:)
117
117
  Response::File.from_json(
118
- post_form_multipart('/v1/files', file: form_file(file), purpose: purpose)
118
+ post_form_multipart('/v1/files', file: form_file(file), purpose:)
119
119
  )
120
120
  end
121
121
 
@@ -151,7 +151,7 @@ class OpenAI
151
151
 
152
152
  def create(training_file:, **kwargs)
153
153
  Response::FineTune.from_json(
154
- post('/v1/fine-tunes', training_file: training_file, **kwargs)
154
+ post('/v1/fine-tunes', training_file:, **kwargs)
155
155
  )
156
156
  end
157
157
 
@@ -177,23 +177,20 @@ class OpenAI
177
177
  class Image < Resource
178
178
  def create(prompt:, **kwargs)
179
179
  Response::ImageGeneration.from_json(
180
- post('/v1/images/generations', prompt: prompt, **kwargs)
180
+ post('/v1/images/generations', prompt:, **kwargs)
181
181
  )
182
182
  end
183
183
 
184
184
  def create_variation(image:, **kwargs)
185
185
  Response::ImageVariation.from_json(
186
- post_form_multipart('/v1/images/variations', {
187
- image: form_file(image),
188
- **kwargs
189
- })
186
+ post_form_multipart('/v1/images/variations', image: form_file(image), **kwargs)
190
187
  )
191
188
  end
192
189
 
193
190
  def edit(image:, prompt:, mask: nil, **kwargs)
194
191
  params = {
195
192
  image: form_file(image),
196
- prompt: prompt,
193
+ prompt:,
197
194
  **kwargs
198
195
  }
199
196
 
@@ -211,7 +208,7 @@ class OpenAI
211
208
  post_form_multipart(
212
209
  '/v1/audio/transcriptions',
213
210
  file: form_file(file),
214
- model: model,
211
+ model:,
215
212
  **kwargs
216
213
  )
217
214
  )
@@ -222,7 +219,7 @@ class OpenAI
222
219
  post_form_multipart(
223
220
  '/v1/audio/translations',
224
221
  file: form_file(file),
225
- model: model,
222
+ model:,
226
223
  **kwargs
227
224
  )
228
225
  )
@@ -41,7 +41,7 @@ class OpenAI
41
41
  register_field(name)
42
42
 
43
43
  define_method(name) do
44
- field(path, wrapper: wrapper)
44
+ field(path, wrapper:)
45
45
  end
46
46
  end
47
47
 
@@ -49,7 +49,7 @@ class OpenAI
49
49
  register_field(name)
50
50
 
51
51
  define_method(name) do
52
- optional_field(path, wrapper: wrapper)
52
+ optional_field(path, wrapper:)
53
53
  end
54
54
  end
55
55
 
data/lib/openai/chat.rb CHANGED
@@ -5,8 +5,9 @@ class OpenAI
5
5
  include Anima.new(:messages, :api_settings, :openai, :config)
6
6
  using Util::Colorize
7
7
 
8
- def initialize(messages:, settings: {}, config: Config.create, **kwargs)
9
- messages = messages.map do |msg|
8
+ def initialize(opts)
9
+ opts = { settings: {}.freeze, config: Config.create }.merge(opts)
10
+ messages = opts.fetch(:messages).map do |msg|
10
11
  if msg.is_a?(Hash)
11
12
  Message.new(msg)
12
13
  else
@@ -15,10 +16,10 @@ class OpenAI
15
16
  end
16
17
 
17
18
  super(
18
- messages: messages,
19
- api_settings: settings,
20
- config: config,
21
- **kwargs
19
+ messages:,
20
+ api_settings: opts.fetch(:settings),
21
+ config: opts.fetch(:config),
22
+ openai: opts.fetch(:openai)
22
23
  )
23
24
  end
24
25
 
@@ -90,7 +91,7 @@ class OpenAI
90
91
  end
91
92
 
92
93
  def add_message(role, content)
93
- with_message(role: role, content: content)
94
+ with_message(role:, content:)
94
95
  end
95
96
 
96
97
  def with_message(message)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OpenAI
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
data/lib/openai.rb CHANGED
@@ -64,7 +64,7 @@ class OpenAI
64
64
  def chat(model:, history: [], **kwargs)
65
65
  Chat.new(
66
66
  openai: self,
67
- settings: kwargs.merge(model: model),
67
+ settings: kwargs.merge(model:),
68
68
  messages: history
69
69
  )
70
70
  end
data/openai.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = %w[lib]
17
17
  spec.executables = []
18
18
 
19
- spec.required_ruby_version = '>= 2.7'
19
+ spec.required_ruby_version = '>= 3.2'
20
20
 
21
21
  spec.add_dependency 'abstract_type', '~> 0.0.7'
22
22
  spec.add_dependency 'anima', '~> 0.3'
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'http', '>= 4.4', '< 6.0'
25
25
  spec.add_dependency 'ice_nine', '~> 0.11.x'
26
26
  spec.add_dependency 'memoizable', '~> 0.4.2'
27
- spec.add_dependency 'tiktoken_ruby', '~> 0.0.3'
27
+ spec.add_dependency 'tiktoken_ruby', '~> 0.0.6'
28
+ spec.metadata['rubygems_mfa_required'] = 'true'
28
29
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.shared_context 'an API Resource' do
4
- let(:api) { OpenAI::API.new(api_client) }
5
- let(:api_client) { OpenAI::API::Client.new('sk-123', http: http) }
4
+ let(:api) { OpenAI::API.new(api_client) }
5
+ let(:api_client) { OpenAI::API::Client.new('sk-123', http:) }
6
6
  let(:http) { class_spy(HTTP) }
7
7
  let(:response_status_code) { 200 }
8
8
 
@@ -9,7 +9,7 @@ RSpec.describe OpenAI::API, '#audio' do
9
9
  context 'when transcribing audio' do
10
10
  let(:response_body) do
11
11
  {
12
- "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that."
12
+ text: "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that."
13
13
  }
14
14
  end
15
15
 
@@ -42,7 +42,7 @@ RSpec.describe OpenAI::API, '#audio' do
42
42
 
43
43
  let(:response_body) do
44
44
  {
45
- "text": 'Hello, my name is Wolfgang and I come from Germany. Where are you heading today?'
45
+ text: 'Hello, my name is Wolfgang and I come from Germany. Where are you heading today?'
46
46
  }
47
47
  end
48
48
 
@@ -6,34 +6,34 @@ RSpec.describe OpenAI::API, '#chat_completions' do
6
6
  let(:resource) { api.chat_completions }
7
7
  let(:response_body) do
8
8
  {
9
- "id": 'chatcmpl-123',
10
- "object": 'chat.completion',
11
- "created": 1_677_652_288,
12
- "choices": [
9
+ id: 'chatcmpl-123',
10
+ object: 'chat.completion',
11
+ created: 1_677_652_288,
12
+ choices: [
13
13
  {
14
- "index": 0,
15
- "message": {
16
- "role": 'assistant',
17
- "content": "\n\nHello there, how may I assist you today?"
14
+ index: 0,
15
+ message: {
16
+ role: 'assistant',
17
+ content: "\n\nHello there, how may I assist you today?"
18
18
  },
19
- "finish_reason": 'stop'
19
+ finish_reason: 'stop'
20
20
  }
21
21
  ],
22
- "usage": {
23
- "prompt_tokens": 9,
24
- "completion_tokens": 12,
25
- "total_tokens": 21
22
+ usage: {
23
+ prompt_tokens: 9,
24
+ completion_tokens: 12,
25
+ total_tokens: 21
26
26
  }
27
27
  }
28
28
  end
29
29
 
30
30
  let(:completion) do
31
31
  messages = [
32
- { "text": 'Hello there!', "user": 'customer' },
33
- { "text": 'Can you help me with my order?', "user": 'customer' },
34
- { "text": 'Sure, what would you like to do?', "user": 'assistant' }
32
+ { text: 'Hello there!', user: 'customer' },
33
+ { text: 'Can you help me with my order?', user: 'customer' },
34
+ { text: 'Sure, what would you like to do?', user: 'assistant' }
35
35
  ]
36
- resource.create(model: 'text-davinci-002', messages: messages)
36
+ resource.create(model: 'text-davinci-002', messages:)
37
37
  end
38
38
 
39
39
  it 'can create a chat completion' do
@@ -64,10 +64,10 @@ RSpec.describe OpenAI::API, '#chat_completions' do
64
64
  context 'when streaming is enabled' do
65
65
  let(:response_chunks) do
66
66
  [
67
- chunk(role: 'assistant'),
68
- chunk(content: 'He'),
69
- chunk(content: 'llo,'),
70
- chunk(content: ' world'),
67
+ chunk({ role: 'assistant' }),
68
+ chunk({ content: 'He' }),
69
+ chunk({ content: 'llo,' }),
70
+ chunk({ content: ' world' }),
71
71
  chunk({ content: '!' }, finish_reason: 'stop')
72
72
  ]
73
73
  end
@@ -102,7 +102,7 @@ RSpec.describe OpenAI::API, '#chat_completions' do
102
102
  object: 'chat.completion.chunk',
103
103
  created: 1_679_780_213,
104
104
  model: 'gpt-3.5-turbo-0301',
105
- choices: [delta: delta, index: 0, finish_reason: finish_reason]
105
+ choices: [delta:, index: 0, finish_reason:]
106
106
  }
107
107
 
108
108
  "data: #{JSON.dump(data)}"
@@ -7,22 +7,22 @@ RSpec.describe OpenAI::API, '#completions' do
7
7
 
8
8
  let(:response_body) do
9
9
  {
10
- "id": 'cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7',
11
- "object": 'text_completion',
12
- "created": 1_589_478_378,
13
- "model": 'text-davinci-003',
14
- "choices": [
10
+ id: 'cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7',
11
+ object: 'text_completion',
12
+ created: 1_589_478_378,
13
+ model: 'text-davinci-003',
14
+ choices: [
15
15
  {
16
- "text": "\n\nThis is indeed a test",
17
- "index": 0,
18
- "logprobs": nil,
19
- "finish_reason": 'length'
16
+ text: "\n\nThis is indeed a test",
17
+ index: 0,
18
+ logprobs: nil,
19
+ finish_reason: 'length'
20
20
  }
21
21
  ],
22
- "usage": {
23
- "prompt_tokens": 5,
24
- "completion_tokens": 7,
25
- "total_tokens": 12
22
+ usage: {
23
+ prompt_tokens: 5,
24
+ completion_tokens: 7,
25
+ total_tokens: 12
26
26
  }
27
27
  }
28
28
  end
@@ -91,16 +91,16 @@ RSpec.describe OpenAI::API, '#completions' do
91
91
 
92
92
  def chunk(text, finish_reason: nil)
93
93
  data = {
94
- "id": 'cmpl-6y5B6Ak8wBk2nKsqVtSlFeJAG1dUM',
95
- "object": 'text_completion',
96
- "created": 1_679_777_604,
97
- "choices": [{
98
- "text": text,
99
- "index": 0,
100
- "logprobs": nil,
101
- "finish_reason": finish_reason
94
+ id: 'cmpl-6y5B6Ak8wBk2nKsqVtSlFeJAG1dUM',
95
+ object: 'text_completion',
96
+ created: 1_679_777_604,
97
+ choices: [{
98
+ text:,
99
+ index: 0,
100
+ logprobs: nil,
101
+ finish_reason:
102
102
  }],
103
- "model": 'text-davinci-002'
103
+ model: 'text-davinci-002'
104
104
  }
105
105
 
106
106
  "data: #{JSON.dump(data)}"
@@ -6,18 +6,18 @@ RSpec.describe OpenAI::API, '#edits' do
6
6
  let(:resource) { api.edits }
7
7
  let(:response_body) do
8
8
  {
9
- "object": 'edit',
10
- "created": 1_589_478_378,
11
- "choices": [
9
+ object: 'edit',
10
+ created: 1_589_478_378,
11
+ choices: [
12
12
  {
13
- "text": 'What day of the week is it?',
14
- "index": 0
13
+ text: 'What day of the week is it?',
14
+ index: 0
15
15
  }
16
16
  ],
17
- "usage": {
18
- "prompt_tokens": 25,
19
- "completion_tokens": 32,
20
- "total_tokens": 57
17
+ usage: {
18
+ prompt_tokens: 25,
19
+ completion_tokens: 32,
20
+ total_tokens: 57
21
21
  }
22
22
  }
23
23
  end
@@ -6,22 +6,22 @@ RSpec.describe OpenAI::API, '#embeddings' do
6
6
  let(:resource) { api.embeddings }
7
7
  let(:response_body) do
8
8
  {
9
- "object": 'list',
10
- "data": [
9
+ object: 'list',
10
+ data: [
11
11
  {
12
- "object": 'embedding',
13
- "embedding": [
12
+ object: 'embedding',
13
+ embedding: [
14
14
  0.0023064255,
15
15
  -0.009327292,
16
16
  -0.0028842222
17
17
  ],
18
- "index": 0
18
+ index: 0
19
19
  }
20
20
  ],
21
- "model": 'text-embedding-ada-002',
22
- "usage": {
23
- "prompt_tokens": 8,
24
- "total_tokens": 8
21
+ model: 'text-embedding-ada-002',
22
+ usage: {
23
+ prompt_tokens: 8,
24
+ total_tokens: 8
25
25
  }
26
26
  }
27
27
  end