Class: Buble::ChatCompletionsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/buble/chat.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ ChatCompletionsResource

Returns a new instance of ChatCompletionsResource.



17
18
19
# File 'lib/buble/chat.rb', line 17

def initialize(http)
  @http = http
end

Instance Method Details

#create(body = nil, **params) ⇒ Object



21
22
23
24
# File 'lib/buble/chat.rb', line 21

def create(body = nil, **params)
  payload = normalize_body(body, params).merge('stream' => false)
  @http.request('POST', '/api/v1/chat/completions', body: payload)
end

#stream(body = nil, **params) ⇒ Object



26
27
28
29
# File 'lib/buble/chat.rb', line 26

def stream(body = nil, **params)
  payload = normalize_body(body, params).merge('stream' => true)
  Streaming.events_from_lines(@http.stream_lines('POST', '/api/v1/chat/completions', body: payload))
end

#stream_text(body = nil, **params) ⇒ Object



31
32
33
# File 'lib/buble/chat.rb', line 31

def stream_text(body = nil, **params)
  Streaming.text_stream(stream(body, **params), :openai)
end