Skip to content

Commit

Permalink
Merge pull request #15 from alexrudall/add_search
Browse files Browse the repository at this point in the history
Add search
  • Loading branch information
alexrudall authored Nov 22, 2020
2 parents b09c257 + e44f5e9 commit e52e305
Show file tree
Hide file tree
Showing 16 changed files with 474 additions and 97 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2020-11-22

### Added

- Add method to use the search endpoint.

## [0.1.4] - 2020-10-18

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby-openai (0.1.4)
ruby-openai (0.2.0)
dotenv (~> 2.7.6)
httparty (~> 0.18.1)

Expand Down
21 changes: 20 additions & 1 deletion lib/ruby/openai/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(access_token: nil)
@access_token = access_token || ENV["OPENAI_ACCESS_TOKEN"]
end

def call(engine:, prompt:, max_tokens:, version: "v1")
def call(engine:, prompt:, max_tokens:, version: default_version)
self.class.post(
"/#{version}/engines/#{engine}/completions",
headers: {
Expand All @@ -19,5 +19,24 @@ def call(engine:, prompt:, max_tokens:, version: "v1")
}.to_json
)
end

def search(engine:, documents:, query:, version: default_version)
self.class.post(
"/#{version}/engines/#{engine}/search",
headers: {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{@access_token}"
},
body: {
documents: documents, query: query
}.to_json
)
end

private

def default_version
"v1".freeze
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby/openai/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ruby
module OpenAI
VERSION = "0.1.4".freeze
VERSION = "0.2.0".freeze
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions spec/fixtures/cassettes/ada_search_the_president.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions spec/fixtures/cassettes/babbage_search_the_president.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e52e305

Please sign in to comment.