Skip to content

List-valued tool arguments

This example assumes using Ollama; is in scope and apiKey contains your Ollama 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
30
31
32
33
34
35
36
37
38
39
var request = new ChatRequest
{
    Model = "test-model",
    Messages =
    [
        new ChatMessage
        {
            Role = ChatMessageRole.Assistant,
            Content = string.Empty,
            ToolCalls =
            [
                new ToolCall
                {
                    Function = new ToolCallFunction
                    {
                        Name = "read_multiple_files",
                        Arguments = new Dictionary<string, object>
                        {
                            ["paths"] = new List<object>
                            {
                                "/tmp/one.txt",
                                "/tmp/two.txt",
                            },
                        },
                    },
                },
            ],
        },
    ],
};

string json = request.ToJson(SourceGenerationContext.Default);
using JsonDocument document = JsonDocument.Parse(json);
JsonElement paths = document.RootElement
    .GetProperty("messages")[0]
    .GetProperty("tool_calls")[0]
    .GetProperty("function")
    .GetProperty("arguments")
    .GetProperty("paths");