Module: Minitest::Assertions

Defined in:
lib/minitest/smartdiff.rb

Instance Method Summary collapse

Instance Method Details

#smart_diff(exp, act) ⇒ Object Also known as: diff



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/minitest/smartdiff.rb', line 137

def smart_diff(exp, act)
  return old_diff(exp,act) unless @smart_diff

  mode = smart_diffable?(exp, act)

  return old_diff(exp, act) unless mode

  expected, actual = if mode == :object
    [exp.to_json, act.to_json]
  else
    [exp, act]
  end

  params = {
    parameters: {
      messages: [
        {
          role: "user",
          content: prompt.result_with_hash({
            expected:,
            actual:,
            mode:
          }),
        },
      ],
      model: model,
      temperature: 0.00000000000001,
      seed: XXhash.xxh32(expected, actual)
    }
  }

  completion = openai.chat(**params)
  completion.dig("choices",0,"message","content") + "\n"
rescue => e
  warn "Error talking to OpenAI: #{e.message} will fallback to basic diff"
  old_diff(exp,act)
end