Class: SmartPrompt::OpenaiAdapter
- Inherits:
-
LLMAdapter
- Object
- LLMAdapter
- SmartPrompt::OpenaiAdapter
- Defined in:
- lib/smart_prompt/llm_adapter.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ OpenaiAdapter
constructor
A new instance of OpenaiAdapter.
- #send_request(messages, model = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ OpenaiAdapter
Returns a new instance of OpenaiAdapter.
19 20 21 22 23 24 25 26 |
# File 'lib/smart_prompt/llm_adapter.rb', line 19 def initialize(config) super @client = OpenAI::Client.new( access_token: @config['api_key'], uri_base: @config['url'], request_timeout: 240 ) end |
Instance Method Details
#send_request(messages, model = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/smart_prompt/llm_adapter.rb', line 28 def send_request(, model=nil) if model model_name = model else model_name = @config['model'] end response = @client.chat( parameters: { model: model_name, messages: , temperature: @config['temperature'] || 0.7 } ) response.dig("choices", 0, "message", "content") end |