mistral_translator 0.1.0 → 0.3.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/CHANGELOG.md +44 -0
- data/CONTRIBUTING.md +70 -0
- data/LICENSE.txt +6 -6
- data/README.md +212 -119
- data/README_TESTING.md +33 -0
- data/SECURITY.md +157 -0
- data/docs/.nojekyll +2 -0
- data/docs/404.html +30 -0
- data/docs/README.md +153 -0
- data/docs/advanced-usage/batch-processing.md +158 -0
- data/docs/advanced-usage/concurrent-async.md +270 -0
- data/docs/advanced-usage/error-handling.md +106 -0
- data/docs/advanced-usage/monitoring.md +133 -0
- data/docs/advanced-usage/summarization.md +86 -0
- data/docs/advanced-usage/translations.md +141 -0
- data/docs/api-reference/callbacks.md +231 -0
- data/docs/api-reference/configuration.md +74 -0
- data/docs/api-reference/errors.md +673 -0
- data/docs/api-reference/methods.md +539 -0
- data/docs/getting-started.md +179 -0
- data/docs/index.html +27 -0
- data/docs/installation.md +142 -0
- data/docs/migration-0.1.0-to-0.2.0.md +61 -0
- data/docs/rails-integration/adapters.md +84 -0
- data/docs/rails-integration/controllers.md +107 -0
- data/docs/rails-integration/jobs.md +97 -0
- data/docs/rails-integration/setup.md +339 -0
- data/examples/basic_usage.rb +129 -102
- data/examples/batch-job.rb +511 -0
- data/examples/monitoring-setup.rb +499 -0
- data/examples/rails-model.rb +399 -0
- data/lib/mistral_translator/adapters.rb +261 -0
- data/lib/mistral_translator/client.rb +103 -100
- data/lib/mistral_translator/client_helpers.rb +191 -0
- data/lib/mistral_translator/configuration.rb +191 -1
- data/lib/mistral_translator/errors.rb +16 -0
- data/lib/mistral_translator/helpers.rb +292 -0
- data/lib/mistral_translator/helpers_extensions.rb +150 -0
- data/lib/mistral_translator/levenshtein_helpers.rb +40 -0
- data/lib/mistral_translator/logger.rb +39 -8
- data/lib/mistral_translator/prompt_builder.rb +93 -41
- data/lib/mistral_translator/prompt_helpers.rb +83 -0
- data/lib/mistral_translator/prompt_metadata_helpers.rb +42 -0
- data/lib/mistral_translator/response_parser.rb +194 -23
- data/lib/mistral_translator/security.rb +72 -0
- data/lib/mistral_translator/summarizer.rb +41 -2
- data/lib/mistral_translator/translator.rb +174 -98
- data/lib/mistral_translator/translator_helpers.rb +268 -0
- data/lib/mistral_translator/version.rb +1 -1
- data/lib/mistral_translator.rb +51 -25
- metadata +55 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5e52138d192d693042abbc570da3a9ed1f7f56acaed881c46a59df100dc476a0
|
|
4
|
+
data.tar.gz: 74a169d74c5248dc7ec1cab84c5892018eeacf3ba398bfb0b0a3c41a98d87ae9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f324d7cb87b75c340d1875fc6189c13c39dfe26c1878ff187c30c04674b88549c813be6f73c644b2b01a5f28ed5e88da55351c86b37800d9648835113f58b3e
|
|
7
|
+
data.tar.gz: 0d9ac452969b457ed81cd34295e564d869c3e8f254e0807a8d473af8c99fbcb10f0d2ea5bc5abea518a0f7bd59d978428dac8e5c25864c63a4fa61d0dfb1617a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2025-12-09
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Thread-safe metrics with Mutex protection for concurrent usage
|
|
8
|
+
- Connection pooling with net-http-persistent (automatic connection reuse)
|
|
9
|
+
- SSL/TLS configuration options: `ssl_verify_mode`, `ssl_ca_file`, `ssl_ca_path`, `ssl_timeout`
|
|
10
|
+
- Thread-safe logger cache for `warn_once` method
|
|
11
|
+
- Comprehensive concurrent/async documentation with SolidQueue, Sidekiq, Concurrent Ruby examples
|
|
12
|
+
- 39 new tests for thread-safety, SSL configuration, and connection pooling
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- HTTP client now uses Net::HTTP::Persistent for better performance
|
|
17
|
+
- Configuration metrics now thread-safe across concurrent requests
|
|
18
|
+
- Documentation reorganized with SolidQueue as recommended background job backend
|
|
19
|
+
|
|
20
|
+
### Performance
|
|
21
|
+
|
|
22
|
+
- Connection pooling reduces TCP handshake overhead
|
|
23
|
+
- Thread-safe implementation enables safe concurrent translations
|
|
24
|
+
- Configurable SSL timeout for production environments
|
|
25
|
+
|
|
26
|
+
## [0.2.0] - 2025-09-09
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Contexte et glossaire via `MistralTranslator::Translator#translate`
|
|
31
|
+
- Rate limiting client (50 req/min par défaut, thread-safe)
|
|
32
|
+
- Validation basique des entrées (max 50k chars, batch ≤ 20)
|
|
33
|
+
- Nouvelles erreurs: `SecurityError`, `RateLimitExceededError`
|
|
34
|
+
- Métriques intégrées et callbacks de monitoring
|
|
35
|
+
- Documentation mise à jour + guide de migration 0.1.0 → 0.2.0
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- Exemples et docs: utilisation d’une instance `Translator` pour `context`/`glossary`
|
|
40
|
+
- Amélioration de la structure interne (client/translator/summarizer)
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- Masquage renforcé des secrets dans VCR
|
|
45
|
+
- Messages d’erreurs plus explicites pour les réponses invalides
|
|
46
|
+
|
|
3
47
|
## [0.1.0] - 2025-09-01
|
|
4
48
|
|
|
5
49
|
- Initial release
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Contributing to MistralTranslator
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to MistralTranslator! We welcome contributions of all kinds.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Ruby 3.2+
|
|
10
|
+
- Bundler
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/your-username/mistral_translator.git
|
|
16
|
+
cd mistral_translator
|
|
17
|
+
bundle install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Running Tests
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Unit tests (no API key required)
|
|
24
|
+
bundle exec rspec
|
|
25
|
+
|
|
26
|
+
# Integration tests (requires real API key)
|
|
27
|
+
export MISTRAL_API_KEY=your_key && bundle exec rspec spec/integration/mistral_api_integration_spec.rb
|
|
28
|
+
|
|
29
|
+
# All tests with coverage
|
|
30
|
+
bundle exec rspec --format documentation
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Contributing Guidelines
|
|
34
|
+
|
|
35
|
+
### Reporting Issues
|
|
36
|
+
|
|
37
|
+
- Use GitHub Issues for bug reports and feature requests
|
|
38
|
+
- Include Ruby version, gem version, and relevant code snippets
|
|
39
|
+
- For API-related issues, include sanitized request/response examples
|
|
40
|
+
|
|
41
|
+
### Pull Requests
|
|
42
|
+
|
|
43
|
+
1. Fork the repository
|
|
44
|
+
2. Create a feature branch: `git checkout -b feature/your-feature`
|
|
45
|
+
3. Make your changes with tests
|
|
46
|
+
4. Ensure all tests pass: `bundle exec rspec`
|
|
47
|
+
5. Follow Ruby style conventions (we use RuboCop - no error) : `bundle exec rubocop`
|
|
48
|
+
6. Submit a pull request with a clear description
|
|
49
|
+
|
|
50
|
+
### Code Standards
|
|
51
|
+
|
|
52
|
+
- Write tests for new features and bug fixes
|
|
53
|
+
- Follow existing code patterns and architecture
|
|
54
|
+
- Update documentation for public API changes
|
|
55
|
+
- Keep commits atomic and well-described
|
|
56
|
+
|
|
57
|
+
### Testing
|
|
58
|
+
|
|
59
|
+
- Unit tests should not require API calls (use mocks/stubs)
|
|
60
|
+
- Integration tests should use VCR cassettes when possible
|
|
61
|
+
- Test edge cases and error conditions
|
|
62
|
+
- Test coverage must be at 100% (for now)
|
|
63
|
+
|
|
64
|
+
## Release Process
|
|
65
|
+
|
|
66
|
+
Releases are handled by maintainers following semantic versioning.
|
|
67
|
+
|
|
68
|
+
## Questions?
|
|
69
|
+
|
|
70
|
+
Feel free to open an issue for any questions about contributing.
|
data/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Pierre Cherbero (peyochanchan)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
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
|
|
21
|
-
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,205 +1,298 @@
|
|
|
1
1
|
# MistralTranslator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ruby gem for AI-powered translation and text summarization using Mistral AI API, with advanced Rails support.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.ruby-lang.org/)
|
|
6
|
+
[](https://badge.fury.io/rb/mistral_translator)
|
|
7
|
+
[](https://rspec.info/)
|
|
8
|
+
[](https://rubocop.org/)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
## Quick Start
|
|
8
12
|
|
|
9
13
|
```ruby
|
|
14
|
+
# Installation
|
|
10
15
|
gem 'mistral_translator'
|
|
16
|
+
|
|
17
|
+
# Configuration
|
|
18
|
+
MistralTranslator.configure do |config|
|
|
19
|
+
config.api_key = ENV['MISTRAL_API_KEY']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Basic usage
|
|
23
|
+
MistralTranslator.translate("Bonjour le monde", from: "fr", to: "en")
|
|
24
|
+
# => "Hello world"
|
|
11
25
|
```
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
## Key Features
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
- **Smart translation** with context and custom glossaries
|
|
30
|
+
- **Native Rails integration** (Mobility, Globalize, I18n attributes)
|
|
31
|
+
- **Batch processing** for high-volume translations
|
|
32
|
+
- **Multi-level summarization** with translation
|
|
33
|
+
- **Robust error handling** with automatic retry and fallback
|
|
34
|
+
- **Complete monitoring** with metrics and callbacks
|
|
35
|
+
- **Thread-safe & concurrent** with connection pooling ([docs](https://peyochanchan.github.io/mistral_translator/#/advanced-usage/concurrent-async))
|
|
36
|
+
- **Built-in rate limiting** and security
|
|
37
|
+
|
|
38
|
+
## Supported Languages
|
|
39
|
+
|
|
40
|
+
`fr` `en` `es` `pt` `de` `it` `nl` `ru` `mg` `ja` `ko` `zh` `ar`
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Add to your Gemfile:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
gem 'mistral_translator'
|
|
17
48
|
```
|
|
18
49
|
|
|
19
|
-
|
|
50
|
+
Then run:
|
|
20
51
|
|
|
21
52
|
```bash
|
|
22
|
-
|
|
53
|
+
bundle install
|
|
23
54
|
```
|
|
24
55
|
|
|
25
|
-
|
|
56
|
+
### API Key Setup
|
|
57
|
+
|
|
58
|
+
Get your API key from [Mistral AI Console](https://console.mistral.ai/) and configure it:
|
|
26
59
|
|
|
27
60
|
```ruby
|
|
28
|
-
|
|
61
|
+
# Environment variable (recommended)
|
|
62
|
+
export MISTRAL_API_KEY="your_api_key_here"
|
|
29
63
|
|
|
64
|
+
# Or in Rails config/initializers/mistral_translator.rb
|
|
30
65
|
MistralTranslator.configure do |config|
|
|
31
|
-
config.api_key = '
|
|
32
|
-
config.
|
|
33
|
-
config.model = 'mistral-small' # optionnel
|
|
66
|
+
config.api_key = ENV['MISTRAL_API_KEY']
|
|
67
|
+
config.enable_metrics = Rails.env.production?
|
|
34
68
|
end
|
|
35
69
|
```
|
|
36
70
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Vous pouvez aussi utiliser des variables d'environnement :
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
export MISTRAL_API_KEY=votre_clé_api
|
|
43
|
-
export MISTRAL_API_URL=https://api.mistral.ai
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Utilisation
|
|
71
|
+
## Basic Usage Examples
|
|
47
72
|
|
|
48
|
-
###
|
|
73
|
+
### Simple Translation
|
|
49
74
|
|
|
50
75
|
```ruby
|
|
51
|
-
#
|
|
52
|
-
result = MistralTranslator.translate("Bonjour
|
|
53
|
-
# => "Hello
|
|
76
|
+
# Basic translation
|
|
77
|
+
result = MistralTranslator.translate("Bonjour", from: "fr", to: "en")
|
|
78
|
+
# => "Hello"
|
|
54
79
|
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
from:
|
|
59
|
-
to:
|
|
80
|
+
# With context for better accuracy
|
|
81
|
+
result = MistralTranslator.translate(
|
|
82
|
+
"Le produit est disponible",
|
|
83
|
+
from: "fr",
|
|
84
|
+
to: "en",
|
|
85
|
+
context: "E-commerce website"
|
|
60
86
|
)
|
|
61
|
-
# =>
|
|
87
|
+
# => "The product is available"
|
|
88
|
+
|
|
89
|
+
# With custom glossary
|
|
90
|
+
result = MistralTranslator.translate(
|
|
91
|
+
"Notre API est performante",
|
|
92
|
+
from: "fr",
|
|
93
|
+
to: "en",
|
|
94
|
+
glossary: { "API" => "API" } # Preserve technical terms
|
|
95
|
+
)
|
|
96
|
+
# => "Our API is high-performing"
|
|
62
97
|
```
|
|
63
98
|
|
|
64
|
-
###
|
|
99
|
+
### Auto-Detection
|
|
65
100
|
|
|
66
101
|
```ruby
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# =>
|
|
102
|
+
# Automatic source language detection
|
|
103
|
+
MistralTranslator.translate_auto("¡Hola mundo!", to: "fr")
|
|
104
|
+
# => "Salut le monde !"
|
|
70
105
|
```
|
|
71
106
|
|
|
72
|
-
###
|
|
107
|
+
### Batch Processing
|
|
73
108
|
|
|
74
109
|
```ruby
|
|
75
|
-
|
|
76
|
-
|
|
110
|
+
texts = ["Bonjour", "Merci", "Au revoir"]
|
|
111
|
+
results = MistralTranslator.translate_batch(texts, from: "fr", to: "en")
|
|
112
|
+
# => {0 => "Hello", 1 => "Thank you", 2 => "Goodbye"}
|
|
77
113
|
```
|
|
78
114
|
|
|
79
|
-
###
|
|
115
|
+
### Text Summarization
|
|
80
116
|
|
|
81
117
|
```ruby
|
|
82
|
-
long_text = "
|
|
118
|
+
long_text = "Ruby on Rails is a web framework..."
|
|
83
119
|
|
|
84
|
-
#
|
|
85
|
-
summary = MistralTranslator.summarize(long_text, language:
|
|
120
|
+
# Simple summary
|
|
121
|
+
summary = MistralTranslator.summarize(long_text, language: "en", max_words: 50)
|
|
86
122
|
|
|
87
|
-
#
|
|
123
|
+
# Summary with translation
|
|
88
124
|
summary = MistralTranslator.summarize_and_translate(
|
|
89
|
-
long_text,
|
|
90
|
-
from: 'fr',
|
|
91
|
-
to: 'en',
|
|
92
|
-
max_words: 150
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
# Résumés par niveaux
|
|
96
|
-
summaries = MistralTranslator.summarize_tiered(
|
|
97
125
|
long_text,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
long: 300
|
|
126
|
+
from: "en",
|
|
127
|
+
to: "fr",
|
|
128
|
+
max_words: 100
|
|
102
129
|
)
|
|
103
|
-
# => { short: "...", medium: "...", long: "..." }
|
|
104
130
|
```
|
|
105
131
|
|
|
106
|
-
###
|
|
132
|
+
### Rails Integration
|
|
107
133
|
|
|
108
134
|
```ruby
|
|
109
|
-
#
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
# With Mobility
|
|
136
|
+
class Article < ApplicationRecord
|
|
137
|
+
extend Mobility
|
|
138
|
+
translates :title, :content, backend: :table
|
|
139
|
+
|
|
140
|
+
def translate_to_all_languages!
|
|
141
|
+
MistralTranslator::RecordTranslation.translate_mobility_record(
|
|
142
|
+
self,
|
|
143
|
+
[:title, :content],
|
|
144
|
+
source_locale: I18n.locale
|
|
145
|
+
)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
115
148
|
|
|
116
|
-
|
|
117
|
-
|
|
149
|
+
# Usage
|
|
150
|
+
article = Article.create!(title_fr: "Titre français", content_fr: "Contenu...")
|
|
151
|
+
article.translate_to_all_languages!
|
|
118
152
|
```
|
|
119
153
|
|
|
120
|
-
##
|
|
121
|
-
|
|
122
|
-
La gem supporte les langues suivantes :
|
|
123
|
-
- Français (fr)
|
|
124
|
-
- Anglais (en)
|
|
125
|
-
- Espagnol (es)
|
|
126
|
-
- Portugais (pt)
|
|
127
|
-
- Allemand (de)
|
|
128
|
-
- Italien (it)
|
|
129
|
-
- Néerlandais (nl)
|
|
130
|
-
- Russe (ru)
|
|
131
|
-
- Japonais (ja)
|
|
132
|
-
- Coréen (ko)
|
|
133
|
-
- Chinois (zh)
|
|
134
|
-
- Arabe (ar)
|
|
154
|
+
## Configuration Options
|
|
135
155
|
|
|
136
156
|
```ruby
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
MistralTranslator.configure do |config|
|
|
158
|
+
# Required
|
|
159
|
+
config.api_key = ENV['MISTRAL_API_KEY']
|
|
160
|
+
|
|
161
|
+
# Optional
|
|
162
|
+
config.model = "mistral-small" # AI model to use
|
|
163
|
+
config.retry_delays = [1, 2, 4, 8, 16] # Retry delays in seconds
|
|
164
|
+
config.enable_metrics = true # Enable performance metrics
|
|
165
|
+
|
|
166
|
+
# Callbacks for monitoring
|
|
167
|
+
config.on_translation_complete = ->(from, to, orig_len, trans_len, duration) {
|
|
168
|
+
Rails.logger.info "Translation #{from}→#{to} completed in #{duration.round(2)}s"
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
config.on_translation_error = ->(from, to, error, attempt, timestamp) {
|
|
172
|
+
Rails.logger.error "Translation failed: #{error.message} (attempt #{attempt})"
|
|
173
|
+
}
|
|
174
|
+
end
|
|
140
175
|
```
|
|
141
176
|
|
|
142
|
-
##
|
|
177
|
+
## Error Handling
|
|
143
178
|
|
|
144
179
|
```ruby
|
|
145
180
|
begin
|
|
146
|
-
result = MistralTranslator.translate("Hello", from:
|
|
181
|
+
result = MistralTranslator.translate("Hello", from: "en", to: "fr")
|
|
147
182
|
rescue MistralTranslator::RateLimitError
|
|
148
|
-
|
|
183
|
+
# Rate limit hit - automatic retry with backoff
|
|
184
|
+
retry
|
|
149
185
|
rescue MistralTranslator::AuthenticationError
|
|
150
|
-
|
|
186
|
+
# Invalid API key
|
|
187
|
+
Rails.logger.error "Check your Mistral API key"
|
|
151
188
|
rescue MistralTranslator::UnsupportedLanguageError => e
|
|
152
|
-
|
|
189
|
+
# Language not supported
|
|
190
|
+
Rails.logger.error "Language '#{e.language}' not supported"
|
|
191
|
+
rescue MistralTranslator::Error => e
|
|
192
|
+
# General error handling
|
|
193
|
+
Rails.logger.error "Translation failed: #{e.message}"
|
|
153
194
|
end
|
|
154
195
|
```
|
|
155
196
|
|
|
156
|
-
##
|
|
157
|
-
|
|
158
|
-
### Client personnalisé
|
|
197
|
+
## Performance Monitoring
|
|
159
198
|
|
|
160
199
|
```ruby
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
200
|
+
# Enable metrics
|
|
201
|
+
MistralTranslator.configure { |c| c.enable_metrics = true }
|
|
202
|
+
|
|
203
|
+
# View metrics
|
|
204
|
+
metrics = MistralTranslator.metrics
|
|
205
|
+
puts "Total translations: #{metrics[:total_translations]}"
|
|
206
|
+
puts "Average time: #{metrics[:average_translation_time]}s"
|
|
207
|
+
puts "Error rate: #{metrics[:error_rate]}%"
|
|
164
208
|
```
|
|
165
209
|
|
|
166
|
-
|
|
210
|
+
## 📖 Complete Documentation
|
|
167
211
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
```
|
|
212
|
+
**For comprehensive guides, advanced usage, and Rails integration examples:**
|
|
213
|
+
|
|
214
|
+
### 🌐 [**Full Documentation Website**](https://peyochanchan.github.io/mistral_translator/)
|
|
172
215
|
|
|
173
|
-
|
|
216
|
+
The complete documentation includes:
|
|
174
217
|
|
|
175
|
-
|
|
218
|
+
- **Getting Started Guide** - Step-by-step tutorials
|
|
219
|
+
- **Advanced Usage** - Context, glossaries, batch processing, monitoring
|
|
220
|
+
- **Rails Integration** - Mobility, Globalize, jobs, controllers
|
|
221
|
+
- **API Reference** - Complete method documentation
|
|
222
|
+
- **Examples** - Ready-to-use code samples
|
|
223
|
+
- **Error Handling** - Comprehensive error management strategies
|
|
224
|
+
|
|
225
|
+
### Quick Links
|
|
226
|
+
|
|
227
|
+
- [Installation & Setup](https://peyochanchan.github.io/mistral_translator/#/installation)
|
|
228
|
+
- [Rails Integration Guide](https://peyochanchan.github.io/mistral_translator/#/rails-integration/setup)
|
|
229
|
+
- [API Methods Reference](https://peyochanchan.github.io/mistral_translator/#/api-reference/methods)
|
|
230
|
+
- [Error Handling Guide](https://peyochanchan.github.io/mistral_translator/#/api-reference/errors)
|
|
231
|
+
- [Monitoring Setup](https://peyochanchan.github.io/mistral_translator/#/advanced-usage/monitoring)
|
|
232
|
+
|
|
233
|
+
## Requirements
|
|
234
|
+
|
|
235
|
+
- Ruby 3.2+
|
|
236
|
+
- Mistral AI API key
|
|
237
|
+
- Rails 6.0+ (optional, for Rails integration features)
|
|
238
|
+
|
|
239
|
+
## Testing
|
|
176
240
|
|
|
177
241
|
```bash
|
|
242
|
+
# Install dependencies
|
|
178
243
|
bundle install
|
|
179
|
-
bin/setup
|
|
180
|
-
```
|
|
181
244
|
|
|
182
|
-
|
|
245
|
+
# Run all unit tests (no API key required)
|
|
246
|
+
bundle exec rspec spec/mistral_translator/
|
|
183
247
|
|
|
184
|
-
|
|
185
|
-
bundle exec rspec
|
|
248
|
+
# Run all tests with documentation format
|
|
249
|
+
bundle exec rspec --format documentation
|
|
186
250
|
```
|
|
187
251
|
|
|
188
|
-
|
|
252
|
+
### Integration Tests
|
|
253
|
+
|
|
254
|
+
Integration tests require a real Mistral API key. **Never commit API keys to version control.**
|
|
189
255
|
|
|
190
256
|
```bash
|
|
191
|
-
|
|
257
|
+
# Set API key via environment variable (recommended)
|
|
258
|
+
export MISTRAL_API_KEY="your_api_key_here"
|
|
259
|
+
|
|
260
|
+
# Run integration tests
|
|
261
|
+
bundle exec rspec spec/integration/
|
|
262
|
+
|
|
263
|
+
**Security Note:** Use a dedicated test API key with limited quotas for integration testing.
|
|
192
264
|
```
|
|
193
265
|
|
|
194
|
-
##
|
|
266
|
+
## Contributing
|
|
267
|
+
|
|
268
|
+
1. Fork the repository
|
|
269
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
270
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
271
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
272
|
+
5. Open a Pull Request
|
|
273
|
+
|
|
274
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT License. See [LICENSE](LICENSE.txt) for details.
|
|
279
|
+
|
|
280
|
+
## Support
|
|
195
281
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
3. Commiter vos changements
|
|
200
|
-
4. Pousser vers la branche
|
|
201
|
-
5. Ouvrir une Pull Request
|
|
282
|
+
- 📖 [Documentation](https://peyochanchan.github.io/mistral_translator/)
|
|
283
|
+
- 🐛 [Issues](../../issues)
|
|
284
|
+
- 📧 Support: Create an issue for help
|
|
202
285
|
|
|
203
|
-
|
|
286
|
+
### ☕ Support the Project
|
|
204
287
|
|
|
205
|
-
|
|
288
|
+
If this gem helps you, consider supporting its development:
|
|
289
|
+
|
|
290
|
+
[](https://buymeacoffee.com/peyochanchan)
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
Built with Ruby ❤️ by [@peyochanchan](https://github.com/peyochanchan)
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
```
|
data/README_TESTING.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Tests de la gem MistralTranslator
|
|
2
|
+
|
|
3
|
+
## Types de tests
|
|
4
|
+
|
|
5
|
+
### 1. Tests unitaires (par défaut)
|
|
6
|
+
|
|
7
|
+
- Utilisent des mocks et stubs
|
|
8
|
+
- Pas besoin de clé API
|
|
9
|
+
- Rapides et fiables
|
|
10
|
+
|
|
11
|
+
### 2. Tests d'intégration
|
|
12
|
+
|
|
13
|
+
- Marqués avec `:integration`
|
|
14
|
+
- Nécessitent `MISTRAL_TEST_API_KEY`
|
|
15
|
+
- Utilisent la vraie API Mistral
|
|
16
|
+
|
|
17
|
+
### 3. Tests VCR
|
|
18
|
+
|
|
19
|
+
- Marqués avec `:vcr`
|
|
20
|
+
- Enregistrent les réponses API
|
|
21
|
+
- Rejouent les réponses sans nouvelle requête
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
### Variables d'environnement
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Pour les tests d'intégration (optionnel)
|
|
29
|
+
export MISTRAL_TEST_API_KEY="votre_cle_de_test"
|
|
30
|
+
|
|
31
|
+
# Alternative (utilise votre clé principale)
|
|
32
|
+
export MISTRAL_API_KEY="votre_cle_principale"
|
|
33
|
+
```
|