Class: Wco::AiWriter

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
app/models/wco/ai_writer.rb

Class Method Summary collapse

Class Method Details

.do_call(task, content) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/wco/ai_writer.rb', line 9

def self.do_call(task, content)
  response = post(
    "/v1/chat/completions",
    headers: {
      "Authorization" => "Bearer #{OPENAI_API_KEY}",
      "Content-Type" => "application/json"
    },
    body: {
      model: "gpt-4o",
      messages: [
        {
          role: "system",
          content: task
        },
        {
          role: "user",
          content: content
        }
      ]
    }.to_json
  )

  response.dig("choices", 0, "message", "content")
end