Class: Seo::Providers::Ollama
Constant Summary collapse
- DEFAULT_MODEL =
"llama3"- DEFAULT_HOST =
"http://localhost:11434"
Instance Method Summary collapse
- #complete(prompt, max_tokens:) ⇒ Object
-
#initialize(api_key: nil, model: DEFAULT_MODEL, host: DEFAULT_HOST) ⇒ Ollama
constructor
A new instance of Ollama.
Constructor Details
#initialize(api_key: nil, model: DEFAULT_MODEL, host: DEFAULT_HOST) ⇒ Ollama
Returns a new instance of Ollama.
14 15 16 17 |
# File 'lib/seo/providers/ollama.rb', line 14 def initialize(api_key: nil, model: DEFAULT_MODEL, host: DEFAULT_HOST) @model = model @host = host end |
Instance Method Details
#complete(prompt, max_tokens:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/seo/providers/ollama.rb', line 19 def complete(prompt, max_tokens:) uri = URI("#{@host}/api/chat") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" req = Net::HTTP::Post.new(uri) req["Content-Type"] = "application/json" req.body = JSON.generate({ model: @model, stream: false, messages: [{ role: "user", content: prompt }] }) data = JSON.parse(http.request(req).body) data.dig("message", "content").to_s end |