huginn_ollama_agent 0.1.0 → 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 +37 -0
 - 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,6 +17,8 @@ module Agents 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                  `prompt` the prompt to generate a response.
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
                  `image` is a base64-encoded image or URL (for multimodal models such as llava).
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       20 
22 
     | 
    
         
             
                  `context` the context parameter returned from a previous request to /generate, this can be used to keep a short conversational memory.
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
24 
     | 
    
         
             
                  `stream` if false the response will be returned as a single response object, rather than a stream of objects.
         
     | 
| 
         @@ -140,6 +142,7 @@ module Agents 
     | 
|
| 
       140 
142 
     | 
    
         
             
                form_configurable :model, type: :string
         
     | 
| 
       141 
143 
     | 
    
         
             
                form_configurable :url, type: :string
         
     | 
| 
       142 
144 
     | 
    
         
             
                form_configurable :prompt, type: :string
         
     | 
| 
      
 145 
     | 
    
         
            +
                form_configurable :image, type: :string
         
     | 
| 
       143 
146 
     | 
    
         
             
                form_configurable :context, type: :string
         
     | 
| 
       144 
147 
     | 
    
         
             
                form_configurable :stream, type: :boolean
         
     | 
| 
       145 
148 
     | 
    
         
             
                form_configurable :raw, type: :boolean
         
     | 
| 
         @@ -246,6 +249,38 @@ module Agents 
     | 
|
| 
       246 
249 
     | 
    
         
             
                  false
         
     | 
| 
       247 
250 
     | 
    
         
             
                end
         
     | 
| 
       248 
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 
     | 
    
         
            +
             
     | 
| 
       249 
284 
     | 
    
         
             
                def generate_completion()
         
     | 
| 
       250 
285 
     | 
    
         | 
| 
       251 
286 
     | 
    
         
             
                  request_payload = {}
         
     | 
| 
         @@ -254,6 +289,7 @@ module Agents 
     | 
|
| 
       254 
289 
     | 
    
         
             
                  request_payload['stream'] = boolify(interpolated['stream'])
         
     | 
| 
       255 
290 
     | 
    
         
             
                  request_payload['raw'] = boolify(interpolated['raw'])
         
     | 
| 
       256 
291 
     | 
    
         
             
                  request_payload['context'] = context if !interpolated['context'].empty?
         
     | 
| 
      
 292 
     | 
    
         
            +
                  request_payload['images'] = ["#{detect_image_source(interpolated['image'])}"] if !interpolated['image'].empty?
         
     | 
| 
       257 
293 
     | 
    
         | 
| 
       258 
294 
     | 
    
         
             
                  if check_remote_model()
         
     | 
| 
       259 
295 
     | 
    
         
             
                    if interpolated['debug'] == 'true'
         
     | 
| 
         @@ -272,6 +308,7 @@ module Agents 
     | 
|
| 
       272 
308 
     | 
    
         | 
| 
       273 
309 
     | 
    
         
             
                  req_options = {
         
     | 
| 
       274 
310 
     | 
    
         
             
                    use_ssl: uri.scheme == "https",
         
     | 
| 
      
 311 
     | 
    
         
            +
                    read_timeout: 120
         
     | 
| 
       275 
312 
     | 
    
         
             
                  }
         
     | 
| 
       276 
313 
     | 
    
         | 
| 
       277 
314 
     | 
    
         
             
                  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
         
     | 
    
        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
         
     |