ruby_llm-providers-synap402 0.1.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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.flayignore +1 -0
  3. data/.github/workflows/ci.yml +28 -0
  4. data/.github/workflows/gitleaks.yml +22 -0
  5. data/.github/workflows/release.yml +36 -0
  6. data/.overcommit.yml +31 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +29 -0
  9. data/Archspec.rb +14 -0
  10. data/LICENSE +21 -0
  11. data/README.md +69 -0
  12. data/lib/ruby_llm/providers/synap402/models.rb +109 -0
  13. data/lib/ruby_llm/providers/synap402.rb +41 -0
  14. data/models.json +986 -0
  15. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_can_handle_a_multi_turn_conversation.yml +172 -0
  16. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_can_have_a_basic_conversation.yml +80 -0
  17. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_returns_the_raw_response.yml +81 -0
  18. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_supports_streaming_responses.yml +206 -0
  19. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_qwen3_coder_30b_can_use_tools.yml +160 -0
  20. data/spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_qwen3_coder_30b_returns_structured_output.yml +80 -0
  21. data/spec/fixtures/vcr_cassettes/rubyllm_embedding_synap402_qwen3_embedding_0_6b_embeds_one_text.yml +75 -0
  22. data/spec/fixtures/vcr_cassettes/rubyllm_embedding_synap402_qwen3_embedding_0_6b_embeds_several_texts.yml +74 -0
  23. data/spec/ruby_llm/chat_schema_spec.rb +30 -0
  24. data/spec/ruby_llm/chat_spec.rb +34 -0
  25. data/spec/ruby_llm/chat_streaming_spec.rb +21 -0
  26. data/spec/ruby_llm/chat_tools_spec.rb +33 -0
  27. data/spec/ruby_llm/embedding_spec.rb +49 -0
  28. data/spec/ruby_llm/image_spec.rb +23 -0
  29. data/spec/ruby_llm/models_spec.rb +11 -0
  30. data/spec/ruby_llm/moderation_spec.rb +22 -0
  31. data/spec/ruby_llm/providers/synap402_spec.rb +32 -0
  32. data/spec/ruby_llm/rerank_spec.rb +23 -0
  33. data/spec/ruby_llm/speech_spec.rb +25 -0
  34. data/spec/ruby_llm/video_spec.rb +27 -0
  35. data/spec/spec_helper.rb +26 -0
  36. data/spec/support/models.rb +24 -0
  37. data/spec/support/rubyllm_configuration.rb +14 -0
  38. data/spec/support/vcr_configuration.rb +16 -0
  39. metadata +108 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6e628ee36079d342276e680ee2852e12d8e5b3dda26326d3ff50b4817aef0f2
