Skip to content

Commit

Permalink
Expose models.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 24, 2024
1 parent ee52001 commit e6329bd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bake/async/ollama.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def initialize(...)
super

require 'async/ollama/client'
end

def models
Async::Ollama::Client.open do |client|
client.models.names
end
end
6 changes: 6 additions & 0 deletions lib/async/ollama/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Copyright, 2024, by Samuel Williams.

require "async/rest/resource"

require_relative "generate"
require_relative "models"

module Async
module Ollama
Expand All @@ -27,6 +29,10 @@ def generate(prompt, **options, &block)
Generate.new(resource, value: response.read, metadata: response.headers)
end
end

def models
Models.get(self.with(path: "/api/tags"))
end
end
end
end
17 changes: 17 additions & 0 deletions lib/async/ollama/models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require "async/rest/representation"
require_relative "wrapper"

module Async
module Ollama
class Models < Async::REST::Representation[Wrapper]
def names
self.value[:models].map{|model| model[:name]}
end
end
end
end
5 changes: 4 additions & 1 deletion lib/async/ollama/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def join
end

def parser_for(response)
case response.headers["content-type"]
content_type = response.headers["content-type"]
media_type = content_type.split(";").first

case media_type
when APPLICATION_JSON
return Async::REST::Wrapper::JSON::Parser
when APPLICATION_JSON_STREAM
Expand Down

0 comments on commit e6329bd

Please sign in to comment.