crystal-mistral
⚡ Crystal Mistral Client
Installation
-
Add the dependency to your
shard.yml
:dependencies: crystal-mistral: github: Skrebnevf/crystal-mistral
-
Run
shards install
🖥️ Usage
require "crystal-mistral"
# API key can be passed directly or loaded from ENV["MISTRAL_API_KEY"]
client = CrystalMistral::Client.new
💬 Chat Completion
# Use custom Messages type
messages = [
Messages.new(role: Role::User, content: "Hello!")
]
# or String type
messages = %([{"role": "user", "content": "Best place in Norilsk"}])
response = client.chat(
model: "mistral-large-latest",
messages: messages,
temperature: 0.7_f32
)
puts response.choices[0].message.content
💻 Code Completion
client = CrystalMistral::Client.new
response = client.code(
model: "codestral-2405",
prompt: "def hello(name : String)",
suffix: "",
temperature: 0.7
)
puts "Generated code:\n#{puts resp.choices[0].message.content}"
🧠 Embeddings
texts = ["Let's compare London and Paris", "Compare?!"]
response = client.embeddings(
model: "mistral-embed",
input: texts
)
response.data.each_with_index do |embedding, idx|
puts "Embedding ##{idx}: #{embedding.embedding[0..4]}"
end
📊 Classifiers
# Moderation
response = client.moderation(
model: "mistral-moderation-latest",
input: "I hate you and want to hurt people"
)
puts "Content: #{response.results[0].categories}"
# Chat moderation
# Use custom Messages type
messages = [
Messages.new(role: "user", content: "I want to hate someone."),
Messages.new(role: "assistant", content: "That doesn't sound good."),
]
# or String
messages = %([{"role": "user", "content": "I want to hate someone."}])
response = client.chat_moderations(
model: "mistral-chat-moderation-latest",
input: messages
)
puts "Content: #{response.results[0].categories}"
✔️ TODO
- Add Chat Completion
- Add Embeddings
- Add Tests
- Add FIM
- Add Agents
- Add Classifiers
- Add Files
- Add Fine Tuning
🤝 Contributing
- Fork it (https://github.com/Skrebnevf/crystal-mistral/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
🏠 Contributors
- f.skrebnev - creator and maintainer
- @hope_you_die - TG
Repository
crystal-mistral
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- about 3 hours ago
- June 22, 2025
License
MIT License
Links
Synced at
Mon, 23 Jun 2025 19:02:07 GMT
Languages