ruby_llm-providers-groq 2.0.0.pre.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.flayignore +1 -0
  3. data/.github/workflows/ci.yml +30 -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 +57 -0
  12. data/lib/ruby_llm/providers/groq.rb +70 -0
  13. data/models.json +218 -0
  14. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_can_handle_a_multi_turn_conversation.yml +153 -0
  15. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_can_have_a_basic_conversation.yml +75 -0
  16. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_can_use_tools.yml +153 -0
  17. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_returns_structured_output.yml +80 -0
  18. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_returns_the_raw_response.yml +79 -0
  19. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_openai_gpt_oss_120b_supports_streaming_responses.yml +252 -0
  20. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_can_handle_a_multi_turn_conversation.yml +160 -0
  21. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_can_have_a_basic_conversation.yml +77 -0
  22. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_can_use_tools.yml +152 -0
  23. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_returns_structured_output.yml +77 -0
  24. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_returns_the_raw_response.yml +77 -0
  25. data/spec/fixtures/vcr_cassettes/rubyllm_chat_groq_qwen_qwen3_8_27b_supports_streaming_responses.yml +126 -0
  26. data/spec/ruby_llm/chat_schema_spec.rb +30 -0
  27. data/spec/ruby_llm/chat_spec.rb +35 -0
  28. data/spec/ruby_llm/chat_streaming_spec.rb +22 -0
  29. data/spec/ruby_llm/chat_tools_spec.rb +31 -0
  30. data/spec/ruby_llm/embedding_spec.rb +49 -0
  31. data/spec/ruby_llm/image_spec.rb +23 -0
  32. data/spec/ruby_llm/models_spec.rb +11 -0
  33. data/spec/ruby_llm/moderation_spec.rb +22 -0
  34. data/spec/ruby_llm/providers/groq_spec.rb +32 -0
  35. data/spec/ruby_llm/rerank_spec.rb +23 -0
  36. data/spec/ruby_llm/speech_spec.rb +25 -0
  37. data/spec/ruby_llm/video_spec.rb +27 -0
  38. data/spec/spec_helper.rb +26 -0
  39. data/spec/support/models.rb +22 -0
  40. data/spec/support/rubyllm_configuration.rb +14 -0
  41. data/spec/support/vcr_configuration.rb +16 -0
  42. metadata +105 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc8fd696d7d3ef887cd311067e41bc36ac0c202c735a7a1b6eb674e395588bc1
