Class: Crimson::Client::OpenAIAdapter
- Defined in:
- lib/crimson/client/openai_adapter.rb
Overview
OpenAI SDK client adapter supporting streaming and non-streaming chat.
Instance Method Summary collapse
- #chat(messages:, tools: []) {|text_chunk, tool_event| ... } ⇒ Array(Message::Assistant, Hash, nil)
-
#initialize(config) ⇒ OpenAIAdapter
constructor
A new instance of OpenAIAdapter.
Constructor Details
#initialize(config) ⇒ OpenAIAdapter
Returns a new instance of OpenAIAdapter.
12 13 14 15 |
# File 'lib/crimson/client/openai_adapter.rb', line 12 def initialize(config) super @client = build_client end |
Instance Method Details
#chat(messages:, tools: []) {|text_chunk, tool_event| ... } ⇒ Array(Message::Assistant, Hash, nil)
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/crimson/client/openai_adapter.rb', line 21 def chat(messages:, tools: [], &stream_callback) params = { messages: .map(&:to_openai_h), model: @config.model } params[:tools] = tools unless tools.empty? if block_given? stream_chat(params, &stream_callback) else non_stream_chat(params) end end |