ruby-openai 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/ruby/openai/client.rb +27 -2
- data/lib/ruby/openai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a10874422fb2b2250857d43afe2baa501152ba0358dadfe12d4a2c21f106325
|
4
|
+
data.tar.gz: 5bfbedd2a2347ee7479ebcdf48dc4c7fe8e4dc74fcd721c9c3beeb1386b3199e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
data/lib/ruby/openai/client.rb
CHANGED
@@ -33,19 +33,44 @@ module OpenAI
|
|
33
33
|
@files ||= OpenAI::Files.new(access_token: @access_token)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
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:
|
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
|
data/lib/ruby/openai/version.rb
CHANGED
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.
|
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
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|