Class: OmniAI::Chat
- Inherits:
-
Object
- Object
- OmniAI::Chat
- Defined in:
- lib/omniai/chat.rb,
lib/omniai/chat/chunk.rb,
lib/omniai/chat/delta.rb,
lib/omniai/chat/usage.rb,
lib/omniai/chat/choice.rb,
lib/omniai/chat/stream.rb,
lib/omniai/chat/content.rb,
lib/omniai/chat/message.rb,
lib/omniai/chat/completion.rb
Overview
An abstract class that provides a consistent interface for processing chat requests.
Usage:
class OmniAI::OpenAI::Chat < OmniAI::Chat
module Model
GPT_4O = "gpt-4o"
end
protected
# @return [Hash]
def payload
raise NotImplementedError, "#{self.class.name}#payload undefined"
end
# @return [String]
def path
raise NotImplementedError, "#{self.class.name}#path undefined"
end
end
client.chat(, model: "...", temperature: 0.0, format: :text)
Defined Under Namespace
Modules: Format, Role Classes: Choice, Chunk, Completion, Content, Delta, Message, Stream, Usage
Constant Summary collapse
- JSON_PROMPT =
'Respond with valid JSON. Do not include any non-JSON in the response.'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(messages, client:, model:, temperature: nil, stream: nil, format: nil) ⇒ Chat
constructor
A new instance of Chat.
- #process! ⇒ Object
Constructor Details
#initialize(messages, client:, model:, temperature: nil, stream: nil, format: nil) ⇒ Chat
Returns a new instance of Chat.
50 51 52 53 54 55 56 57 |
# File 'lib/omniai/chat.rb', line 50 def initialize(, client:, model:, temperature: nil, stream: nil, format: nil) @messages = @client = client @model = model @temperature = temperature @stream = stream @format = format end |
Class Method Details
.process! ⇒ Object
40 41 42 |
# File 'lib/omniai/chat.rb', line 40 def self.process!(...) new(...).process! end |
Instance Method Details
#process! ⇒ Object
60 61 62 63 64 65 |
# File 'lib/omniai/chat.rb', line 60 def process! response = request! raise HTTPError, response.flush unless response.status.ok? parse!(response:) end |