ruby_llm-providers-apfel 0.1.0 → 0.2.0
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/.github/workflows/ci.yml +2 -5
- data/.rubocop.yml +1 -1
- data/README.md +9 -6
- data/lib/ruby_llm/providers/apfel/version.rb +1 -1
- data/lib/ruby_llm/providers/apfel.rb +15 -3
- data/spec/ruby_llm/providers/apfel_spec.rb +20 -1
- data/spec/support/rubyllm_configuration.rb +2 -2
- metadata +2 -3
- data/.github/workflows/release.yml +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8e88420fe62866b9da1771c2e574267f9e6ee8a31638b3b4731d490714c94f4
|
|
4
|
+
data.tar.gz: 8aa4dd1476384cad4b1330634d19da240a619e4c8add5a68d040e24d6278885c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80e08d7afcfab3104c5dd001f710f61d428279b101a5eab8b90c760b24ea7a11855280c68004474e2fc5ccbda49174569116aa9b5a57952429bf070a3aaa634e
|
|
7
|
+
data.tar.gz: '0964193abab2e686630ecc6c59d7a7013c941cf3c2dcdeef84ebdd781862c9254841bce5891c5e35296038a9236b2ba1f0c8a73f22cddfc8ed51561beb573239'
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -16,7 +16,8 @@ jobs:
|
|
|
16
16
|
strategy:
|
|
17
17
|
fail-fast: false
|
|
18
18
|
matrix:
|
|
19
|
-
|
|
19
|
+
# Non-EOL Rubies only; must match the gemspec's required_ruby_version.
|
|
20
|
+
ruby-version: ["3.3", "3.4", "4.0"]
|
|
20
21
|
steps:
|
|
21
22
|
- uses: actions/checkout@v6
|
|
22
23
|
|
|
@@ -26,7 +27,3 @@ jobs:
|
|
|
26
27
|
bundler-cache: true
|
|
27
28
|
|
|
28
29
|
- run: bundle exec rake
|
|
29
|
-
if: matrix.ruby-version != '3.1'
|
|
30
|
-
|
|
31
|
-
- run: bundle exec rake rubocop flay spec
|
|
32
|
-
if: matrix.ruby-version == '3.1'
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
|
@@ -41,21 +41,24 @@ Add this line to your application's Gemfile:
|
|
|
41
41
|
gem 'ruby_llm-providers-apfel', require: 'ruby_llm/providers/apfel'
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
The provider works out of the box against Apfel's default address
|
|
45
|
+
(`http://127.0.0.1:11434/v1`) with no API key, so no configuration is required:
|
|
45
46
|
|
|
46
47
|
```ruby
|
|
47
48
|
require 'ruby_llm/providers/apfel'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Configure it only to override the defaults:
|
|
48
52
|
|
|
53
|
+
```ruby
|
|
49
54
|
RubyLLM.configure do |config|
|
|
50
|
-
|
|
55
|
+
# Only needed when the server listens somewhere else
|
|
56
|
+
config.apfel_api_base = ENV.fetch('APFEL_API_BASE', nil)
|
|
51
57
|
# Only needed if you started `apfel --serve --token <value>`
|
|
52
|
-
config.apfel_api_key = ENV
|
|
58
|
+
config.apfel_api_key = ENV.fetch('APFEL_API_KEY', nil)
|
|
53
59
|
end
|
|
54
60
|
```
|
|
55
61
|
|
|
56
|
-
Since Apfel runs locally with no API key required, `apfel_api_key` can be left unset unless you
|
|
57
|
-
started the server with `--token`.
|
|
58
|
-
|
|
59
62
|
## Usage
|
|
60
63
|
|
|
61
64
|
```ruby
|
|
@@ -6,8 +6,14 @@ require 'ruby_llm/providers/apfel/connection_guard'
|
|
|
6
6
|
|
|
7
7
|
module RubyLLM
|
|
8
8
|
module Providers
|
|
9
|
-
# Apfel
|
|
9
|
+
# Apfel — Apple's on-device Foundation Model (AFM) exposed as a local
|
|
10
|
+
# OpenAI-compatible server by the `apfel` CLI (`apfel --serve`).
|
|
11
|
+
# Works out of the box against http://127.0.0.1:11434/v1 — no API key
|
|
12
|
+
# required (set apfel_api_key only when the server was started with
|
|
13
|
+
# `apfel --serve --token <value>`).
|
|
10
14
|
class Apfel < Provider
|
|
15
|
+
DEFAULT_API_BASE = 'http://127.0.0.1:11434/v1'
|
|
16
|
+
|
|
11
17
|
# Apfel's ChatCompletions protocol.
|
|
12
18
|
class ChatCompletions < Protocols::ChatCompletions
|
|
13
19
|
def models_url
|
|
@@ -23,10 +29,12 @@ module RubyLLM
|
|
|
23
29
|
end
|
|
24
30
|
|
|
25
31
|
def api_base
|
|
26
|
-
@config.apfel_api_base ||
|
|
32
|
+
@config.apfel_api_base || DEFAULT_API_BASE
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
def headers
|
|
36
|
+
return {} unless @config.apfel_api_key
|
|
37
|
+
|
|
30
38
|
{ 'Authorization' => "Bearer #{@config.apfel_api_key}" }
|
|
31
39
|
end
|
|
32
40
|
|
|
@@ -36,7 +44,11 @@ module RubyLLM
|
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
def configuration_requirements
|
|
39
|
-
|
|
47
|
+
[]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def local?
|
|
51
|
+
true
|
|
40
52
|
end
|
|
41
53
|
|
|
42
54
|
# Use this only when the provider has no model-listing endpoint.
|
|
@@ -22,11 +22,30 @@ RSpec.describe RubyLLM::Providers::Apfel do
|
|
|
22
22
|
|
|
23
23
|
it 'declares provider configuration' do
|
|
24
24
|
expect(described_class.configuration_options).to eq(%i[apfel_api_key apfel_api_base])
|
|
25
|
-
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'requires no configuration — Apfel runs locally without an API key' do
|
|
28
|
+
expect(described_class.configuration_requirements).to eq([])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'is a local provider' do
|
|
32
|
+
expect(described_class.local?).to be(true)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
it 'uses configured API base and bearer token' do
|
|
29
36
|
expect(provider.api_base).to eq('https://example.test/v1')
|
|
30
37
|
expect(provider.headers).to eq('Authorization' => 'Bearer test-key')
|
|
31
38
|
end
|
|
39
|
+
|
|
40
|
+
context 'without any configuration' do
|
|
41
|
+
let(:config) { RubyLLM::Configuration.new }
|
|
42
|
+
|
|
43
|
+
it 'defaults to the local apfel server' do
|
|
44
|
+
expect(provider.api_base).to eq('http://127.0.0.1:11434/v1')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'sends no Authorization header when no token is configured' do
|
|
48
|
+
expect(provider.headers).to eq({})
|
|
49
|
+
end
|
|
50
|
+
end
|
|
32
51
|
end
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
RSpec.shared_context 'with configured RubyLLM' do
|
|
4
4
|
before do
|
|
5
5
|
RubyLLM.configure do |config|
|
|
6
|
-
config.apfel_api_key = ENV.fetch('APFEL_API_KEY',
|
|
7
|
-
config.apfel_api_base = ENV.fetch('APFEL_API_BASE',
|
|
6
|
+
config.apfel_api_key = ENV.fetch('APFEL_API_KEY', nil)
|
|
7
|
+
config.apfel_api_base = ENV.fetch('APFEL_API_BASE', RubyLLM::Providers::Apfel::DEFAULT_API_BASE)
|
|
8
8
|
config.max_retries = 0
|
|
9
9
|
config.retry_backoff_factor = 0
|
|
10
10
|
config.retry_interval = 0
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_llm-providers-apfel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- madbomber
|
|
@@ -35,7 +35,6 @@ files:
|
|
|
35
35
|
- ".flayignore"
|
|
36
36
|
- ".github/workflows/ci.yml"
|
|
37
37
|
- ".github/workflows/gitleaks.yml"
|
|
38
|
-
- ".github/workflows/release.yml"
|
|
39
38
|
- ".overcommit.yml"
|
|
40
39
|
- ".rspec"
|
|
41
40
|
- ".rubocop.yml"
|
|
@@ -77,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
77
76
|
requirements:
|
|
78
77
|
- - ">="
|
|
79
78
|
- !ruby/object:Gem::Version
|
|
80
|
-
version: '3.
|
|
79
|
+
version: '3.3'
|
|
81
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
81
|
requirements:
|
|
83
82
|
- - ">="
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- "v*"
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
contents: read
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
publish:
|
|
13
|
-
name: Build and publish
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v6
|
|
17
|
-
|
|
18
|
-
- uses: ruby/setup-ruby@v1
|
|
19
|
-
with:
|
|
20
|
-
ruby-version: "3.4"
|
|
21
|
-
bundler-cache: true
|
|
22
|
-
|
|
23
|
-
- run: bundle exec rake
|
|
24
|
-
|
|
25
|
-
- name: Build gem
|
|
26
|
-
run: gem build ruby_llm-providers-apfel.gemspec
|
|
27
|
-
|
|
28
|
-
- name: Publish to RubyGems
|
|
29
|
-
run: |
|
|
30
|
-
mkdir -p "$HOME/.gem"
|
|
31
|
-
touch "$HOME/.gem/credentials"
|
|
32
|
-
chmod 0600 "$HOME/.gem/credentials"
|
|
33
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > "$HOME/.gem/credentials"
|
|
34
|
-
gem push ruby_llm-providers-apfel-*.gem
|
|
35
|
-
env:
|
|
36
|
-
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
|