ruby_llm-providers-qiniu 0.1.1
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 +7 -0
- data/.flayignore +1 -0
- data/.github/workflows/ci.yml +28 -0
- data/.github/workflows/gitleaks.yml +23 -0
- data/.github/workflows/release.yml +36 -0
- data/.overcommit.yml +31 -0
- data/.rspec +2 -0
- data/.rubocop.yml +29 -0
- data/Archspec.rb +14 -0
- data/LICENSE +21 -0
- data/README.md +114 -0
- data/lib/ruby_llm/providers/qiniu.rb +134 -0
- data/models.json +859 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_can_handle_a_multi_turn_conversation.yml +154 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_can_have_a_basic_conversation.yml +61 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_can_use_tools.yml +121 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_returns_structured_output.yml +62 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_returns_the_raw_response.yml +66 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_anthropic_claude_sonnet_5_supports_streaming_responses.yml +105 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_can_handle_a_multi_turn_conversation.yml +127 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_can_have_a_basic_conversation.yml +58 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_can_use_tools.yml +119 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_returns_structured_output.yml +59 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_returns_the_raw_response.yml +58 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_deepseek_deepseek_v4_1_flash_supports_streaming_responses.yml +89 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_can_handle_a_multi_turn_conversation.yml +195 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_can_have_a_basic_conversation.yml +96 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_can_use_tools.yml +165 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_returns_structured_output.yml +97 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_returns_the_raw_response.yml +97 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_gemini_3_1_flash_lite_preview_supports_streaming_responses.yml +70 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_can_handle_a_multi_turn_conversation.yml +194 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_can_have_a_basic_conversation.yml +96 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_can_use_tools.yml +165 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_returns_structured_output.yml +97 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_returns_the_raw_response.yml +97 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_1_flash_lite_supports_streaming_responses.yml +70 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_can_handle_a_multi_turn_conversation.yml +199 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_can_have_a_basic_conversation.yml +97 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_can_use_tools.yml +166 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_returns_structured_output.yml +98 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_returns_the_raw_response.yml +98 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_google_gemini_3_8_flash_supports_streaming_responses.yml +71 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_can_handle_a_multi_turn_conversation.yml +419 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_can_have_a_basic_conversation.yml +210 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_can_use_tools.yml +468 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_returns_structured_output.yml +229 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_returns_the_raw_response.yml +210 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_2_supports_streaming_responses.yml +102 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_can_handle_a_multi_turn_conversation.yml +421 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_can_have_a_basic_conversation.yml +157 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_can_use_tools.yml +469 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_can_handle_a_multi_turn_conversation.yml +422 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_can_have_a_basic_conversation.yml +211 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_can_use_tools.yml +469 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_returns_structured_output.yml +230 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_returns_the_raw_response.yml +211 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_mini_supports_streaming_responses.yml +102 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_returns_structured_output.yml +230 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_returns_the_raw_response.yml +157 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_4_supports_streaming_responses.yml +102 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_can_handle_a_multi_turn_conversation.yml +389 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_can_have_a_basic_conversation.yml +241 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_can_use_tools.yml +437 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_returns_structured_output.yml +214 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_returns_the_raw_response.yml +241 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_5_6_luna_supports_streaming_responses.yml +106 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_can_handle_a_multi_turn_conversation.yml +389 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_can_have_a_basic_conversation.yml +202 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_can_use_tools.yml +437 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_returns_structured_output.yml +221 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_returns_the_raw_response.yml +202 -0
- data/spec/fixtures/vcr_cassettes/rubyllm_chat_qiniu_openai_gpt_6_luna_supports_streaming_responses.yml +112 -0
- data/spec/ruby_llm/chat_schema_spec.rb +30 -0
- data/spec/ruby_llm/chat_spec.rb +35 -0
- data/spec/ruby_llm/chat_streaming_spec.rb +22 -0
- data/spec/ruby_llm/chat_tools_spec.rb +32 -0
- data/spec/ruby_llm/embedding_spec.rb +49 -0
- data/spec/ruby_llm/image_spec.rb +23 -0
- data/spec/ruby_llm/models_spec.rb +11 -0
- data/spec/ruby_llm/moderation_spec.rb +22 -0
- data/spec/ruby_llm/providers/qiniu_spec.rb +103 -0
- data/spec/ruby_llm/rerank_spec.rb +23 -0
- data/spec/ruby_llm/speech_spec.rb +25 -0
- data/spec/ruby_llm/video_spec.rb +27 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/models.rb +30 -0
- data/spec/support/rubyllm_configuration.rb +14 -0
- data/spec/support/vcr_configuration.rb +16 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b5e7836bffa849ff6b9fd54403b700a8dbaeab2a67a74f3c6cf3b6e1a970ec48
|
|
4
|
+
data.tar.gz: 2410a9a181ca32639c239935827a41fff116c115e01ba4904b6d4b785a1ae9a9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 852caaac2b39890efe96174c3597c559649e333a4c942ef2bcfa583e6eb9435950b87d4ec8959062f4b0e6104e634c5777a2d4ed3951e68f56d058943cd29ad7
|
|
7
|
+
data.tar.gz: 6e7b0361b660c2d92321d947f2e40e845a1d8622b63950f599d9f71f5fa1b43c2848de7cb63615a6cbabe6b0677552d35f214452081a6dc94615929970b61ea3
|
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: ["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,23 @@
|
|
|
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@v3
|
|
21
|
+
env:
|
|
22
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
|
|
@@ -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-qiniu.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-qiniu-*.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
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: 4.0
|
|
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/qiniu.rb
|
|
8
|
+
lib/ruby_llm/providers/qiniu/**/*.rb
|
|
9
|
+
],
|
|
10
|
+
namespace: 'RubyLLM::Providers::Qiniu'
|
|
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 Mihuashi
|
|
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,114 @@
|
|
|
1
|
+
# ruby_llm-providers-qiniu (modelink)
|
|
2
|
+
|
|
3
|
+
RubyLLM provider gem for Qiniu's model gateway (documented at
|
|
4
|
+
[docs.modelink.ai](https://docs.modelink.ai) — Modelink is the overseas
|
|
5
|
+
brand of the same service).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'ruby_llm-providers-qiniu', require: 'ruby_llm/providers/qiniu'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then configure the provider:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'ruby_llm/providers/qiniu'
|
|
19
|
+
|
|
20
|
+
RubyLLM.configure do |config|
|
|
21
|
+
config.qiniu_api_key = ENV['QINIU_API_KEY']
|
|
22
|
+
config.qiniu_api_base = ENV.fetch('QINIU_BASE_URL', 'https://api.qnaigc.com')
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Endpoints
|
|
27
|
+
|
|
28
|
+
Pick one regional entry point per deployment; all of them serve the same
|
|
29
|
+
protocols:
|
|
30
|
+
|
|
31
|
+
| Region | Base URL | Use when |
|
|
32
|
+
| ------ | -------- | -------- |
|
|
33
|
+
| Mainland China | `https://api.qnaigc.com` | default; lowest latency for China deployments |
|
|
34
|
+
| Overseas | `https://api.modelink.ai` | overseas deployment or cross-border access |
|
|
35
|
+
| Hybrid | `https://xapi.qnaigc.com` | sharing one entry across protocol-different clients |
|
|
36
|
+
|
|
37
|
+
`qiniu_api_base` is used verbatim — pass the bare host, since each protocol
|
|
38
|
+
path already carries its own version segment (`/v1`, `/bypass/…/v1`, …).
|
|
39
|
+
|
|
40
|
+
## Protocols
|
|
41
|
+
|
|
42
|
+
One provider, several wire formats. For chat, RubyLLM prefers each vendor's
|
|
43
|
+
native bypass channel — Claude models use Anthropic Messages, Gemini models
|
|
44
|
+
use GenerateContent, GPT models use Responses — while every other model and
|
|
45
|
+
all auxiliary operations use the OpenAI-compatible endpoint. Override
|
|
46
|
+
globally with `config.qiniu_protocol = :anthropic` or per call:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
RubyLLM.chat(model: 'deepseek-v3', provider: :qiniu, protocol: :chat_completions)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Protocol | Path | Notes |
|
|
53
|
+
| -------- | ---- | ----- |
|
|
54
|
+
| `:chat_completions` (default) | `POST /v1/chat/completions` | All models; also serves model listing at `GET /v1/models` |
|
|
55
|
+
| `:anthropic` | `POST /v1/messages` | Anthropic Messages compat; accepts every model, gateway adapts per channel |
|
|
56
|
+
| `:anthropic_bypass` | `POST /bypass/anthropic/v1/messages` | Claude only; vendor-native Messages semantics |
|
|
57
|
+
| `:gemini_bypass` | `POST /bypass/vertex/v1/models/{model}:{func}` | Gemini only; native GenerateContent (generateContent / streamGenerateContent) |
|
|
58
|
+
| `:responses` | `POST /bypass/openai/v1/responses` | GPT family; OpenAI Responses API |
|
|
59
|
+
|
|
60
|
+
Only chat is wired up for now — embeddings, images, audio, video, rerank
|
|
61
|
+
and other capabilities raise `RubyLLM::Error` until the corresponding
|
|
62
|
+
endpoints are added.
|
|
63
|
+
|
|
64
|
+
Prefer the compatible dialects for unified multi-model access. Reach for a
|
|
65
|
+
bypass protocol when you depend on vendor-native fields, streaming events,
|
|
66
|
+
or extended capabilities (Extended Thinking, Prompt Caching, Gemini-native
|
|
67
|
+
tools, Responses). Bypass requests still pass through the gateway's auth,
|
|
68
|
+
routing, rate limiting, and billing — "bypass" only skips the unified
|
|
69
|
+
protocol conversion.
|
|
70
|
+
|
|
71
|
+
Authentication is `Authorization: Bearer <api_key>` everywhere (the
|
|
72
|
+
Anthropic paths also accept `X-Api-Key`; Bearer alone is sufficient).
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
model = RubyLLM.models.by_provider(:qiniu).chat_models.first
|
|
78
|
+
chat = RubyLLM.chat(model: model.id)
|
|
79
|
+
response = chat.ask('Hello')
|
|
80
|
+
puts response.content
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Notes
|
|
84
|
+
|
|
85
|
+
- `GET /v1/models` may be called anonymously; the provider still sends
|
|
86
|
+
credentials when configured. The listing is only a partial catalog — it
|
|
87
|
+
omits whole vendors such as Claude, Gemini and GPT and exposes no
|
|
88
|
+
capabilities or pricing — which is why `models.json` is maintained by
|
|
89
|
+
hand from the official docs.
|
|
90
|
+
- Batch inference (`/v1/batchjob/inference`), FAL-format async media
|
|
91
|
+
(`/queue/...`), AK/SK management endpoints, and Volcengine asset signing
|
|
92
|
+
are service-specific APIs this provider does not wrap.
|
|
93
|
+
- The hybrid endpoint converts between protocols but may not preserve every
|
|
94
|
+
vendor-native field or streaming event; verify tool calls, thinking,
|
|
95
|
+
caching, structured output, and multimodal inputs with real requests
|
|
96
|
+
before production use.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
The generator installs the bundle and creates an ignored `.env`. Edit the generated `op read` reference so it points to your 1Password credential. If you do not use the 1Password CLI, replace the expression with the provider key.
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
bundle exec rake
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The packaged `models.json` at the gem root is maintained by hand from the official catalog at [modelink.ai/models](https://modelink.ai/models) — `GET /v1/models` is too thin to generate it, since the listing omits whole vendors (no Claude, Gemini or GPT entries) and carries no context windows, capabilities or pricing. RubyLLM loads that catalog as a fallback when this provider is registered, so applications do not need to combine registry files. The main RubyLLM registry always wins when both catalogs carry the same model. If the API grows a richer listing path, update `models_url` in `lib/ruby_llm/providers/qiniu.rb`.
|
|
107
|
+
|
|
108
|
+
Edit `models.json` directly when you want to update the packaged catalog. `RubyLLM.models.refresh` updates the application's main registry and does not refresh provider gem catalogs.
|
|
109
|
+
|
|
110
|
+
If the packaged catalog is ever dropped, uncomment `assume_models_exist?` in the provider so chats can start against unlisted models.
|
|
111
|
+
|
|
112
|
+
The suite always runs the provider integration specs. The first local run calls the API and records VCR cassettes; CI only replays committed cassettes. A failing example deletes its cassette so the next local run tests the live API again.
|
|
113
|
+
|
|
114
|
+
After updating the catalog, add real model IDs to `spec/support/models.rb`. Keep only the operation matrices the provider supports. The portable contract specs are adapted from [RubyLLM's live specs](https://github.com/crmne/ruby_llm/tree/main/spec/ruby_llm); use those as the reference when your provider needs coverage for another feature or dialect.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruby_llm'
|
|
4
|
+
|
|
5
|
+
module RubyLLM
|
|
6
|
+
module Providers
|
|
7
|
+
# Qiniu API integration (documented at https://docs.modelink.ai —
|
|
8
|
+
# Modelink is the overseas brand of the same gateway).
|
|
9
|
+
#
|
|
10
|
+
# The gateway serves several access styles on the same regional host:
|
|
11
|
+
#
|
|
12
|
+
# - OpenAI Chat Completions compatible API under /v1 (chat and model
|
|
13
|
+
# listing)
|
|
14
|
+
# - Anthropic Messages compatible API at /v1/messages, which accepts
|
|
15
|
+
# every chat model and lets the gateway adapt per-channel
|
|
16
|
+
# - Native protocol bypass endpoints that keep vendor-native wire
|
|
17
|
+
# formats: /bypass/anthropic (Claude only), /bypass/vertex (Gemini),
|
|
18
|
+
# /bypass/openai (Responses and Images)
|
|
19
|
+
#
|
|
20
|
+
# All regional endpoints speak the same protocols; pick one with
|
|
21
|
+
# qiniu_api_base:
|
|
22
|
+
#
|
|
23
|
+
# - https://api.qnaigc.com — mainland China (default)
|
|
24
|
+
# - https://api.modelink.ai — overseas
|
|
25
|
+
# - https://xapi.qnaigc.com — hybrid multi-protocol entry
|
|
26
|
+
class Qiniu < Provider
|
|
27
|
+
# OpenAI Chat Completions-compatible dialect under /v1. This is the
|
|
28
|
+
# default protocol and the only one used for model listing.
|
|
29
|
+
class ChatCompletions < Protocols::ChatCompletions
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def completion_url
|
|
33
|
+
'v1/chat/completions'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def models_url
|
|
37
|
+
'v1/models'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# OpenAI Responses native bypass at /bypass/openai/v1/responses for
|
|
42
|
+
# GPT-family models. count_tokens_url and compaction_url derive from
|
|
43
|
+
# completion_url.
|
|
44
|
+
class ResponsesBypass < Protocols::Responses
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def completion_url
|
|
48
|
+
'bypass/openai/v1/responses'
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Anthropic native bypass at /bypass/anthropic/v1/messages. Claude
|
|
53
|
+
# models only; request and streaming events stay vendor-native.
|
|
54
|
+
class AnthropicBypass < Protocols::Anthropic
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def completion_url
|
|
58
|
+
'bypass/anthropic/v1/messages'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def count_tokens_url
|
|
62
|
+
'bypass/anthropic/v1/messages/count_tokens'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Vertex/Gemini native bypass at /bypass/vertex/v1/models/{m}:{func}.
|
|
67
|
+
# Gemini models only; keeps the GenerateContent wire format.
|
|
68
|
+
class GeminiBypass < Protocols::Gemini
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def completion_url
|
|
72
|
+
vertex_url(super)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def stream_url
|
|
76
|
+
vertex_url(super)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def count_tokens_url
|
|
80
|
+
vertex_url(super)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def vertex_url(path)
|
|
84
|
+
"bypass/vertex/v1/#{path}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
protocol :chat_completions, ChatCompletions
|
|
89
|
+
protocol :anthropic, Protocols::Anthropic
|
|
90
|
+
protocol :responses, ResponsesBypass
|
|
91
|
+
protocol :anthropic_bypass, AnthropicBypass
|
|
92
|
+
protocol :gemini_bypass, GeminiBypass
|
|
93
|
+
|
|
94
|
+
def api_base
|
|
95
|
+
@config.qiniu_api_base || 'https://api.qnaigc.com'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def headers
|
|
99
|
+
{ 'Authorization' => "Bearer #{@config.qiniu_api_key}" }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Chat prefers each vendor's native bypass channel — Claude via
|
|
103
|
+
# Anthropic Messages, Gemini via GenerateContent, GPT via Responses —
|
|
104
|
+
# and everything else uses the OpenAI-compatible endpoint. Auxiliary
|
|
105
|
+
# operations (embeddings, images, audio, …) only exist on the
|
|
106
|
+
# compatible layout. Override globally with config.qiniu_protocol or
|
|
107
|
+
# per call with protocol: (e.g. :anthropic for the Messages compat
|
|
108
|
+
# layer, :chat_completions to force the compatible dialect).
|
|
109
|
+
def protocol_for(model, operation: nil, **)
|
|
110
|
+
return super if operation
|
|
111
|
+
|
|
112
|
+
case model_id_for(model).to_s
|
|
113
|
+
when /claude/i then protocols[:anthropic_bypass]
|
|
114
|
+
when /gemini/i then protocols[:gemini_bypass]
|
|
115
|
+
when %r{(?:\A|/)(?:gpt|o\d)}i then protocols[:responses]
|
|
116
|
+
else super
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
class << self
|
|
121
|
+
def configuration_options
|
|
122
|
+
%i[qiniu_api_key qiniu_api_base]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def configuration_requirements
|
|
126
|
+
%i[qiniu_api_key]
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
RubyLLM::Provider.register :qiniu, RubyLLM::Providers::Qiniu,
|
|
134
|
+
models: File.expand_path('../../../models.json', __dir__)
|