Skip to content

Commit 29f042b

Browse files
committed
Modernize gem.
1 parent ac81807 commit 29f042b

File tree

15 files changed

+139
-40
lines changed

15 files changed

+139
-40
lines changed

Diff for: .github/workflows/documentation-coverage.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Documentation Coverage
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
COVERAGE: PartialSummary
11+
12+
jobs:
13+
validate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: "3.3"
21+
bundler-cache: true
22+
23+
- name: Validate coverage
24+
timeout-minutes: 5
25+
run: bundle exec bake decode:index:coverage lib

Diff for: .github/workflows/rubocop.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: RuboCop
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: ruby
20+
bundler-cache: true
21+
22+
- name: Run RuboCop
23+
timeout-minutes: 10
24+
run: bundle exec rubocop

Diff for: .github/workflows/coverage.yaml renamed to .github/workflows/test-coverage.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Coverage
1+
name: Test Coverage
22

33
on: [push, pull_request]
44

@@ -39,7 +39,7 @@ jobs:
3939
timeout-minutes: 5
4040
run: bundle exec bake test
4141

42-
- uses: actions/upload-artifact@v3
42+
- uses: actions/upload-artifact@v4
4343
with:
4444
name: coverage-${{matrix.os}}-${{matrix.ruby}}
4545
path: .covered.db
@@ -55,7 +55,7 @@ jobs:
5555
ruby-version: "3.3"
5656
bundler-cache: true
5757

58-
- uses: actions/download-artifact@v3
58+
- uses: actions/download-artifact@v4
5959

6060
- name: Validate coverage
6161
timeout-minutes: 5

Diff for: .rubocop.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
4+
Layout/IndentationStyle:
5+
Enabled: true
6+
EnforcedStyle: tabs
7+
8+
Layout/InitialIndentation:
9+
Enabled: true
10+
11+
Layout/IndentationWidth:
12+
Enabled: true
13+
Width: 1
14+
15+
Layout/IndentationConsistency:
16+
Enabled: true
17+
EnforcedStyle: normal
18+
19+
Layout/BlockAlignment:
20+
Enabled: true
21+
22+
Layout/EndAlignment:
23+
Enabled: true
24+
EnforcedStyleAlignWith: start_of_line
25+
26+
Layout/BeginEndAlignment:
27+
Enabled: true
28+
EnforcedStyleAlignWith: start_of_line
29+
30+
Layout/ElseAlignment:
31+
Enabled: true
32+
33+
Layout/DefEndAlignment:
34+
Enabled: true
35+
36+
Layout/CaseIndentation:
37+
Enabled: true
38+
39+
Layout/CommentIndentation:
40+
Enabled: true
41+
42+
Layout/EmptyLinesAroundClassBody:
43+
Enabled: true
44+
45+
Layout/EmptyLinesAroundModuleBody:
46+
Enabled: true
47+
48+
Style/FrozenStringLiteralComment:
49+
Enabled: true
50+
51+
Style/StringLiterals:
52+
Enabled: true
53+
EnforcedStyle: double_quotes

Diff for: async-ollama.gemspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
1010
spec.authors = ["Samuel Williams"]
1111
spec.license = "MIT"
1212

13-
spec.cert_chain = ['release.cert']
14-
spec.signing_key = File.expand_path('~/.gem/release.pem')
13+
spec.cert_chain = ["release.cert"]
14+
spec.signing_key = File.expand_path("~/.gem/release.pem")
1515

1616
spec.homepage = "https://github.com/socketry/async-ollama"
1717

@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
2020
"source_code_uri" => "https://github.com/socketry/async-ollama.git",
2121
}
2222

