huginn_ollama_agent 0.1.10 → 0.1.11
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 +4 -4
- data/lib/huginn_ollama_agent/ollama_agent.rb +34 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2528d73ee7c66815ff599fea1ca57382036a367670849a0c9d1180c94dd4035
|
4
|
+
data.tar.gz: 73f49b9773db8c5015da9d42c01764023c61d76bfa9badac00b289446c20ca8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad7f7f1881cb615762106c7e0f1d25aefe031515c61d1fc3c1e498ac130e8c84b3d449cb12444823c0ba0fb7154208c1255c563c09606a73e4d0bc167c931b1
|
7
|
+
data.tar.gz: 853c508e1a36aa8c0b1f96d73703c05fd73a220097f374080bd87bf2c99aa2cd004602ffea18c6cc485c7c3c7a3517079a0beec49f8ae98c800421e4597a9543
|
@@ -17,7 +17,7 @@ module Agents
|
|
17
17
|
|
18
18
|
`prompt` the prompt to generate a response.
|
19
19
|
|
20
|
-
`image` is a base64-encoded image (for multimodal models such as llava).
|
20
|
+
`image` is a base64-encoded image or URL (for multimodal models such as llava).
|
21
21
|
|
22
22
|
`context` the context parameter returned from a previous request to /generate, this can be used to keep a short conversational memory.
|
23
23
|
|
@@ -249,6 +249,38 @@ module Agents
|
|
249
249
|
false
|
250
250
|
end
|
251
251
|
|
252
|
+
def encode_to_base64(data)
|
253
|
+
return Base64.strict_encode64(data)
|
254
|
+
end
|
255
|
+
|
256
|
+
def download_and_convert_to_base64(url)
|
257
|
+
begin
|
258
|
+
uri = URI(url)
|
259
|
+
response = Net::HTTP.get_response(uri)
|
260
|
+
|
261
|
+
log_curl_output(response.code,response.body)
|
262
|
+
|
263
|
+
if response.is_a?(Net::HTTPSuccess)
|
264
|
+
file_data = response.body
|
265
|
+
base64_data = encode_to_base64(file_data)
|
266
|
+
return base64_data
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def detect_image_source(input)
|
272
|
+
if input =~ URI::DEFAULT_PARSER.regexp[:ABS_URI]
|
273
|
+
download_and_convert_to_base64(interpolated['image'])
|
274
|
+
elsif input.match?(/\A(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?\z/)
|
275
|
+
begin
|
276
|
+
decoded = Base64.strict_decode64(input)
|
277
|
+
if Base64.strict_encode64(decoded) == input
|
278
|
+
return input
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
252
284
|
def generate_completion()
|
253
285
|
|
254
286
|
request_payload = {}
|
@@ -257,7 +289,7 @@ module Agents
|
|
257
289
|
request_payload['stream'] = boolify(interpolated['stream'])
|
258
290
|
request_payload['raw'] = boolify(interpolated['raw'])
|
259
291
|
request_payload['context'] = context if !interpolated['context'].empty?
|
260
|
-
request_payload['images'] = ["#{interpolated['image']}"] if !interpolated['image'].empty?
|
292
|
+
request_payload['images'] = ["#{detect_image_source(interpolated['image'])}"] if !interpolated['image'].empty?
|
261
293
|
|
262
294
|
if check_remote_model()
|
263
295
|
if interpolated['debug'] == 'true'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_ollama_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Germain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|