Class: SmartPrompt::OllamaAdapter

Inherits:
LLMAdapter show all
Defined in:
lib/smart_prompt/llm_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ OllamaAdapter

Returns a new instance of OllamaAdapter.



75
76
77
78
# File 'lib/smart_prompt/llm_adapter.rb', line 75

def initialize(config)
  super
  @client = Ollama.new(credentials: { address: @config['url'] })
end

Instance Method Details

#send_request(messages, model = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/smart_prompt/llm_adapter.rb', line 80

def send_request(messages, model=nil)
  SmartPrompt.logger.info "OllamaAdapter: Sending request to Ollama"
  if model
    model_name = model
  else
    model_name = @config['model']        
  end
  SmartPrompt.logger.info "OllamaAdapter: Using model #{model_name}"
  response = @client.generate(
    {
      model: model_name,
      prompt: messages.to_s,
      stream: false
    }
  )
  SmartPrompt.logger.info "OllamaAdapter: Received response from Ollama"
  return response[0]["response"]
end