4
+ data.tar.gz: b90cdf305c9b647cae1195498a41c501ff9c1085d85a8aba380ab9a2fdbe76c9
5
+ SHA512:
6
+ metadata.gz: 13e5fe1c937fc234a895d6f83ff7aa4b6a985c8404c3f7c81552f781e85cc1e916017d711ecf1fb80bf9894c8f30c75ef8221e6f92d7e4eccbcf5f0d2172c6d1
7
+ data.tar.gz: dd9b74eeb3912370573f46b16a72cdf12ae706fe51f995ae5bd4c9dc0ac6ecf6405f21168aafaeee1f4bc85793d98f701129fd1d4b595f9595024fb725ad213c
data/.flayignore ADDED
@@ -0,0 +1 @@
1
+ spec/support/streaming_error_helpers.rb
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ["main"]
6
+ push:
7
+ branches: ["main"]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ name: Ruby ${{ matrix.ruby-version }}
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby-version: ["3.2", "3.3", "3.4", "4.0"]
20
+ steps:
21
+ - uses: actions/checkout@v6
22
+
23
+ - uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true
27
+
28
+ - run: bundle exec rake
@@ -0,0 +1,22 @@
1
+ name: Gitleaks
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ["main"]
6
+ push:
7
+ branches: ["main"]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ scan:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - uses: gitleaks/gitleaks-action@v2
21
+ env:
22
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,36 @@
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-synap402.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-synap402-*.gem
35
+ env:
36
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
data/.overcommit.yml ADDED
@@ -0,0 +1,31 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ auto_correct: true
5
+ on_warn: fail
6
+
7
+ Flay:
8
+ enabled: true
9
+ include:
10
+ - lib/**/*.rb
11
+ - spec/**/*.rb
12
+ mass_threshold: 70
13
+
14
+ ArchSpec:
15
+ enabled: true
16
+ command: ['bundle', 'exec', 'archspec', 'check']
17
+ on_warn: fail
18
+
19
+ RSpec:
20
+ enabled: true
21
+ command: ['bundle', 'exec', 'rspec']
22
+ on_warn: fail
23
+
24
+ TrailingWhitespace:
25
+ enabled: true
26
+ auto_correct: true
27
+
28
+ Gitleaks:
29
+ enabled: true
30
+ required_executable: gitleaks
31
+ command: ['gitleaks', 'protect', '--staged', '--redact', '--verbose']
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ plugins:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ NewCops: enable
8
+ TargetRubyVersion: 3.2
9
+ Exclude:
10
+ - Archspec.rb
11
+ - vendor/**/*
12
+ - gemfiles/**/*
13
+ SuggestExtensions: false
14
+
15
+ Metrics/AbcSize:
16
+ Max: 80
17
+ Metrics/MethodLength:
18
+ Max: 40
19
+ CountAsOne:
20
+ - array
21
+ - hash
22
+ - heredoc
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - spec/**/*.rb
26
+ RSpec/ExampleLength:
27
+ Enabled: false
28
+ RSpec/MultipleExpectations:
29
+ Enabled: false
data/Archspec.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'lib/**/*.rb'
4
+
5
+ component :provider,
6
+ in: %w[
7
+ lib/ruby_llm/providers/synap402.rb
8
+ lib/ruby_llm/providers/synap402/**/*.rb
9
+ ],
10
+ namespace: 'RubyLLM::Providers::Synap402'
11
+
12
+ provider.cannot_reference_constants 'RSpec', 'WebMock', 'VCR'
13
+
14
+ preset :ruby_conventions
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 weare-linkrra
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,69 @@
1
+ # ruby_llm-providers-synap402
2
+
3
+ [RubyLLM](https://rubyllm.com) provider for [Synap402](https://synap402.com): production LLM inference for open models behind one OpenAI-compatible API at `https://synap402.com/v1`.
4
+
5
+ Chat, streaming, tool calls, structured output and embeddings work through RubyLLM's normal interface. The gem ships a model catalog (`models.json`) generated from Synap402's live `/v1/models` endpoint, with context windows, per-million-token prices and capabilities.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ gem 'ruby_llm-providers-synap402', require: 'ruby_llm/providers/synap402'
12
+ ```
13
+
14
+ Get an API key at [synap402.com](https://synap402.com/ai/account.html), then configure:
15
+
16
+ ```ruby
17
+ require 'ruby_llm/providers/synap402'
18
+
19
+ RubyLLM.configure do |config|
20
+ config.synap402_api_key = ENV['SYNAP402_API_KEY']
21
+ # Optional: point at a different deployment.
22
+ # config.synap402_api_base = 'https://synap402.com/v1'
23
+ end
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ chat = RubyLLM.chat(model: 'gpt-oss-20b', provider: :synap402)
30
+ puts chat.ask('What is the capital of France?').content
31
+
32
+ # Streaming
33
+ chat.ask('Write a haiku about Ruby') { |chunk| print chunk.content }
34
+
35
+ # Tools
36
+ class Weather < RubyLLM::Tool
37
+ description 'Gets current weather for a city'
38
+ parameter :city, description: 'City name'
39
+
40
+ def execute(city:) = "Sunny, 21°C in #{city}"
41
+ end
42
+
43
+ RubyLLM.chat(model: 'qwen3-coder-30b', provider: :synap402).with_tools(Weather).ask('Weather in Berlin?')
44
+
45
+ # Embeddings
46
+ RubyLLM.embed("Ruby is a programmer's best friend", model: 'qwen3-embedding-0.6b', provider: :synap402)
47
+
48
+ # Browse the packaged catalog
49
+ RubyLLM.models.by_provider(:synap402).chat_models.map(&:id)
50
+ ```
51
+
52
+ `synap-v1` and `synap-v1-pro` are routers: they pick a model per request and bill at the price of the model that ran. See [synap402.com/models.html](https://synap402.com/models.html) for the current list and prices.
53
+
54
+ ## Development
55
+
56
+ ```sh
57
+ bundle install
58
+ echo 'SYNAP402_API_KEY=your-key' > .env # ignored by git
59
+ bundle exec rake models # refresh models.json from the live /v1/models endpoint
60
+ bundle exec rake # rubocop, flay, archspec, specs
61
+ ```
62
+
63
+ The live contract specs record VCR cassettes on the first local run (with the API key filtered out) and CI replays the committed cassettes. A failing example deletes its cassette, so the next local run calls the API again. The model matrix lives in `spec/support/models.rb`.
64
+
65
+ This gem was scaffolded with `ruby_llm provider-gem` (RubyLLM 2.2.3).
66
+
67
+ ## License
68
+
69
+ MIT. Maintained by [Linkrra](https://synap402.com).
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLLM
4
+ module Providers
5
+ class Synap402 < Provider
6
+ # Parses Synap402's /v1/models catalog. It is OpenAI-shaped, with extra
7
+ # fields: per-million pricing, context length, modalities, and the
8
+ # request parameters each model accepts.
9
+ module Models
10
+ CAPABILITY_PARAMETERS = {
11
+ 'function_calling' => %w[tools tool_choice],
12
+ 'structured_output' => %w[response_format structured_outputs]
13
+ }.freeze
14
+
15
+ PRICE_FIELDS = {
16
+ 'prompt_per_million' => :input_per_million,
17
+ 'completion_per_million' => :output_per_million,
18
+ 'cached_prompt_per_million' => :cache_read_input_per_million
19
+ }.freeze
20
+
21
+ BATCH_PRICE_FIELDS = {
22
+ 'batch_prompt_per_million' => :input_per_million,
23
+ 'batch_completion_per_million' => :output_per_million
24
+ }.freeze
25
+
26
+ module_function
27
+
28
+ def models_url
29
+ 'models'
30
+ end
31
+
32
+ def parse_list_models_response(response, slug)
33
+ Array(response.body['data']).map { |model_data| build_model(model_data, slug) }
34
+ end
35
+
36
+ def build_model(model_data, slug)
37
+ modalities = model_modalities(model_data)
38
+
39
+ Model.new(
40
+ id: model_data['id'],
41
+ name: model_data['name'] || model_data['id'],
42
+ provider: slug,
43
+ family: model_data['id'].include?('/') ? model_data['id'].split('/').first : nil,
44
+ created_at: model_data['created'] ? Time.at(model_data['created']) : nil,
45
+ context_window: model_data['context_length'],
46
+ max_output_tokens: model_data.dig('top_provider', 'max_completion_tokens'),
47
+ modalities: modalities,
48
+ capabilities: model_capabilities(model_data, modalities),
49
+ pricing: model_pricing(model_data, modalities),
50
+ metadata: model_metadata(model_data)
51
+ )
52
+ end
53
+
54
+ def model_modalities(model_data)
55
+ return { input: ['text'], output: ['embeddings'] } if embedding_model?(model_data)
56
+
57
+ input = Array(model_data.dig('architecture', 'input_modalities'))
58
+ output = Array(model_data.dig('architecture', 'output_modalities'))
59
+ { input: input.empty? ? ['text'] : input, output: output.empty? ? ['text'] : output }
60
+ end
61
+
62
+ def embedding_model?(model_data)
63
+ output = Array(model_data.dig('architecture', 'output_modalities'))
64
+ output.include?('embeddings') || model_data['capability'].to_s.match?(/embedding/i)
65
+ end
66
+
67
+ def model_capabilities(model_data, modalities)
68
+ return [] if modalities[:output].include?('embeddings')
69
+
70
+ params = Array(model_data['supported_parameters'])
71
+ capabilities = CAPABILITY_PARAMETERS.filter_map do |capability, names|
72
+ capability if names.any? { |name| params.include?(name) }
73
+ end
74
+ capabilities << 'vision' if modalities[:input].include?('image')
75
+ capabilities
76
+ end
77
+
78
+ def model_pricing(model_data, modalities)
79
+ prices = model_data['pricing'] || {}
80
+ category = modalities[:output].include?('embeddings') ? :embeddings : :text_tokens
81
+ tiers = { standard: tier(prices, PRICE_FIELDS), batch: tier(prices, BATCH_PRICE_FIELDS) }.reject do |_, v|
82
+ v.empty?
83
+ end
84
+ tiers.empty? ? {} : { category => tiers }
85
+ end
86
+
87
+ def tier(prices, fields)
88
+ fields.each_with_object({}) do |(source, target), out|
89
+ value = prices[source].to_f
90
+ out[target] = value if value.positive?
91
+ end
92
+ end
93
+
94
+ def model_metadata(model_data)
95
+ {
96
+ object: model_data['object'],
97
+ owned_by: model_data['owned_by'],
98
+ route: model_data['route'],
99
+ served_by: model_data['served_by'] || model_data['resolves_to'],
100
+ tier: model_data['tier'],
101
+ capability: model_data['capability'],
102
+ data_policy: model_data['data_policy'],
103
+ supported_parameters: model_data['supported_parameters']
104
+ }.compact
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_llm'
4
+ require_relative 'synap402/models'
5
+
6
+ module RubyLLM
7
+ module Providers
8
+ # Synap402 API integration: an OpenAI-compatible endpoint at
9
+ # https://synap402.com/v1 serving open-weight and brokered models.
10
+ class Synap402 < Provider
11
+ # Synap402's ChatCompletions protocol, with a catalog parser that keeps
12
+ # Synap402's pricing, context length, and modality metadata.
13
+ class ChatCompletions < Protocols::ChatCompletions
14
+ include Synap402::Models
15
+ end
16
+
17
+ protocol :chat_completions, ChatCompletions
18
+
19
+ def api_base
20
+ @config.synap402_api_base || 'https://synap402.com/v1'
21
+ end
22
+
23
+ def headers
24
+ { 'Authorization' => "Bearer #{@config.synap402_api_key}" }
25
+ end
26
+
27
+ class << self
28
+ def configuration_options
29
+ %i[synap402_api_key synap402_api_base]
30
+ end
31
+
32
+ def configuration_requirements
33
+ %i[synap402_api_key]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ RubyLLM::Provider.register :synap402, RubyLLM::Providers::Synap402,
41
+ models: File.expand_path('../../../models.json', __dir__)