smollama 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9f331024c63381cad8781105f25f9c86f8d1745f89ee4ec6ce230e65646500b
4
- data.tar.gz: 14b790b0158ac0cd54a9520e37d68eab471cbc5951e9a38274bbc3da51d9df93
3
+ metadata.gz: 5eb20d070bc8386684a46b046d3b31bcb91c48c444bffb9366c9fdc9e8c1a34c
4
+ data.tar.gz: 9d0df8aa3966ae405d9df737fd2cc82799eeee7f2c8bb983f4c583f28f578fd5
5
5
  SHA512:
6
- metadata.gz: 7f9e09789dcabfc5282332fda7742f7a054547e9c0df57b349282db5ab7d4dba7ead148da52b0a5345aa921b94d07d611feec48f34e20672473933776c6cfff0
7
- data.tar.gz: e81e862f8534d92d9b929dfe6ee0901b3f39030cb55610572d4a2dbf1f6f5e4c29a90866b9fd26c74226b494795a612ce6df5adf4fb49458d806ab3eb9b9706b
6
+ metadata.gz: 67f0073ebf5dc0bda3b5851ab85c9354dbb1e63fa722f3120230974045b7b4a930d6fc0b0aebc692aff6267853471a6fa2c9ef715e68bf55d62637ce79f0f769
7
+ data.tar.gz: 0efde51d756f704a4b0570728a836affbf22676bb22c8490e41a545d5c2050e7e5fc545da5cb5fe5c5cfe336f6d6e2b328c112e80f51033bc33fb716846ac7b9
data/README.md CHANGED
@@ -85,6 +85,47 @@ special_client = Smollama::Client.new(model: 'llama2')
85
85
  response = special_client.ask("Hello!")
86
86
  ```
87
87
 
88
+ ### Vision - Chat with Images
89
+
90
+ Vision models can accept images alongside text to describe, classify, and answer questions about what they see.
91
+
92
+ ```ruby
93
+ # Use a vision-capable model
94
+ client = Smollama::Client.new(model: 'gemma3')
95
+
96
+ # With a local file path
97
+ response = client.chat(
98
+ "What is in this image?",
99
+ images: ["./cat.jpg"]
100
+ )
101
+ puts response[:content]
102
+
103
+ # With a URL
104
+ response = client.chat(
105
+ "Describe this image",
106
+ images: ["https://example.com/image.jpg"]
107
+ )
108
+
109
+ # With multiple images
110
+ response = client.chat(
111
+ "Compare these images",
112
+ images: ["./image1.jpg", "./image2.jpg"]
113
+ )
114
+
115
+ # With base64 encoded image data
116
+ img_data = Base64.strict_encode64(File.read("./image.jpg"))
117
+ response = client.chat(
118
+ "What do you see?",
119
+ images: [img_data]
120
+ )
121
+ ```
122
+
123
+ The `images` parameter accepts:
124
+ - File paths (e.g., `"./image.jpg"`)
125
+ - URLs (e.g., `"https://example.com/image.jpg"`)
126
+ - Base64 encoded strings
127
+ - An array of any combination of the above
128
+
88
129
  ### Server Health Check
89
130
 
90
131
  ```ruby
@@ -1,5 +1,6 @@
1
1
  require 'excon'
2
2
  require 'json'
3
+ require 'base64'
3
4
 
4
5
  module Smollama
5
6
  class Client
@@ -33,8 +34,8 @@ module Smollama
33
34
  end
34
35
 
35
36
  # Main chat method with configurable parameters
36
- def chat(message, temperature: nil, top_p: nil, max_tokens: nil, stream: false)
37
- messages = build_messages(message)
37
+ def chat(message, temperature: nil, top_p: nil, max_tokens: nil, stream: false, images: nil)
38
+ messages = build_messages(message, images: images)
38
39
 
39
40
  payload = {
40
41
  model: @model,
@@ -105,8 +106,8 @@ module Smollama
105
106
 
106
107
  private
107
108
 
108
- def build_messages(input)
109
- case input
109
+ def build_messages(input, images: nil)
110
+ messages = case input
110
111
  when String
111
112
  [{ role: 'user', content: input }]
112
113
  when Hash
@@ -116,6 +117,35 @@ module Smollama
116
117
  else
117
118
  raise "Invalid message format"
118
119
  end
120
+
121
+ # Add images to the last user message if provided
122
+ if images && !images.empty?
123
+ encoded_images = encode_images(images)
124
+ messages.last[:images] = encoded_images
125
+ end
126
+
127
+ messages
128
+ end
129
+
130
+ def encode_images(images)
131
+ Array(images).map do |image|
132
+ case image
133
+ when String
134
+ if image.start_with?('http://', 'https://')
135
+ # URL - Ollama can handle URLs directly, but we'll fetch and encode
136
+ require 'open-uri'
137
+ Base64.strict_encode64(URI.open(image).read)
138
+ elsif File.exist?(image)
139
+ # File path
140
+ Base64.strict_encode64(File.read(image))
141
+ else
142
+ # Assume it's already base64 encoded
143
+ image
144
+ end
145
+ else
146
+ raise "Invalid image format: #{image.class}"
147
+ end
148
+ end
119
149
  end
120
150
 
121
151
  def send_request(payload)
@@ -1,3 +1,3 @@
1
1
  module Smollama
2
- VERSION = "0.1.0"
3
- end
2
+ VERSION = "0.2.0"
3
+ end
data/smollama.gemspec CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  # Runtime dependencies
27
27
  spec.add_dependency "excon", "~> 0.100"
28
+ spec.add_dependency "base64"
29
+ spec.add_dependency "logger"
28
30
 
29
31
  # Development dependencies
30
32
  spec.add_development_dependency "bundler", "~> 2.0"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smollama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makevoid
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-08-29 00:00:00.000000000 Z
10
+ date: 2025-11-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: excon
@@ -23,6 +23,34 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0.100'
26
+ - !ruby/object:Gem::Dependency
27
+ name: base64
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: logger
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
26
54
  - !ruby/object:Gem::Dependency
27
55
  name: bundler
28
56
  requirement: !ruby/object:Gem::Requirement