Class: ActiveHarness::Providers::OpenAI
- Defined in:
- lib/active_harness/providers/openai.rb
Constant Summary collapse
- API_URL =
URI("https://api.openai.com/v1/chat/completions")
Constants inherited from Base
Base::HTTP, Base::STREAMING_HTTP
Instance Method Summary collapse
-
#call(model:, messages:, temperature: 0.7) ⇒ Hash
{ content:, provider:, model: }.
Instance Method Details
#call(model:, messages:, temperature: 0.7) ⇒ Hash
Returns { content:, provider:, model: }.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_harness/providers/openai.rb', line 12 def call(model:, messages:, temperature: 0.7) raw = post_json(API_URL, headers: { "Content-Type" => "application/json", "Authorization" => "Bearer #{api_key}" }, body: { model: model, messages: , temperature: temperature } ) data = parse!(raw) handle_error!(data) { content: data.dig("choices", 0, "message", "content").to_s.strip, provider: :openai, model: data["model"] || model, usage: extract_usage_openai(data) } end |