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.



64
65
66
67
# File 'lib/smart_prompt/llm_adapter.rb', line 64

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

Instance Method Details

#send_request(messages, model = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/smart_prompt/llm_adapter.rb', line 69

def send_request(messages, model=nil)
  if model
    model_name = model
  else
    model_name = @config['model']        
  end
  response = @client.generate(
    {
      model: model_name,
      prompt: messages.to_s,
      stream: false
    }
  )
  return response[0]["response"]
end