Class: RCrewAI::LLMClients::OpenAI
- Defined in:
- lib/rcrewai/llm_clients/openai.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
'https://api.openai.com/v1'
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
-
#initialize(config = RCrewAI.configuration) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #models ⇒ Object
-
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument.
Methods inherited from Base
Constructor Details
#initialize(config = RCrewAI.configuration) ⇒ OpenAI
Returns a new instance of OpenAI.
16 17 18 19 |
# File 'lib/rcrewai/llm_clients/openai.rb', line 16 def initialize(config = RCrewAI.configuration) super @base_url = BASE_URL end |
Instance Method Details
#chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rcrewai/llm_clients/openai.rb', line 21 def chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **) payload = { model: config.model, messages: , temperature: [:temperature] || config.temperature, max_tokens: [:max_tokens] || config.max_tokens }.compact payload[:top_p] = [:top_p] if [:top_p] payload[:frequency_penalty] = [:frequency_penalty] if [:frequency_penalty] payload[:presence_penalty] = [:presence_penalty] if [:presence_penalty] payload[:stop] = [:stop] if [:stop] if tools && !tools.empty? payload[:tools] = ProviderSchema.for_many(:openai, tools) payload[:tool_choice] = tool_choice if tool_choice != :auto end if stream payload[:stream] = true payload[:stream_options] = { include_usage: true } stream_chat(payload, stream) else plain_chat(payload) end end |
#models ⇒ Object
52 53 54 55 56 57 |
# File 'lib/rcrewai/llm_clients/openai.rb', line 52 def models url = "#{@base_url}/models" response = http_client.get(url, {}, build_headers.merge(auth_header)) result = handle_response(response) result['data'].map { |model| model['id'] } end |
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument
48 49 50 |
# File 'lib/rcrewai/llm_clients/openai.rb', line 48 def supports_native_tools?(model: config.model) # rubocop:disable Lint/UnusedMethodArgument true end |