Class: Net::Llm::Ollama
- Inherits:
-
Object
- Object
- Net::Llm::Ollama
- Defined in:
- lib/net/llm/ollama.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #chat(messages, tools = [], &block) ⇒ Object
- #embeddings(input) ⇒ Object
- #generate(prompt, &block) ⇒ Object
-
#initialize(host: "localhost:11434", model: "llama2", http: Net::Llm.http) ⇒ Ollama
constructor
A new instance of Ollama.
- #show(name) ⇒ Object
- #tags ⇒ Object
Constructor Details
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/net/llm/ollama.rb', line 6 def host @host end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
6 7 8 |
# File 'lib/net/llm/ollama.rb', line 6 def http @http end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/net/llm/ollama.rb', line 6 def model @model end |
Instance Method Details
#chat(messages, tools = [], &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/net/llm/ollama.rb', line 14 def chat(, tools = [], &block) url = build_url("/api/chat") payload = { model: model, messages: , stream: block_given? } payload[:tools] = tools unless tools.empty? if block_given? stream_request(url, payload, &block) else post_request(url, payload) end end |
#embeddings(input) ⇒ Object
37 38 39 40 41 |
# File 'lib/net/llm/ollama.rb', line 37 def (input) url = build_url("/api/embed") payload = { model: model, input: input } post_request(url, payload) end |
#generate(prompt, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/net/llm/ollama.rb', line 26 def generate(prompt, &block) url = build_url("/api/generate") payload = { model: model, prompt: prompt, stream: block_given? } if block_given? stream_request(url, payload, &block) else post_request(url, payload) end end |
#show(name) ⇒ Object
49 50 51 52 53 |
# File 'lib/net/llm/ollama.rb', line 49 def show(name) url = build_url("/api/show") payload = { name: name } post_request(url, payload) end |
#tags ⇒ Object
43 44 45 46 47 |
# File 'lib/net/llm/ollama.rb', line 43 def url = build_url("/api/tags") response = http.get(url) handle_response(response) end |