Skip to content

Chat Client Request Includes Role

This example assumes using Mistral; is in scope and apiKey contains your Mistral API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var handler = new RecordingHandler();
using var httpClient = new HttpClient(handler);
using var client = new MistralClient("test-key", httpClient, disposeHttpClient: false);

Meai.IChatClient chatClient = client;
await chatClient.GetResponseAsync(
    [
        new Meai.ChatMessage(Meai.ChatRole.System, "Use metric units."),
        new Meai.ChatMessage(Meai.ChatRole.User, "What is the weather in Paris?"),
        new Meai.ChatMessage(Meai.ChatRole.Assistant,
        [
            new Meai.TextContent("I'll check."),
            new Meai.FunctionCallContent(
                "call-1",
                "get_weather",
                new Dictionary<string, object?> { ["location"] = "Paris" }),
        ]),
        new Meai.ChatMessage(Meai.ChatRole.Tool,
        [
            new Meai.FunctionResultContent("call-1", "18°C and sunny"),
        ]),
    ],
    new Meai.ChatOptions
    {
        Instructions = "Respond concisely.",
    });

using var request = JsonDocument.Parse(handler.RequestBody!);
var messages = request.RootElement.GetProperty("messages");