4
+ data.tar.gz: 5be0aa59c8a2d164ec35b374947a8108440cbe37cd762987bb41d2af187cf040
5
+ SHA512:
6
+ metadata.gz: 257873259aabd817b71f2d2f49f1c44c5fe0f10196c4e04c8a5f4ff13a0030d8388b8d38fb263c6a1bdedf1d1511956559b04096ccae548387d197f14e3cffda
7
+ data.tar.gz: 7428bbeeb1302be35d569074f6751971fa048038576d35ab8e80e94e7713bc3d53de4544dc076caa3076790df1b28bd60e9986bdf54c5fe96c4ffd777590476e
data/.flayignore ADDED
@@ -0,0 +1 @@
1
+ spec/support/streaming_error_helpers.rb
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ["main"]
6
+ push:
7
+ branches: ["main", "wip"]
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.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
29
+
30
+ - run: bundle exec rake rubocop flay spec
@@ -0,0 +1,22 @@
1
+ name: Gitleaks
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ["main"]
6
+ push:
7
+ branches: ["main", "wip"]
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-groq.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-groq-*.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.3
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/groq.rb
8
+ lib/ruby_llm/providers/groq/**/*.rb
9
+ ],
10
+ namespace: 'RubyLLM::Providers::Groq'
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 your-github-org
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,57 @@
1
+ # ruby_llm-providers-groq
2
+
3
+ RubyLLM provider gem for [Groq](https://groq.com) support.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruby_llm-providers-groq', require: 'ruby_llm/providers/groq'
11
+ ```
12
+
13
+ Then configure the provider:
14
+
15
+ ```ruby
16
+ require 'ruby_llm/providers/groq'
17
+
18
+ RubyLLM.configure do |config|
19
+ config.groq_api_key = ENV['GROQ_API_KEY']
20
+ end
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ An example of automatically picking the first chat-capable model:
26
+
27
+ ```ruby
28
+ model = RubyLLM.models.by_provider(:groq).chat_models.first
29
+ chat = RubyLLM.chat(provider: :groq, model: model.id)
30
+ response = chat.ask('Hello')
31
+ puts "The selected chat model '#{model.name}' replied:"
32
+ puts response.content
33
+ ```
34
+
35
+ When using Enterprise models, add an extra `assume_model_exists: true` argument (as they are for some reason not listed in the models registry):
36
+
37
+ ```ruby
38
+ chat = RubyLLM.chat(provider: :groq, model: 'llama-3.3-70b-versatile',
39
+ assume_model_exists: true)
40
+ ```
41
+
42
+ ## Development
43
+
44
+ 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.
45
+
46
+ ```sh
47
+ bundle exec rake models
48
+ bundle exec rake
49
+ ```
50
+
51
+ `rake models` calls only Groq's model-listing endpoint and writes `models.json` at the gem root. 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 uses a different path, change `models_url` in `lib/ruby_llm/providers/groq.rb`.
52
+
53
+ Run `rake models` from this provider gem when you want to update its packaged catalog. `RubyLLM.models.refresh` updates the application's main registry and does not refresh provider gem catalogs.
54
+
55
+ 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.
56
+
57
+ After refreshing 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,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_llm'
4
+
5
+ module RubyLLM
6
+ module Providers
7
+ # Groq API integration.
8
+ class Groq < Provider
9
+ # Groq's Responses protocol.
10
+ class Responses < Protocols::Responses
11
+ def models_url
12
+ 'models'
13
+ end
14
+
15
+ # rubocop:disable-next Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Style/MultipleComparison
16
+ # replace 'output_text' with 'input_text'
17
+ def sanitize_input_types!(node)
18
+ case node
19
+ when Hash
20
+ node.each do |key, value|
21
+ if (key == :type || key == 'type') && (value == :output_text || value == 'output_text')
22
+ node[key] = value.is_a?(Symbol) ? :input_text : 'input_text'
23
+ else
24
+ sanitize_input_types!(value)
25
+ end
26
+ end
27
+ when Array
28
+ node.each { |element| sanitize_input_types!(element) }
29
+ end
30
+ end
31
+
32
+ # Groq does not support the 'include' field
33
+ def render_payload(...)
34
+ payload = super
35
+ sanitize_input_types!(payload[:input]) if payload[:input]
36
+ payload.delete(:include)
37
+ payload
38
+ end
39
+ end
40
+
41
+ protocol :responses, Responses
42
+
43
+ def api_base
44
+ @config.groq_api_base || 'https://api.groq.com/openai/v1'
45
+ end
46
+
47
+ def headers
48
+ { 'Authorization' => "Bearer #{@config.groq_api_key}" }
49
+ end
50
+
51
+ class << self
52
+ def configuration_options
53
+ %i[groq_api_key groq_api_base]
54
+ end
55
+
56
+ def configuration_requirements
57
+ %i[groq_api_key]
58
+ end
59
+
60
+ # Use this only when the provider has no model-listing endpoint.
61
+ # def assume_models_exist?
62
+ # true
63
+ # end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ RubyLLM::Provider.register :groq, RubyLLM::Providers::Groq,
70
+ models: File.expand_path('../../../models.json', __dir__)
data/models.json ADDED
@@ -0,0 +1,218 @@
1
+ [
2
+ {
3
+ "id": "meta-llama/llama-prompt-guard-2-22m",
4
+ "name": "meta-llama/llama-prompt-guard-2-22m",
5
+ "provider": "groq",
6
+ "family": null,
7
+ "created_at": "2025-05-30 19:08:21 UTC",
8
+ "context_window": 512,
9
+ "max_output_tokens": 512,
10
+ "knowledge_cutoff": null,
11
+ "modalities": {
12
+ "input": ["text"],
13
+ "output": ["moderation"]
14
+ },
15
+ "capabilities": [],
16
+ "pricing": {},
17
+ "metadata": {
18
+ "object": "model",
19
+ "owned_by": "Meta"
20
+ }
21
+ },
22
+ {
23
+ "id": "openai/gpt-oss-safeguard-20b",
24
+ "name": "openai/gpt-oss-safeguard-20b",
25
+ "provider": "groq",
26
+ "family": null,
27
+ "created_at": "2025-10-29 03:33:09 UTC",
28
+ "context_window": 131072,
29
+ "max_output_tokens": 65536,
30
+ "knowledge_cutoff": null,
31
+ "modalities": {
32
+ "input": ["text"],
33
+ "output": ["text"]
34
+ },
35
+ "capabilities": [
36
+ "reasoning"
37
+ ],
38
+ "pricing": {},
39
+ "metadata": {
40
+ "object": "model",
41
+ "owned_by": "OpenAI"
42
+ }
43
+ },
44
+ {
45
+ "id": "meta-llama/llama-prompt-guard-2-86m",
46
+ "name": "meta-llama/llama-prompt-guard-2-86m",
47
+ "provider": "groq",
48
+ "family": null,
49
+ "created_at": "2025-05-30 19:09:25 UTC",
50
+ "context_window": 512,
51
+ "max_output_tokens": 512,
52
+ "knowledge_cutoff": null,
53
+ "modalities": {
54
+ "input": ["text"],
55
+ "output": ["moderation"]
56
+ },
57
+ "capabilities": [],
58
+ "pricing": {},
59
+ "metadata": {
60
+ "object": "model",
61
+ "owned_by": "Meta"
62
+ }
63
+ },
64
+ {
65
+ "id": "canopylabs/orpheus-v1-english",
66
+ "name": "canopylabs/orpheus-v1-english",
67
+ "provider": "groq",
68
+ "family": null,
69
+ "created_at": "2025-12-19 23:18:36 UTC",
70
+ "context_window": 4000,
71
+ "max_output_tokens": 50000,
72
+ "knowledge_cutoff": null,
73
+ "modalities": {
74
+ "input": ["text"],
75
+ "output": ["audio"]
76
+ },
77
+ "capabilities": [
78
+ "speech_generation"
79
+ ],
80
+ "pricing": {},
81
+ "metadata": {
82
+ "object": "model",
83
+ "owned_by": "Canopy Labs"
84
+ }
85
+ },
86
+ {
87
+ "id": "whisper-large-v3",
88
+ "name": "whisper-large-v3",
89
+ "provider": "groq",
90
+ "family": null,
91
+ "created_at": "2023-09-03 06:14:58 UTC",
92
+ "context_window": null,
93
+ "max_output_tokens": null,
94
+ "knowledge_cutoff": null,
95
+ "modalities": {
96
+ "input": ["audio"],
97
+ "output": ["text"]
98
+ },
99
+ "capabilities": [],
100
+ "pricing": {},
101
+ "metadata": {
102
+ "object": "model",
103
+ "owned_by": "OpenAI"
104
+ }
105
+ },
106
+ {
107
+ "id": "qwen/qwen3.8-27b",
108
+ "name": "qwen/qwen3.8-27b",
109
+ "provider": "groq",
110
+ "family": null,
111
+ "created_at": "2026-08-17 16:40:46 UTC",
112
+ "context_window": 131072,
113
+ "max_output_tokens": 16384,
114
+ "knowledge_cutoff": null,
115
+ "modalities": {
116
+ "input": ["text", "image"],
117
+ "output": ["text"]
118
+ },
119
+ "capabilities": [
120
+ "reasoning",
121
+ "structured_output",
122
+ "vision"
123
+ ],
124
+ "pricing": {},
125
+ "metadata": {
126
+ "object": "model",
127
+ "owned_by": "Alibaba Cloud"
128
+ }
129
+ },
130
+ {
131
+ "id": "openai/gpt-oss-120b",
132
+ "name": "openai/gpt-oss-120b",
133
+ "provider": "groq",
134
+ "family": null,
135
+ "created_at": "2025-08-05 15:37:04 UTC",
136
+ "context_window": 131072,
137
+ "max_output_tokens": 65536,
138
+ "knowledge_cutoff": "2024-06-30",
139
+ "modalities": {
140
+ "input": ["text"],
141
+ "output": ["text"]
142
+ },
143
+ "capabilities": [
144
+ "reasoning",
145
+ "structured_output"
146
+ ],
147
+ "pricing": {},
148
+ "metadata": {
149
+ "object": "model",
150
+ "owned_by": "OpenAI"
151
+ }
152
+ },
153
+ {
154
+ "id": "openai/gpt-oss-20b",
155
+ "name": "openai/gpt-oss-20b",
156
+ "provider": "groq",
157
+ "family": null,
158
+ "created_at": "2025-08-05 15:32:37 UTC",
159
+ "context_window": 131072,
160
+ "max_output_tokens": 65536,
161
+ "knowledge_cutoff": "2024-06-30",
162
+ "modalities": {
163
+ "input": ["text"],
164
+ "output": ["text"]
165
+ },
166
+ "capabilities": [
167
+ "reasoning",
168
+ "structured_output"
169
+ ],
170
+ "pricing": {},
171
+ "metadata": {
172
+ "object": "model",
173
+ "owned_by": "OpenAI"
174
+ }
175
+ },
176
+ {
177
+ "id": "whisper-large-v3-turbo",
178
+ "name": "whisper-large-v3-turbo",
179
+ "provider": "groq",
180
+ "family": null,
181
+ "created_at": "2024-10-08 18:44:48 UTC",
182
+ "context_window": null,
183
+ "max_output_tokens": null,
184
+ "knowledge_cutoff": null,
185
+ "modalities": {
186
+ "input": ["audio"],
187
+ "output": ["text"]
188
+ },
189
+ "capabilities": [],
190
+ "pricing": {},
191
+ "metadata": {
192
+ "object": "model",
193
+ "owned_by": "OpenAI"
194
+ }
195
+ },
196
+ {
197
+ "id": "canopylabs/orpheus-arabic-saudi",
198
+ "name": "canopylabs/orpheus-arabic-saudi",
199
+ "provider": "groq",
200
+ "family": null,
201
+ "created_at": "2025-12-16 23:07:19 UTC",
202
+ "context_window": 4000,
203
+ "max_output_tokens": 50000,
204
+ "knowledge_cutoff": null,
205
+ "modalities": {
206
+ "input": ["text"],
207
+ "output": ["audio"]
208
+ },
209
+ "capabilities": [
210
+ "speech_generation"
211
+ ],
212
+ "pricing": {},
213
+ "metadata": {
214
+ "object": "model",
215
+ "owned_by": "Canopy Labs"
216
+ }
217
+ }
218
+ ]