mistralai_client_dart 0.0.2 mistralai_client_dart: ^0.0.2 copied to clipboard
This is an unofficial Dart/Flutter client for the Mistral AI API.
Mistral AI client for Dart #
Description #
This is an unofficial Dart/Flutter client for the Mistral AI API.
The implementation is inspired by the official Mistral AI JS client.
Overview (current state) #
The package is supporting Mistral AI API (0.0.1) at the moment.
Installation #
dart pub add mistralai_client_dart
Usage #
Create client #
import 'package:mistralai_client_dart/mistralai_client_dart.dart';
final client = MistralAIClient(apiKey: 'your api key here');
List models #
final modelsResult = await client.listModels();
final models = modelsResult.data.map((e) => e.id).toList();
print(models.join(', '));
Chat #
final params = ChatParams(
model: 'mistral-tiny',
messages: const [
ChatMessage(role: 'user', content: 'Hello chat!'),
],
);
final chatCompletion = await client.chat(params);
final chatMessage = chatCompletion.choices[0].message;
print(chatMessage);
Chat stream #
final stream = client.streamChat(params);
await for (final completionChunk in stream) {
final chatMessage = completionChunk.choices[0].delta?.content;
if (chatMessage != null) {
print(chatMessage);
}
}
Embeddings #
final embeddings = await client.embeddings(
const EmbeddingParams(
model: 'mistral-embed',
input: ['Hello chat!'],
),
);
for (final data in embeddings.data) {
print(data.embedding);
}
Resources #
You can check the official Mistral AI docs.
Contributing #
For contributing guide please see CONTRIBUTING.md.