Skip to content

Commit 2997e70

Browse files
committed
Add spec & README for completions
1 parent f8bbc3b commit 2997e70

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ end
399399
# => "The weather is nice 🌞"
400400
```
401401

402+
### Completions
403+
404+
Hit the OpenAI API for a completion using other GPT-3 models:
405+
406+
````ruby
407+
response = client.completions(
408+
parameters: {
409+
model: "text-davinci-001",
410+
prompt: "Once upon a time",
411+
max_tokens: 5
412+
})
413+
puts response["choices"].map { |c| c["text"] }
414+
# => [", there lived a great"]
415+
402416
### Edits
403417

404418
Send a string and some instructions for what to do to the string:
@@ -413,7 +427,7 @@ response = client.edits(
413427
)
414428
puts response.dig("choices", 0, "text")
415429
# => What day of the week is it?
416-
```
430+
````
417431
418432
### Embeddings
419433

spec/fixtures/cassettes/gpt-3_5-turbo-instruct_completions_once_upon_a_time.yml

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
RSpec.describe OpenAI::Client do
2+
describe "#completions: gpt-3.5-turbo-instruct" do
3+
context "with a prompt and max_tokens", :vcr do
4+
let(:prompt) { "Once upon a time" }
5+
let(:max_tokens) { 5 }
6+
7+
let(:response) do
8+
OpenAI::Client.new.completions(
9+
parameters: {
10+
model: model,
11+
prompt: prompt,
12+
max_tokens: max_tokens
13+
}
14+
)
15+
end
16+
let(:text) { response.dig("choices", 0, "text") }
17+
let(:cassette) { "#{model} completions #{prompt}".downcase }
18+
let(:model) { "gpt-3.5-turbo-instruct" }
19+
20+
it "succeeds" do
21+
VCR.use_cassette(cassette) do
22+
expect(text.split.empty?).to eq(false)
23+
end
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)