async-ollama 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/ollama/client.rb +8 -5
- data/lib/async/ollama/generate.rb +8 -2
- data/lib/async/ollama/version.rb +1 -1
- data/lib/async/ollama/wrapper.rb +9 -9
- data/lib/async/ollama.rb +2 -2
- data/readme.md +5 -3
- data.tar.gz.sig +0 -0
- metadata +11 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1e52839defa45793d0099a223261d94f3a5cdfc7d5ca1f859defc943608f65
|
4
|
+
data.tar.gz: e8f8c3aa9e16f368e7f0a68b7be2e66d7d899bc635e31f9f62bd09aa67a434f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b1266042797be83ef0317b42d155b72ff9431cb6368f9f0528aaab435d26e62ced79d326bd76d35a493b32a50c43753db404a3cb4c37e6e0e0a35b0fd5b4759
|
7
|
+
data.tar.gz: ca36a8d5d4762b65de815a8920a7bdf73b30be48a7cecc229d217da2d52566bd76d3909db8895a0f0d103366c38785454aeb29c5d9c454413561b1b7e4302e64
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/async/ollama/client.rb
CHANGED
@@ -3,20 +3,23 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
7
|
-
require_relative
|
6
|
+
require "async/rest/resource"
|
7
|
+
require_relative "generate"
|
8
8
|
|
9
9
|
module Async
|
10
10
|
module Ollama
|
11
11
|
# Represents a connection to the Ollama service.
|
12
12
|
class Client < Async::REST::Resource
|
13
|
-
|
13
|
+
# The default endpoint to connect to.
|
14
|
+
ENDPOINT = Async::HTTP::Endpoint.parse("http://localhost:11434")
|
14
15
|
|
16
|
+
# Generate a response from the given prompt.
|
17
|
+
# @parameter prompt [String] The prompt to generate a response from.
|
15
18
|
def generate(prompt, **options, &block)
|
16
19
|
options[:prompt] = prompt
|
17
|
-
options[:model] ||=
|
20
|
+
options[:model] ||= "llama3"
|
18
21
|
|
19
|
-
Generate.post(self.with(path:
|
22
|
+
Generate.post(self.with(path: "/api/generate"), options, &block)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
@@ -3,24 +3,30 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
7
|
-
require_relative
|
6
|
+
require "async/rest/representation"
|
7
|
+
require_relative "wrapper"
|
8
8
|
|
9
9
|
module Async
|
10
10
|
module Ollama
|
11
11
|
class Generate < Async::REST::Representation[Wrapper]
|
12
|
+
# The response to the prompt.
|
12
13
|
def response
|
13
14
|
self.value[:response]
|
14
15
|
end
|
15
16
|
|
17
|
+
# The conversation context. Used to maintain state between prompts.
|
16
18
|
def context
|
17
19
|
self.value[:context]
|
18
20
|
end
|
19
21
|
|
22
|
+
# The model used to generate the response.
|
20
23
|
def model
|
21
24
|
self.value[:model]
|
22
25
|
end
|
23
26
|
|
27
|
+
# Generate a new response from the given prompt.
|
28
|
+
# @parameter prompt [String] The prompt to generate a response from.
|
29
|
+
# @yields {|response| ...} Optional streaming response.
|
24
30
|
def generate(prompt, &block)
|
25
31
|
self.class.post(self.resource, prompt: prompt, context: self.context, model: self.model, &block)
|
26
32
|
end
|
data/lib/async/ollama/version.rb
CHANGED
data/lib/async/ollama/wrapper.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require "async/rest/wrapper/generic"
|
7
|
+
require "async/rest/wrapper/json"
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
9
|
+
require "protocol/http/body/wrapper"
|
10
|
+
require "protocol/http/body/buffered"
|
11
11
|
|
12
|
-
require
|
12
|
+
require "json"
|
13
13
|
|
14
14
|
module Async
|
15
15
|
module Ollama
|
@@ -18,11 +18,11 @@ module Async
|
|
18
18
|
APPLICATION_JSON_STREAM = "application/x-ndjson"
|
19
19
|
|
20
20
|
def prepare_request(request, payload)
|
21
|
-
request.headers.add(
|
22
|
-
request.headers.add(
|
21
|
+
request.headers.add("accept", APPLICATION_JSON)
|
22
|
+
request.headers.add("accept", APPLICATION_JSON_STREAM)
|
23
23
|
|
24
24
|
if payload
|
25
|
-
request.headers[
|
25
|
+
request.headers["content-type"] = APPLICATION_JSON
|
26
26
|
|
27
27
|
request.body = ::Protocol::HTTP::Body::Buffered.new([
|
28
28
|
::JSON.dump(payload)
|
@@ -85,7 +85,7 @@ module Async
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def parser_for(response)
|
88
|
-
case response.headers[
|
88
|
+
case response.headers["content-type"]
|
89
89
|
when APPLICATION_JSON
|
90
90
|
return Async::REST::Wrapper::JSON::Parser
|
91
91
|
when APPLICATION_JSON_STREAM
|
data/lib/async/ollama.rb
CHANGED
data/readme.md
CHANGED
@@ -8,6 +8,8 @@ Provides an interface for accessing the Ollama HTTP interface.
|
|
8
8
|
|
9
9
|
Please see the [project documentation](https://socketry.github.io/async-ollama/) for more details.
|
10
10
|
|
11
|
+
- [Getting Started](https://socketry.github.io/async-ollama/guides/getting-started/index) - This guide explains how to get started with the `async-ollama` gem.
|
12
|
+
|
11
13
|
## Contributing
|
12
14
|
|
13
15
|
We welcome contributions to this project.
|
@@ -20,8 +22,8 @@ We welcome contributions to this project.
|
|
20
22
|
|
21
23
|
### Developer Certificate of Origin
|
22
24
|
|
23
|
-
|
25
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
24
26
|
|
25
|
-
###
|
27
|
+
### Community Guidelines
|
26
28
|
|
27
|
-
This project is
|
29
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-ollama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
+
autorequire:
|
8
9
|
bindir: bin
|
9
10
|
cert_chain:
|
10
11
|
- |
|
@@ -36,7 +37,7 @@ cert_chain:
|
|
36
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
37
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
38
39
|
-----END CERTIFICATE-----
|
39
|
-
date: 2024-
|
40
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
40
41
|
dependencies:
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: async
|
@@ -58,14 +59,16 @@ dependencies:
|
|
58
59
|
requirements:
|
59
60
|
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
62
|
+
version: '0.15'
|
62
63
|
type: :runtime
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
67
|
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
69
|
+
version: '0.15'
|
70
|
+
description:
|
71
|
+
email:
|
69
72
|
executables: []
|
70
73
|
extensions: []
|
71
74
|
extra_rdoc_files: []
|
@@ -81,8 +84,9 @@ homepage: https://github.com/socketry/async-ollama
|
|
81
84
|
licenses:
|
82
85
|
- MIT
|
83
86
|
metadata:
|
84
|
-
documentation_uri: https://socketry.github.io/
|
87
|
+
documentation_uri: https://socketry.github.io/async-ollama/
|
85
88
|
source_code_uri: https://github.com/socketry/async-ollama.git
|
89
|
+
post_install_message:
|
86
90
|
rdoc_options: []
|
87
91
|
require_paths:
|
88
92
|
- lib
|
@@ -97,7 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
101
|
- !ruby/object:Gem::Version
|
98
102
|
version: '0'
|
99
103
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.5.11
|
105
|
+
signing_key:
|
101
106
|
specification_version: 4
|
102
107
|
summary: A asynchronous interface to the ollama chat service
|
103
108
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|