c This is an unofficial wrapper library around the Mistral API. I am not affiliated with Mistral and this library is not endorsed or supported by them.
None.
You can install directly from Nuget : dotnet add package GoatReview.MistralDotNetClient
The client is the main entry point to the Mistral API. You can create a new client by calling the Build method with your API key.
MistralClient.Build(API_KEY);If you don't have API key, you can create one direclty from the Mistral website.
Before starting to explain the features, it's important to understand the main concepts of monads and how they are used in this library.
Each feature return an object of Either<InternalError, XXX> where XXX is the expected return type of the feature. The Either type is a monad that can be either a Left or a Right. The Left side is used to represent an error and the Right side is used to represent a success.
To handle the result of a feature, you can use the Match method of the Either object. The Match method takes two functions as parameters. The first function is called if the Either object is a Left and the second function is called if the Either object is a Right.
var result = MistralClient.Build(API_KEY)
.CreateEmbedding(embedding);
// Result is Either<InternalError, XXX>
var response = result.Match(
success => success, // Handle the type XXX
error => throw new Exception(error.Message) // Handle the error InternalError
);The InternalError class contains the error reason and the error message of the request.
You can use GetUnsafe() if you prefer having an exception thrown when a Monad is not in the desired state.
try
{
var result = MistralClient.Build(API_KEY)
.CreateEmbedding(embedding)
.GetUnsafe();
// Result is XXX or throw a MistralClientException if the process failed
} catch (MistralClientException e) {
// Handle the exception
}It can be used for all features.
In order to create completion, you need to create a ChatCompletion object. The ChatCompletion object is created using the ChatCompletion.Builder class.
var chat = ChatCompletion.Builder()
.WithUserMessage("What is the current date ?")
.Build();
MistralClient.Build(API_KEY)
.CreateChatCompletion(chat);In order to create embedding, you need to create a Embedding object. The Embedding object is created using the Embedding.Builder class.
var embedding = Embedding.Build().WithInputs(new[] {"Hello", "World"}).Create();
MistralClient.Build(API_KEY)
.CreateEmbedding(embedding);The MIT License (MIT)
Copyright (c) 2019 - 2024 Goat Review and other authors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.