mistralai_client_dart_flutter_flow

Last updated:

0 purchases

mistralai_client_dart_flutter_flow Image
mistralai_client_dart_flutter_flow Images
Add to Cart

Description:

mistralai client dart flutter flow

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.
FlutterFlow #
This is a special version of the Mistral AI client that supports FlutterFlow 4.1 with Flutter 3.13.7.
Installation #
dart pub add mistralai_client_dart_flutter_flow
copied to clipboard
Usage #
Create client #
import 'package:mistralai_client_dart_flutter_flow/mistralai_client_dart_flutter_flow.dart';

final client = MistralAIClient(apiKey: 'your api key here');
copied to clipboard
List models #
final modelsResult = await client.listModels();
final models = modelsResult.data.map((e) => e.id).toList();
print(models.join(', '));
copied to clipboard
Chat #
final params = ChatParams(
model: 'mistral-small-latest',
messages: const [
ChatMessage(role: 'user', content: 'Hello chat!'),
],
);
final chatCompletion = await client.chat(params);
final chatMessage = chatCompletion.choices[0].message;
print(chatMessage);
copied to clipboard
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);
}
}
copied to clipboard
Embeddings #
final embeddings = await client.embeddings(
const EmbeddingParams(
model: 'mistral-embed',
input: ['Hello chat!'],
),
);
for (final data in embeddings.data) {
print(data.embedding);
}
copied to clipboard
Function calling #
String retrievePaymentStatus(Map<String, String> data, String transactionId) =>
'{"status": ${data[transactionId]}}';

final namesToFunctions = {
'retrievePaymentStatus': (String transactionId) =>
retrievePaymentStatus(paymentStatusData, transactionId),
};

final tools = [
const ToolsFunction(
name: 'retrievePaymentStatus',
description: 'Get payment status of a transaction',
parameters: [
ToolsFunctionParameter(
name: 'transactionId',
type: 'string',
description: 'The transaction ID',
isRequired: true,
),
],
).toChatParamsFormat(),
];

var chatResponse = await client.chat(
ChatParams(
model: 'mistral-large-latest',
messages: messages,
tools: tools,
toolChoice: 'auto',
),
);

final toolCall = chatResponse.choices[0].message.toolCalls?[0];
if (toolCall != null && toolCall.type == 'function') {
final functionName = toolCall.function!.name;
final functionParams = toolCall.function!.argumentsMap;

print('calling functionName: $functionName');
print('functionParams: $functionParams');

final functionResult = namesToFunctions[functionName]!(
functionParams['transactionId']! as String,
);

messages.add(
ChatMessage(role: 'tool', content: functionResult, name: functionName),
);

chatResponse = await client.chat(
ChatParams(
model: model,
messages: messages,
tools: tools,
toolChoice: 'auto',
),
);

print(chatResponse.choices[0].message.content);
}
copied to clipboard
Resources #
You can check the official Mistral AI docs.
Contributing #
For contributing guide please see CONTRIBUTING.md.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.