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
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Embedding, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ each_model(EMBEDDING_MODELS) do |provider, model, model_info|
9
+ it "#{provider}/#{model} embeds one text" do
10
+ embedding = RubyLLM.embed(
11
+ "Ruby is a programmer's best friend",
12
+ model: model,
13
+ provider: provider,
14
+ assume_model_exists: true
15
+ )
16
+
17
+ expect(embedding.vectors).to be_an(Array)
18
+ expect(embedding.vectors.first).to be_a(Numeric)
19
+ expect(embedding.model).to eq(model)
20
+ expect(embedding.tokens.input.to_i).to be >= 0
21
+ end
22
+
23
+ it "#{provider}/#{model} embeds several texts" do
24
+ embeddings = RubyLLM.embed(
25
+ %w[Ruby Python JavaScript],
26
+ model: model,
27
+ provider: provider,
28
+ assume_model_exists: true
29
+ )
30
+
31
+ expect(embeddings.vectors.size).to eq(3)
32
+ expect(embeddings.vectors).to all(be_an(Array))
33
+ end
34
+
35
+ next unless model_info[:dimensions]
36
+
37
+ it "#{provider}/#{model} supports custom dimensions" do
38
+ embedding = RubyLLM.embed(
39
+ 'Ruby',
40
+ model: model,
41
+ provider: provider,
42
+ assume_model_exists: true,
43
+ dimensions: model_info[:dimensions]
44
+ )
45
+
46
+ expect(embedding.vectors.length).to eq(model_info[:dimensions])
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Image, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ each_model(IMAGE_GENERATION_MODELS) do |provider, model, model_info|
9
+ it "#{provider}/#{model} paints an image" do
10
+ image = RubyLLM.paint(
11
+ 'a siamese cat',
12
+ model: model,
13
+ provider: provider,
14
+ assume_model_exists: true,
15
+ provider_options: model_info.fetch(:provider_options, {})
16
+ )
17
+
18
+ expect(image.mime_type).to include('image')
19
+ expect(image.model).to eq(model)
20
+ expect(image.to_blob.bytesize).to be > 1000
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Models do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ it 'expects generated providers to add registry metadata before use' do
9
+ expect(RubyLLM::Providers::Synap402.assume_models_exist?).to be(false)
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Moderation, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ each_model(MODERATION_MODELS) do |provider, model|
9
+ it "#{provider}/#{model} moderates content" do
10
+ moderation = RubyLLM.moderate(
11
+ 'This is a safe message',
12
+ model: model,
13
+ provider: provider,
14
+ assume_model_exists: true
15
+ )
16
+
17
+ expect(moderation).to be_a(described_class)
18
+ expect(moderation.results).to all(be_a(RubyLLM::Moderation::Result))
19
+ expect(moderation.flagged?).to be(true).or be(false)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Providers::Synap402 do
6
+ subject(:provider) { described_class.new(config) }
7
+
8
+ let(:config) do
9
+ RubyLLM::Configuration.new.tap do |provider_config|
10
+ provider_config.synap402_api_key = 'test-key'
11
+ provider_config.synap402_api_base = 'https://example.test/v1'
12
+ end
13
+ end
14
+
15
+ it 'is registered with RubyLLM' do
16
+ expect(RubyLLM::Provider.resolve(:synap402)).to eq(described_class)
17
+ end
18
+
19
+ it 'registers a default protocol' do
20
+ expect(described_class.protocols).to include(chat_completions: described_class::ChatCompletions)
21
+ end
22
+
23
+ it 'declares provider configuration' do
24
+ expect(described_class.configuration_options).to eq(%i[synap402_api_key synap402_api_base])
25
+ expect(described_class.configuration_requirements).to eq(%i[synap402_api_key])
26
+ end
27
+
28
+ it 'uses configured API base and bearer token' do
29
+ expect(provider.api_base).to eq('https://example.test/v1')
30
+ expect(provider.headers).to eq('Authorization' => 'Bearer test-key')
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Rerank, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ each_model(RERANK_MODELS) do |provider, model|
9
+ it "#{provider}/#{model} orders documents by relevance" do
10
+ rerank = RubyLLM.rerank(
11
+ 'What is the capital of the United States?',
12
+ ['Carson City is the capital of Nevada.', 'Washington, D.C. is the capital of the United States.'],
13
+ model: model,
14
+ provider: provider,
15
+ assume_model_exists: true
16
+ )
17
+
18
+ expect(rerank.results.first.document).to include('Washington')
19
+ expect(rerank.results.first.score).to be > rerank.results.last.score
20
+ expect(rerank.results.map(&:index)).to contain_exactly(0, 1)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Speech, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ each_model(SPEECH_MODELS) do |provider, model, model_info|
9
+ it "#{provider}/#{model} speaks" do
10
+ speech = RubyLLM.speak(
11
+ 'Ruby is a programming language designed for developer happiness.',
12
+ model: model,
13
+ provider: provider,
14
+ assume_model_exists: true,
15
+ voice: model_info[:voice],
16
+ format: model_info[:format]
17
+ )
18
+
19
+ expect(speech.data).to be_a(String)
20
+ expect(speech.data.bytesize).to be > 1000
21
+ expect(speech.model).to eq(model)
22
+ expect(speech.mime_type).to start_with('audio/')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RubyLLM::Video, :live do
6
+ include_context 'with configured RubyLLM'
7
+
8
+ before do
9
+ RubyLLM.config.video_generation_poll_interval = VCR.current_cassette&.recording? ? 5 : 0
10
+ end
11
+
12
+ each_model(VIDEO_GENERATION_MODELS) do |provider, model, model_info|
13
+ it "#{provider}/#{model} animates a video" do
14
+ video = RubyLLM.animate(
15
+ 'a calm ocean wave at sunset',
16
+ model: model,
17
+ provider: provider,
18
+ assume_model_exists: true,
19
+ provider_options: model_info.fetch(:provider_options, {})
20
+ )
21
+
22
+ expect(video.mime_type).to include('video')
23
+ expect(video.url || video.data).not_to be_nil
24
+ expect(video.to_blob.bytesize).to be > 10_000
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'dotenv/load'
5
+ require 'fileutils'
6
+
7
+ require 'vcr'
8
+ require 'ruby_llm/providers/synap402'
9
+ require 'webmock/rspec'
10
+
11
+ Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
12
+
13
+ RSpec.configure do |config|
14
+ config.disable_monkey_patching!
15
+ config.expect_with(:rspec) { |expectations| expectations.syntax = :expect }
16
+ config.order = :random
17
+ Kernel.srand config.seed
18
+
19
+ config.around(:each, :live) do |example|
20
+ cassette_name = example.full_description.downcase.gsub(/[^a-z0-9]+/, '_').delete_prefix('_').delete_suffix('_')
21
+ cassette_path = File.join(VCR.configuration.cassette_library_dir, "#{cassette_name}.yml")
22
+
23
+ VCR.use_cassette(cassette_name) { example.run }
24
+ FileUtils.rm_f(cassette_path) if example.exception
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Live contract matrix: real Synap402 model ids per operation (see models.json for the full catalog).
4
+ PROVIDER = :synap402
5
+ CHAT_MODELS = [
6
+ { provider: :synap402, model: 'gpt-oss-20b' }
7
+ ].freeze
8
+ TOOL_MODELS = [
9
+ { provider: :synap402, model: 'qwen3-coder-30b' }
10
+ ].freeze
11
+ STRUCTURED_OUTPUT_MODELS = TOOL_MODELS
12
+
13
+ EMBEDDING_MODELS = [
14
+ { provider: :synap402, model: 'qwen3-embedding-0.6b' }
15
+ ].freeze
16
+ IMAGE_GENERATION_MODELS = [].freeze
17
+ SPEECH_MODELS = [].freeze
18
+ VIDEO_GENERATION_MODELS = [].freeze
19
+ MODERATION_MODELS = [].freeze
20
+ RERANK_MODELS = [].freeze
21
+
22
+ def each_model(models)
23
+ models.each { |model_info| yield model_info[:provider], model_info[:model], model_info }
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context 'with configured RubyLLM' do
4
+ before do
5
+ RubyLLM.configure do |config|
6
+ config.synap402_api_key = ENV.fetch('SYNAP402_API_KEY', '').then { |key| key.empty? ? 'test' : key }
7
+ config.synap402_api_base = ENV.fetch('SYNAP402_API_BASE', 'https://synap402.com/v1')
8
+ config.max_retries = 0
9
+ config.retry_backoff_factor = 0
10
+ config.retry_interval = 0
11
+ config.retry_interval_randomness = 0
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ VCR.configure do |config|
4
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ config.hook_into :webmock
6
+ config.default_cassette_options = { record: ENV['CI'] ? :none : :once }
7
+ config.allow_http_connections_when_no_cassette = true
8
+ config.filter_sensitive_data('<SYNAP402_API_KEY>') { ENV.fetch('SYNAP402_API_KEY', nil) }
9
+ config.filter_sensitive_data('<SYNAP402_API_BASE>') { ENV.fetch('SYNAP402_API_BASE', nil) }
10
+
11
+ config.before_record do |interaction|
12
+ next unless interaction.request.headers['Authorization']
13
+
14
+ interaction.request.headers['Authorization'] = ['Bearer <AUTH_TOKEN>']
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_llm-providers-synap402
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Linkrra
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ruby_llm
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "2.2"
20
+ -
21
+ - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: "3"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ -
29
+ - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "2.2"
32
+ -
33
+ - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: "3"
36
+ description: "Adds Synap402 (https://synap402.com) to RubyLLM: chat, streaming, tools, structured output and embeddings, with a model catalog from the live /v1/models endpoint."
37
+ email:
38
+ - weare@linkrra.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .flayignore
44
+ - .github/workflows/ci.yml
45
+ - .github/workflows/gitleaks.yml
46
+ - .github/workflows/release.yml
47
+ - .overcommit.yml
48
+ - .rspec
49
+ - .rubocop.yml
50
+ - Archspec.rb
51
+ - LICENSE
52
+ - README.md
53
+ - lib/ruby_llm/providers/synap402.rb
54
+ - lib/ruby_llm/providers/synap402/models.rb
55
+ - models.json
56
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_can_handle_a_multi_turn_conversation.yml
57
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_can_have_a_basic_conversation.yml
58
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_returns_the_raw_response.yml
59
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_gpt_oss_20b_supports_streaming_responses.yml
60
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_qwen3_coder_30b_can_use_tools.yml
61
+ - spec/fixtures/vcr_cassettes/rubyllm_chat_synap402_qwen3_coder_30b_returns_structured_output.yml
62
+ - spec/fixtures/vcr_cassettes/rubyllm_embedding_synap402_qwen3_embedding_0_6b_embeds_one_text.yml
63
+ - spec/fixtures/vcr_cassettes/rubyllm_embedding_synap402_qwen3_embedding_0_6b_embeds_several_texts.yml
64
+ - spec/ruby_llm/chat_schema_spec.rb
65
+ - spec/ruby_llm/chat_spec.rb
66
+ - spec/ruby_llm/chat_streaming_spec.rb
67
+ - spec/ruby_llm/chat_tools_spec.rb
68
+ - spec/ruby_llm/embedding_spec.rb
69
+ - spec/ruby_llm/image_spec.rb
70
+ - spec/ruby_llm/models_spec.rb
71
+ - spec/ruby_llm/moderation_spec.rb
72
+ - spec/ruby_llm/providers/synap402_spec.rb
73
+ - spec/ruby_llm/rerank_spec.rb
74
+ - spec/ruby_llm/speech_spec.rb
75
+ - spec/ruby_llm/video_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/support/models.rb
78
+ - spec/support/rubyllm_configuration.rb
79
+ - spec/support/vcr_configuration.rb
80
+ homepage: "https://github.com/weare-linkrra/ruby_llm-providers-synap402"
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: "https://github.com/weare-linkrra/ruby_llm-providers-synap402"
85
+ source_code_uri: "https://github.com/weare-linkrra/ruby_llm-providers-synap402"
86
+ changelog_uri: "https://github.com/weare-linkrra/ruby_llm-providers-synap402/releases"
87
+ bug_tracker_uri: "https://github.com/weare-linkrra/ruby_llm-providers-synap402/issues"
88
+ rubygems_mfa_required: "true"
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ -
95
+ - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "3.2"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ -
101
+ - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ requirements: []
105
+ rubygems_version: 4.1.0
106
+ specification_version: 4
107
+ summary: "RubyLLM provider for Synap402, an OpenAI-compatible API for open models."
108
+ test_files: []