mistral 0.1.0 → 0.2.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/.env.example +1 -1
- data/CHANGELOG.md +20 -2
- data/PYTHON_CLIENT_COMPARISON.md +12 -1
- data/examples/function_calling.rb +4 -2
- data/lib/mistral/client.rb +1 -1
- data/lib/mistral/client_base.rb +7 -3
- data/lib/mistral/models/chat_completion.rb +1 -0
- data/lib/mistral/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9d2632f2ddb13e1ebe7e1e286eef43e577598bfe3f918a8961efda0fd471b84
|
4
|
+
data.tar.gz: 150463bfd7ec228c3d8bbae83a3e1277d1907324e10649ebe236868486e91c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d10df680e7ad04178dea6a386539404659836ce4df94fa991a45bc3a00837802c251923ea9bb58a5118e96b4dd2b44dfce171c55588a8c704bb886627144b4ee
|
7
|
+
data.tar.gz: 709d9ccaf6ed76d8c56d513f5c08ff3610eafe2662430f9f71ff6984f0ec83b3ec37daa0cf7d04efcdd2b8f5ad41e6af17ea6a62a6d593abb07f97542bf64cdd
|
data/.env.example
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,8 +5,26 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.1/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.2.0] - 2024-05-23
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- We now support tool_call_id for tool messages. This will be mandatory in the future but you can start using right
|
13
|
+
away to improve the model performance during function calling (especially multiple).
|
14
|
+
Ports [mistralai/client-python#93](https://github.com/mistralai/client-python/pull/93)
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Renamed `LOG_LEVEL` to `MISTRAL_LOG_LEVEL`. This is not a direct port of the Python client because Python has a
|
19
|
+
global logger in the `logging` module, but Ruby doesn't.
|
20
|
+
Ports [mistralai/client-python#86](https://github.com/mistralai/client-python/pull/86)
|
21
|
+
- Get API key at client initialization. Ports
|
22
|
+
[mistralai/client-python#57](https://github.com/mistralai/client-python/pull/57)
|
23
|
+
|
8
24
|
## [0.1.0] - 2024-05-04
|
9
25
|
|
10
|
-
- Initial release. Feature parity with `v0.1.8` of the
|
26
|
+
- Initial release. Feature parity with `v0.1.8` of the
|
27
|
+
[mistralai/client-python](https://github.com/mistralai/client-python)
|
11
28
|
|
12
|
-
[0.
|
29
|
+
[0.2.0]: https://github.com/wilsonsilva/mistral/compare/v0.1.0...v0.2.0
|
30
|
+
[0.1.0]: https://github.com/wilsonsilva/mistral/compare/28e7c9...v0.1.0
|
data/PYTHON_CLIENT_COMPARISON.md
CHANGED
@@ -175,10 +175,21 @@ This code resides in `lib/http/features/line_iterable_body.rb`.
|
|
175
175
|
## Testing
|
176
176
|
|
177
177
|
The Ruby gem aims for 1:1 parity with the Python client. As such, it uses `Minitest` (similar to Python's `pytest`).
|
178
|
-
However, testing was simplified by using
|
178
|
+
However, testing was simplified by using `webmock` for stubbing requests, instead of implementing 100% test
|
179
179
|
coverage and using RSpec, which is usually what I do.
|
180
180
|
|
181
181
|
## Examples
|
182
182
|
|
183
183
|
The `function_calling.rb` example omits the unnecessary `n_rows = data['transaction_id'].length` line present in
|
184
184
|
the Python version.
|
185
|
+
|
186
|
+
## Logging
|
187
|
+
|
188
|
+
Python has a global logger:
|
189
|
+
|
190
|
+
```python
|
191
|
+
self._logger = logging.getLogger(__name__)
|
192
|
+
```
|
193
|
+
|
194
|
+
Ruby doesn't. Thus, in order to allow users to customize the logging level, they can set the environment variable
|
195
|
+
`MISTRAL_LOG_LEVEL` to `DEBUG`, `INFO`, `WARN`, `ERROR` or `FATAL`.
|
@@ -73,7 +73,7 @@ tools = [
|
|
73
73
|
]
|
74
74
|
|
75
75
|
api_key = ENV.fetch('MISTRAL_API_KEY')
|
76
|
-
model = 'mistral-
|
76
|
+
model = 'mistral-small-latest'
|
77
77
|
|
78
78
|
client = Mistral::Client.new(api_key: api_key)
|
79
79
|
|
@@ -97,7 +97,9 @@ puts "calling function_name: #{function_name}, with function_params: #{function_
|
|
97
97
|
function_result = names_to_functions[function_name].call(function_params['transaction_id'])
|
98
98
|
|
99
99
|
messages << response.choices[0].message
|
100
|
-
messages << Mistral::ChatMessage.new(
|
100
|
+
messages << Mistral::ChatMessage.new(
|
101
|
+
role: 'tool', name: function_name, content: function_result, tool_call_id: tool_call.id
|
102
|
+
)
|
101
103
|
|
102
104
|
response = client.chat(model: model, messages: messages, tools: tools)
|
103
105
|
|
data/lib/mistral/client.rb
CHANGED
data/lib/mistral/client_base.rb
CHANGED
@@ -5,11 +5,15 @@ module Mistral
|
|
5
5
|
attr_reader :endpoint, :api_key, :max_retries, :timeout
|
6
6
|
|
7
7
|
def initialize(endpoint:, api_key: nil, max_retries: 5, timeout: 120)
|
8
|
-
@endpoint = endpoint
|
9
|
-
@api_key = api_key
|
10
8
|
@max_retries = max_retries
|
11
9
|
@timeout = timeout
|
12
10
|
|
11
|
+
api_key = ENV['MISTRAL_API_KEY'] if api_key.nil?
|
12
|
+
|
13
|
+
raise Error, 'API key not provided. Please set MISTRAL_API_KEY environment variable.' if api_key.nil?
|
14
|
+
|
15
|
+
@api_key = api_key
|
16
|
+
@endpoint = endpoint
|
13
17
|
@logger = config_logger
|
14
18
|
|
15
19
|
# For azure endpoints, we default to the mistral model
|
@@ -115,7 +119,7 @@ module Mistral
|
|
115
119
|
|
116
120
|
def config_logger
|
117
121
|
Logger.new($stdout).tap do |logger|
|
118
|
-
logger.level = ENV.fetch('
|
122
|
+
logger.level = ENV.fetch('MISTRAL_LOG_LEVEL', 'ERROR')
|
119
123
|
|
120
124
|
logger.formatter = proc do |severity, datetime, progname, msg|
|
121
125
|
"#{datetime.strftime("%Y-%m-%d %H:%M:%S")} #{severity} #{progname}: #{msg}\n"
|
@@ -43,6 +43,7 @@ module Mistral
|
|
43
43
|
attribute :content, Types::Strict::Array.of(Types::Strict::String) | Types::Strict::String
|
44
44
|
attribute? :name, Types::String.optional
|
45
45
|
attribute? :tool_calls, Types::Strict::Array.of(ToolCall).optional
|
46
|
+
attribute? :tool_call_id, Types::String.optional
|
46
47
|
end
|
47
48
|
|
48
49
|
class DeltaMessage < Dry::Struct
|
data/lib/mistral/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mistral
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|
@@ -108,7 +108,8 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.23'
|
111
|
-
description:
|
111
|
+
description: A 1:1 Ruby port of the official Mistral Python client, with feature and
|
112
|
+
API parity.
|
112
113
|
email:
|
113
114
|
- wilson.dsigns@gmail.com
|
114
115
|
executables: []
|