Skip to content

Commit 66a866c

Browse files
committed
Add bake task for pulling a model.
1 parent 7f955e2 commit 66a866c

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

bake/async/ollama.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ def models
1414
client.models.names
1515
end
1616
end
17+
18+
# Pulls the specified models from the Ollama API. If no models are specified, but there is a default model, it will pull that one.
19+
# @parameter models [Array(String)] The names of the models to pull.
20+
def pull(models)
21+
if models.empty?
22+
models = [Async::Ollama::Client.default_model]
23+
end
24+
25+
Async::Ollama::Client.open do |client|
26+
models.each do |model|
27+
client.pull(model) do |response|
28+
response.each do |line|
29+
puts line
30+
end
31+
end
32+
end
33+
end
34+
end

lib/async/ollama/client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require_relative "generate"
99
require_relative "chat"
1010
require_relative "models"
11+
require_relative "pull"
1112

1213
module Async
1314
module Ollama
@@ -57,6 +58,16 @@ def chat(messages, **options, &block)
5758
def models
5859
Models.get(self.with(path: "/api/tags"))
5960
end
61+
62+
def pull(model)
63+
Pull.post(self.with(path: "/api/pull"), model: model) do |resource, response|
64+
if block_given?
65+
yield response
66+
end
67+
68+
Pull.new(resource, value: response.read, metadata: response.headers)
69+
end
70+
end
6071
end
6172
end
6273
end

lib/async/ollama/pull.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024-2025, by Samuel Williams.
5+
6+
require "async/rest/representation"
7+
require_relative "wrapper"
8+
9+
module Async
10+
module Ollama
11+
# Represents the response from pulling models from the Ollama API.
12+
class Pull < Async::REST::Representation[Wrapper]
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)