23-
spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
23+
spec.files = Dir.glob(["{lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)
2424

2525
spec.required_ruby_version = ">= 3.1"
2626

2727
spec.add_dependency "async"
28-
spec.add_dependency "async-rest", "~> 0.13.0"
28+
spec.add_dependency "async-rest", "~> 0.15"
2929
end

Diff for: config/sus.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'covered/sus'
6+
require "covered/sus"
77
include Covered::Sus

Diff for: examples/chat.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# Released under the MIT License.
55
# Copyright, 2024, by Samuel Williams.
66

7-
require_relative 'lib/async/ollama'
7+
require_relative "lib/async/ollama"
88

9-
require 'console'
9+
require "console"
1010

1111
terminal = Console::Terminal.for($stdout)
1212
terminal[:reply] = terminal.style(:blue)

Diff for: examples/conversation.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# Released under the MIT License.
55
# Copyright, 2024, by Samuel Williams.
66

7-
require_relative '../lib/async/ollama'
7+
require_relative "../lib/async/ollama"
88

9-
require 'console'
9+
require "console"
1010

1111
class Entity
1212
def initialize(client, name, background)

Diff for: gems.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
group :test do
1818
gem "sus"
1919
gem "covered"
20+
gem "decode"
21+
gem "rubocop"
2022

2123
gem "sus-fixtures-async"
2224

2325
gem "bake-test"
2426
gem "bake-test-external"
2527
end
26-

Diff for: lib/async/ollama.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require_relative 'ollama/version'
7-
require_relative 'ollama/client'
6+
require_relative "ollama/version"
7+
require_relative "ollama/client"

Diff for: lib/async/ollama/client.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'async/rest/resource'
7-
require_relative 'generate'
6+
require "async/rest/resource"
7+
require_relative "generate"
88

99
module Async
1010
module Ollama
1111
# Represents a connection to the Ollama service.
1212
class Client < Async::REST::Resource
1313
# The default endpoint to connect to.
14-
ENDPOINT = Async::HTTP::Endpoint.parse('http://localhost:11434')
14+
ENDPOINT = Async::HTTP::Endpoint.parse("http://localhost:11434")
1515

1616
# Generate a response from the given prompt.
1717
# @parameter prompt [String] The prompt to generate a response from.
1818
def generate(prompt, **options, &block)
1919
options[:prompt] = prompt
20-
options[:model] ||= 'llama3'
20+
options[:model] ||= "llama3"
2121

22-
Generate.post(self.with(path: '/api/generate'), options, &block)
22+
Generate.post(self.with(path: "/api/generate"), options, &block)
2323
end
2424
end
2525
end

Diff for: lib/async/ollama/generate.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'async/rest/representation'
7-
require_relative 'wrapper'
6+
require "async/rest/representation"
7+
require_relative "wrapper"
88

99
module Async
1010
module Ollama

Diff for: lib/async/ollama/wrapper.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'async/rest/wrapper/generic'
7-
require 'async/rest/wrapper/json'
6+
require "async/rest/wrapper/generic"
7+
require "async/rest/wrapper/json"
88

9-
require 'protocol/http/body/wrapper'
10-
require 'protocol/http/body/buffered'
9+
require "protocol/http/body/wrapper"
10+
require "protocol/http/body/buffered"
1111

12-
require 'json'
12+
require "json"
1313

1414
module Async
1515
module Ollama
@@ -18,11 +18,11 @@ class Wrapper < Async::REST::Wrapper::Generic
1818
APPLICATION_JSON_STREAM = "application/x-ndjson"
1919

2020
def prepare_request(request, payload)
21-
request.headers.add('accept', APPLICATION_JSON)
22-
request.headers.add('accept', APPLICATION_JSON_STREAM)
21+
request.headers.add("accept", APPLICATION_JSON)
22+
request.headers.add("accept", APPLICATION_JSON_STREAM)
2323

2424
if payload
25-
request.headers['content-type'] = APPLICATION_JSON
25+
request.headers["content-type"] = APPLICATION_JSON
2626

2727
request.body = ::Protocol::HTTP::Body::Buffered.new([
2828
::JSON.dump(payload)
@@ -85,7 +85,7 @@ def join
8585
end
8686

8787
def parser_for(response)
88-
case response.headers['content-type']
88+
case response.headers["content-type"]
8989
when APPLICATION_JSON
9090
return Async::REST::Wrapper::JSON::Parser
9191
when APPLICATION_JSON_STREAM

Diff for: test/async/ollama.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'async/ollama'
6+
require "async/ollama"
77

88
describe Async::Ollama do
99
it "should have a version number" do

Diff for: test/async/ollama/client.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6-
require 'async/ollama'
7-
require 'sus/fixtures/async/reactor_context'
6+
require "async/ollama"
7+
require "sus/fixtures/async/reactor_context"
88

99
describe Async::Ollama::Client do
1010
include Sus::Fixtures::Async::ReactorContext
1111

1212
attr :client
1313

14-
def before
15-
super
16-
14+
before do
1715
@client = Async::Ollama::Client.open
1816
end
1917

20-
def after
18+
after do
2119
@client.close
22-
23-
super
2420
end
2521

2622
it "can connect to the default endpoint" do

0 commit comments

Comments
 (0)