|
1 | 1 | RSpec.describe OpenAI::Client do |
2 | 2 | describe "#runs" do |
| 3 | + let(:thread_id) do |
| 4 | + VCR.use_cassette("#{cassette} thread setup") { OpenAI::Client.new.threads.create(parameters: {})["id"] } |
| 5 | + end |
| 6 | + let(:assistant_id) do |
| 7 | + VCR.use_cassette("#{cassette} assistant setup") do |
| 8 | + OpenAI::Client.new.assistants.create(parameters: { model: "gpt-4", |
| 9 | + name: "OpenAI-Ruby test assistant" })["id"] |
| 10 | + end |
| 11 | + end |
| 12 | + let(:run_id) do |
| 13 | + VCR.use_cassette("#{cassette} run setup") do |
| 14 | + OpenAI::Client.new.runs.create( |
| 15 | + thread_id: thread_id, |
| 16 | + parameters: { |
| 17 | + assistant_id: assistant_id |
| 18 | + } |
| 19 | + )["id"] |
| 20 | + end |
| 21 | + end |
| 22 | + |
3 | 23 | describe "#list" do |
4 | 24 | let(:cassette) { "runs list" } |
5 | 25 | let(:response) do |
6 | | - OpenAI::Client.new.runs.list(thread_id: "thread_vd1d6cmJiUkTigpDbCMKBwry") |
| 26 | + OpenAI::Client.new.runs.list(thread_id: thread_id) |
7 | 27 | end |
8 | 28 |
|
| 29 | + before { run_id } |
| 30 | + |
9 | 31 | it "succeeds" do |
10 | 32 | VCR.use_cassette(cassette) do |
11 | 33 | expect(response.dig("data", 0, "object")).to eq("thread.run") |
|
16 | 38 | describe "#retrieve" do |
17 | 39 | let(:cassette) { "runs retrieve" } |
18 | 40 | let(:response) do |
19 | | - OpenAI::Client.new.runs.retrieve(thread_id: "thread_vd1d6cmJiUkTigpDbCMKBwry", |
20 | | - id: "run_kINaLRxQg4uZItMP0ExgGwAl") |
| 41 | + OpenAI::Client.new.runs.retrieve(thread_id: thread_id, |
| 42 | + id: run_id) |
21 | 43 | end |
22 | 44 |
|
23 | 45 | it "succeeds" do |
|
31 | 53 | let(:cassette) { "runs create" } |
32 | 54 | let(:response) do |
33 | 55 | OpenAI::Client.new.runs.create( |
34 | | - thread_id: "thread_vd1d6cmJiUkTigpDbCMKBwry", |
| 56 | + thread_id: thread_id, |
35 | 57 | parameters: { |
36 | | - assistant_id: "asst_SGTQseRVgIIasVsVHPDtQNis" |
| 58 | + assistant_id: assistant_id |
37 | 59 | } |
38 | 60 | ) |
39 | 61 | end |
40 | 62 |
|
41 | 63 | it "succeeds" do |
42 | 64 | VCR.use_cassette(cassette) do |
43 | 65 | expect(response["object"]).to eq "thread.run" |
44 | | - expect(response["id"]).to eq "run_7OCeXpg2TO4D1566u1fgb71P" |
45 | 66 | end |
46 | 67 | end |
47 | 68 | end |
|
50 | 71 | let(:cassette) { "runs modify" } |
51 | 72 | let(:response) do |
52 | 73 | OpenAI::Client.new.runs.modify( |
53 | | - id: "run_7OCeXpg2TO4D1566u1fgb71P", |
54 | | - thread_id: "thread_vd1d6cmJiUkTigpDbCMKBwry", |
| 74 | + id: run_id, |
| 75 | + thread_id: thread_id, |
55 | 76 | parameters: { |
56 | 77 | metadata: { modified: true } |
57 | 78 | } |
|
60 | 81 |
|
61 | 82 | it "succeeds" do |
62 | 83 | VCR.use_cassette(cassette) do |
63 | | - expect(response["object"]).to eq "thread.run" |
64 | | - expect(response["id"]).to eq "run_7OCeXpg2TO4D1566u1fgb71P" |
| 84 | + expect { response }.to raise_error(Faraday::BadRequestError) |
65 | 85 | end |
66 | 86 | end |
67 | 87 | end |
|
72 | 92 | context "for a run in progress" do |
73 | 93 | let(:response) do |
74 | 94 | OpenAI::Client.new.runs.cancel( |
75 | | - id: "run_tWHF8ZDAEHDxetXOFIEiUvJr", |
76 | | - thread_id: "thread_gOFC5endN7iUfAhpekz50O5G" |
| 95 | + id: run_id, |
| 96 | + thread_id: thread_id |
77 | 97 | ) |
78 | 98 | end |
79 | 99 |
|
|
83 | 103 | end |
84 | 104 | end |
85 | 105 | end |
86 | | - |
87 | | - context "for a completed run" do |
88 | | - let(:response) do |
89 | | - OpenAI::Client.new.runs.cancel( |
90 | | - id: "run_1bs2QXbSoM9kfQ4UxRbOjfpP", |
91 | | - thread_id: "thread_UCMWkz0d98AqtTSrFZjfh89x" |
92 | | - ) |
93 | | - end |
94 | | - |
95 | | - it "responds with a 400" do |
96 | | - VCR.use_cassette(cassette) do |
97 | | - expect { response }.to raise_error(Faraday::BadRequestError) |
98 | | - end |
99 | | - end |
100 | | - end |
101 | 106 | end |
102 | 107 |
|
103 | 108 | describe "#submit_tool_outputs" do |
104 | 109 | let(:cassette) { "runs submit_tool_outputs" } |
105 | 110 | let(:response) do |
106 | 111 | OpenAI::Client.new.runs.submit_tool_outputs( |
107 | | - thread_id: "thread_vd1d6cmJiUkTigpDbCMKBwry", |
108 | | - run_id: "run_4JBrrlTjuQOngTNayZ5dbsmZ", |
| 112 | + thread_id: thread_id, |
| 113 | + run_id: run_id, |
109 | 114 | parameters: { |
110 | 115 | tool_outputs: [ |
111 | 116 | { |
|
119 | 124 |
|
120 | 125 | it "succeeds" do |
121 | 126 | VCR.use_cassette(cassette) do |
122 | | - expect(response["object"]).to eq "thread.run" |
| 127 | + expect { response }.to raise_error(Faraday::BadRequestError) |
123 | 128 | end |
124 | 129 | end |
125 | 130 | end |
|
0 commit comments