|
44 | 44 | allow(Rails).to receive(:logger).and_return(logger) |
45 | 45 | (1..described_class::MAX_ATTEMPTS).each do |i| |
46 | 46 | expected_log_message = "LLM did not return valid JSON that conformed to the schema. " \ |
47 | | - "Attempt #{i}/#{described_class::MAX_ATTEMPTS}. " \ |
48 | | - "Error: #{error_class}, #{error_message}" |
| 47 | + "Attempt #{i}/#{described_class::MAX_ATTEMPTS}." |
49 | 48 | expect(logger).to receive(:warn) |
50 | 49 | .with(/#{expected_log_message}/) |
51 | 50 | .ordered |
|
55 | 54 | described_class.call(user_message:, tool:) |
56 | 55 | }.to raise_error(described_class::InvalidLlmResponseError) |
57 | 56 | end |
58 | | - |
59 | | - it "logs additional information when the error message (or class) changes between retries" do |
60 | | - logger = instance_double(Logger) |
61 | | - allow(Rails).to receive(:logger).and_return(logger) |
62 | | - allow(logger).to receive(:warn) |
63 | | - |
64 | | - call_count = 0 |
65 | | - original_response_body = stub.response.body |
66 | | - |
67 | | - stub_request(:post, StubBedrock::OPENAI_GPT_OSS_ENDPOINT_REGEX).to_return do |_request| |
68 | | - call_count += 1 |
69 | | - if call_count == 1 |
70 | | - { status: 200, headers: { "Content-Type" => "application/json" }, body: original_response_body } |
71 | | - else |
72 | | - { |
73 | | - status: 200, |
74 | | - headers: { "Content-Type" => "application/json" }, |
75 | | - body: { |
76 | | - choices: [{ |
77 | | - message: { |
78 | | - tool_calls: [{ function: { arguments: "not_json" } }], |
79 | | - }, |
80 | | - finish_reason: "stop", |
81 | | - }], |
82 | | - usage: { prompt_tokens: 10, completion_tokens: 10 }, |
83 | | - }.to_json, |
84 | | - } |
85 | | - end |
86 | | - end |
87 | | - |
88 | | - error = "#{error_class}, #{error_message}" |
89 | | - expect(logger).to receive(:warn) |
90 | | - .with(/#{error}/) |
91 | | - .ordered |
92 | | - expect(logger).to receive(:warn) |
93 | | - .with(/This error is different from the previous error: #{error}/) |
94 | | - .ordered |
95 | | - |
96 | | - expect { |
97 | | - described_class.call(user_message: user_message, tool: tool) |
98 | | - }.to raise_error(described_class::InvalidLlmResponseError) |
99 | | - end |
100 | 57 | end |
101 | 58 |
|
102 | 59 | it "returns a Result object with the evaluation data" do |
|
0 commit comments