async-ollama 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48c03b349a35f753bc070a075d69b6d6b56090830115ff219ecb275238d0092d
4
+ data.tar.gz: 68219ece8502ab454ceced00fd20d3c878b145e5dd712da47eff5620ca18c141
5
+ SHA512:
6
+ metadata.gz: a71b7b32bbb34b670a41d52aa8ea03e54a9ef8ba90b2a0c18e86163f44ced131818c2e96ddb742fed1e77559f17781a3c3f50c197ffd6044dccf71f4492a4881
7
+ data.tar.gz: '059344b7fc623d8fc857e5761cbe511c2a5a1b9201027302d232e573d4cc3e76a0766a3e0568d879bd35a427574fc4970a77e620f89431f59b7ce123abcb2ad2'
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require 'async/rest/resource'
7
+ require_relative 'generate'
8
+
9
+ module Async
10
+ module Ollama
11
+ # Represents a connection to the Ollama service.
12
+ class Client < Async::REST::Resource
13
+ ENDPOINT = Async::HTTP::Endpoint.parse('http://localhost:11434')
14
+
15
+ def generate(prompt, **options, &block)
16
+ options[:prompt] = prompt
17
+ options[:model] ||= 'llama2'
18
+
19
+ Generate.post(self.with(path: '/api/generate'), options, &block)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require 'async/rest/representation'
7
+ require_relative 'wrapper'
8
+
9
+ module Async
10
+ module Ollama
11
+ class Generate < Async::REST::Representation[Wrapper]
12
+ def response
13
+ self.value[:response]
14
+ end
15
+
16
+ def context
17
+ self.value[:context]
18
+ end
19
+
20
+ def model
21
+ self.value[:model]
22
+ end
23
+
24
+ def generate(prompt, &block)
25
+ self.class.post(self.resource, prompt: prompt, context: self.context, model: self.model, &block)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ module Async
7
+ module Ollama
8
+ VERSION = "0.1.0"
9
+ end
10
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require 'async/rest/wrapper/generic'
7
+ require 'async/rest/wrapper/json'
8
+
9
+ require 'protocol/http/body/wrapper'
10
+ require 'protocol/http/body/buffered'
11
+
12
+ require 'json'
13
+
14
+ module Async
15
+ module Ollama
16
+ class Wrapper < Async::REST::Wrapper::Generic
17
+ APPLICATION_JSON = "application/json"
18
+ APPLICATION_JSON_STREAM = "application/x-ndjson"
19
+
20
+ def prepare_request(request, payload)
21
+ request.headers.add('accept', APPLICATION_JSON)
22
+ request.headers.add('accept', APPLICATION_JSON_STREAM)
23
+
24
+ if payload
25
+ request.headers['content-type'] = APPLICATION_JSON
26
+
27
+ request.body = ::Protocol::HTTP::Body::Buffered.new([
28
+ ::JSON.dump(payload)
29
+ ])
30
+ end
31
+ end
32
+
33
+ class StreamingResponseParser < ::Protocol::HTTP::Body::Wrapper
34
+ def initialize(...)
35
+ super
36
+
37
+ @buffer = String.new.b
38
+ @offset = 0
39
+
40
+ @response = String.new
41
+ @value = {response: @response}
42
+ end
43
+
44
+ def read
45
+ return if @buffer.nil?
46
+
47
+ while true
48
+ if index = @buffer.index("\n", @offset)
49
+ line = @buffer.byteslice(@offset, index - @offset)
50
+ @buffer = @buffer.byteslice(index + 1, @buffer.bytesize - index - 1)
51
+ @offset = 0
52
+
53
+ return ::JSON.parse(line, symbolize_names: true)
54
+ end
55
+
56
+ if chunk = super
57
+ @buffer << chunk
58
+ else
59
+ return nil if @buffer.empty?
60
+
61
+ line = @buffer
62
+ @buffer = nil
63
+ @offset = 0
64
+
65
+ return ::JSON.parse(line, symbolize_names: true)
66
+ end
67
+ end
68
+ end
69
+
70
+ def each
71
+ super do |line|
72
+ token = line.delete(:response)
73
+ @response << token
74
+ @value.merge!(line)
75
+
76
+ yield token
77
+ end
78
+ end
79
+
80
+ def join
81
+ self.each{}
82
+
83
+ return @value
84
+ end
85
+ end
86
+
87
+ def parser_for(response)
88
+ case response.headers['content-type']
89
+ when APPLICATION_JSON
90
+ return Async::REST::Wrapper::JSON::Parser
91
+ when APPLICATION_JSON_STREAM
92
+ return StreamingResponseParser
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require_relative 'ollama/version'
7
+ require_relative 'ollama/client'
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2024, by Samuel Williams.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,27 @@
1
+ # Async::Ollama
2
+
3
+ Provides an interface for accessing the Ollama HTTP interface.
4
+
5
+ [![Development Status](https://github.com/socketry/async-ollama/workflows/Test/badge.svg)](https://github.com/socketry/async-ollama/actions?workflow=Test)
6
+
7
+ ## Usage
8
+
9
+ Please see the [project documentation](https://socketry.github.io/async-ollama/) for more details.
10
+
11
+ ## Contributing
12
+
13
+ We welcome contributions to this project.
14
+
15
+ 1. Fork it.
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
18
+ 4. Push to the branch (`git push origin my-new-feature`).
19
+ 5. Create new Pull Request.
20
+
21
+ ### Developer Certificate of Origin
22
+
23
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
24
+
25
+ ### Contributor Covenant
26
+
27
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-ollama
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ bindir: bin
9
+ cert_chain:
10
+ - |
11
+ -----BEGIN CERTIFICATE-----
12
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
13
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
14
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
15
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
16
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnN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XmnW/
32
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
33
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
34
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
35
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
36
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
37
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
38
+ -----END CERTIFICATE-----
39
+ date: 2024-04-09 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: async
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: async-rest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.0
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - lib/async/ollama.rb
74
+ - lib/async/ollama/client.rb
75
+ - lib/async/ollama/generate.rb
76
+ - lib/async/ollama/version.rb
77
+ - lib/async/ollama/wrapper.rb
78
+ - license.md
79
+ - readme.md
80
+ homepage: https://github.com/socketry/async-ollama
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ documentation_uri: https://socketry.github.io/falcon/
85
+ source_code_uri: https://github.com/socketry/async-ollama.git
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '3.1'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.6.0.dev
101
+ specification_version: 4
102
+ summary: A asynchronous interface to the ollama chat service
103
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ [1�b�͆���g�[�Qߞuq��xvV���s\*�$��h,NmE�5�"�f���'Y_�$u��2��}o�Ð� �837���Ȋ0�xQ/�rY��C��=�Ǘ�?�[�l��.ٱ�j4�fJ�?�Pu� ���e�c*��r�tˑ[ �K� �i"Z&�;(݂���Ȗm|�$<ݱ$C�
2
+ l�h,�4�0_���NEE�u�>s@"���P���j