ruby-openai 1.2.1 → 1.2.2

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: eb5a5c5d8b8e04ba7f6c22de243bfd1e901b69e28cdc2bb234b8bdc46c58a110
4
- data.tar.gz: 138fa30d605a4ca116b98a3acb5b74617f27420a8110ef38605ec00f5896fbc3
3
+ metadata.gz: 9a10874422fb2b2250857d43afe2baa501152ba0358dadfe12d4a2c21f106325
4
+ data.tar.gz: 5bfbedd2a2347ee7479ebcdf48dc4c7fe8e4dc74fcd721c9c3beeb1386b3199e
5
5
  SHA512:
6
- metadata.gz: 2cf09eca86b84db3f6dce82589fd5c2ccd36259308e941427a5b5b9498ebccf3797a57cd6802a91879d0b6cdc87e2383e4ae4451b0941ef74beea64e721a120a
7
- data.tar.gz: f3f9dff8efd9ba3c4a32880940078b460c8d853e9a88b0e12fb360de1e3bcb8c3b88dda695b49de9a1c08f9947d69a421be2021a466b0693b74b252cb84348f9
6
+ metadata.gz: 67f860d7243072419bc21c91bce26e71b8def68115f91347822770e087c2cc898b42cf2b8fd2a97155d7b44cf79d096e54e6dd16b0842d680ddcef4effb4ca9c
7
+ data.tar.gz: 6283aaf2aba88b61f47c6218a62bf70c837c9d9a8893bea5f1ee27801f2168f5868329fe33b3de827e056f278e6c70f61b7d70b18582ffc87586bce579374d47
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.2] - 2021-04-18
9
+
10
+ ### Changed
11
+
12
+ - Add Client#search(parameters:) to allow passing `max_rerank` or `return_metadata`.
13
+ - Deprecate Client#search with query, file or document parameters at the top level.
14
+ - Thanks [@stevegeek](https://github.com/stevegeek) for pointing this issue out!
15
+
8
16
  ## [1.2.1] - 2021-04-11
9
17
 
10
18
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai (1.2.1)
4
+ ruby-openai (1.2.2)
5
5
  dotenv (~> 2.7.6)
6
6
  httparty (~> 0.18.1)
7
7
 
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/ruby-openai.svg)](https://badge.fury.io/rb/ruby-openai)
4
4
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/ruby-openai/blob/main/LICENSE.txt)
5
5
  [![CircleCI Build Status](https://circleci.com/gh/alexrudall/ruby-openai.svg?style=shield)](https://circleci.com/gh/alexrudall/ruby-openai)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
6
7
 
7
8
  A simple Ruby wrapper for the [OpenAI GPT-3 API](https://openai.com/blog/openai-api/).
8
9
 
@@ -81,7 +82,7 @@ and pass the path to `client.files.upload` to upload it to OpenAI, and then inte
81
82
  Pass documents and a query string to get semantic search scores against each document:
82
83
 
83
84
  ```
84
- response = client.search(engine: "ada", documents: %w[washington hospital school], query: "president")
85
+ response = client.search(engine: "ada", parameters: { documents: %w[washington hospital school], query: "president" })
85
86
  puts response["data"].map { |d| d["score"] }
86
87
  => [202.0, 48.052, 19.247]
87
88
  ```
@@ -89,7 +90,7 @@ Pass documents and a query string to get semantic search scores against each doc
89
90
  You can alternatively search using the ID of a file you've uploaded:
90
91
 
91
92
  ```
92
- client.search(engine: "ada", file: "abc123", query: "happy")
93
+ client.search(engine: "ada", parameters: { file: "abc123", query: "happy" })
93
94
  ```
94
95
 
95
96
  ### Answers
@@ -33,19 +33,44 @@ module OpenAI
33
33
  @files ||= OpenAI::Files.new(access_token: @access_token)
34
34
  end
35
35
 
36
- def search(engine:, query:, documents: nil, file: nil, version: default_version)
36
+ # rubocop:disable Layout/LineLength
37
+ # rubocop:disable Metrics/ParameterLists
38
+ def search(engine:, query: nil, documents: nil, file: nil, version: default_version, parameters: {})
39
+ return legacy_search(engine: engine, query: query, documents: documents, file: file, version: version) if query || documents || file
40
+
37
41
  self.class.post(
38
42
  "/#{version}/engines/#{engine}/search",
39
43
  headers: {
40
44
  "Content-Type" => "application/json",
41
45
  "Authorization" => "Bearer #{@access_token}"
42
46
  },
43
- body: { query: query }.merge(documents_or_file(documents: documents, file: file)).to_json
47
+ body: parameters.to_json
44
48
  )
45
49
  end
50
+ # rubocop:enable Layout/LineLength
51
+ # rubocop:enable Metrics/ParameterLists
46
52
 
47
53
  private
48
54
 
55
+ # rubocop:disable Metrics/MethodLength
56
+ # rubocop:disable Layout/LineLength
57
+ def legacy_search(engine:, query:, documents: nil, file: nil, version: default_version)
58
+ warn "[DEPRECATION] Passing `query`, `documents` or `file` directly to `Client#search` is deprecated and will be removed in a future version of ruby-openai.
59
+ Please nest these terms within `parameters` instead, like this:
60
+ client.search(engine: 'davinci', parameters: { query: 'president', documents: %w[washington hospital school] })
61
+ "
62
+ self.class.post(
63
+ "/#{version}/engines/#{engine}/search",
64
+ headers: {
65
+ "Content-Type" => "application/json",
66
+ "Authorization" => "Bearer #{@access_token}"
67
+ },
68
+ body: { query: query }.merge(documents_or_file(documents: documents, file: file)).to_json
69
+ )
70
+ end
71
+ # rubocop:enable Metrics/MethodLength
72
+ # rubocop:enable Layout/LineLength
73
+
49
74
  def default_version
50
75
  "v1".freeze
51
76
  end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module OpenAI
3
- VERSION = "1.2.1".freeze
3
+ VERSION = "1.2.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-11 00:00:00.000000000 Z
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv