Skip to content

Writer

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official Writer OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using Writer;

using var client = new WriterClient(apiKey);

Generate

Basic example showing how to create a client and make a request.

1
using var client = new WriterClient(apiKey);

Chat Client Get Response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using var client = new WriterClient(apiKey);
Meai.IChatClient chatClient = client;

// Use the MEAI IChatClient interface for chat completions.
var response = await chatClient.GetResponseAsync(
    messages: [new Meai.ChatMessage(Meai.ChatRole.User, "Generate 5 random words.")],
    new Meai.ChatOptions
    {
        ModelId = "palmyra-x-004",
    });

Console.WriteLine(response.Text);

Chat Client Streaming

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
using var client = new WriterClient(apiKey);
Meai.IChatClient chatClient = client;

// Stream chat responses using the MEAI IChatClient interface.
var enumerable = chatClient.GetStreamingResponseAsync(
    messages: [new Meai.ChatMessage(Meai.ChatRole.User, "Generate 5 random words.")],
    new Meai.ChatOptions
    {
        ModelId = "palmyra-x-004",
    });

var deltas = new List<string>();
await foreach (var update in enumerable)
{
    Console.Write(update.Text);
    deltas.Add(update.Text ?? string.Empty);
}

Chat Client Get Service Metadata

1
2
3
4
5
using var client = new WriterClient("test-api-key");
Meai.IChatClient chatClient = client;

// Retrieve metadata about the chat provider.
var metadata = Meai.ChatClientExtensions.GetService<Meai.ChatClientMetadata>(chatClient);

Chat Client Streaming Tool Calling

 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
using var client = new WriterClient(apiKey);
Meai.IChatClient chatClient = client;

// Stream chat responses with tool calling using the MEAI IChatClient interface.
// Define a simple tool that returns the current weather.
var tool = Meai.AIFunctionFactory.Create(
    (string location) => $"The weather in {location} is sunny, 72°F.",
    "get_weather",
    "Gets the current weather for a location.");

var enumerable = chatClient.GetStreamingResponseAsync(
    messages: [new Meai.ChatMessage(Meai.ChatRole.User, "What's the weather in San Francisco?")],
    new Meai.ChatOptions
    {
        ModelId = "palmyra-x-004",
        Tools = [tool],
    });

var hasContent = false;
Meai.ChatFinishReason? finishReason = null;
await foreach (var update in enumerable)
{
    if (update.Text is { Length: > 0 })
    {
        Console.Write(update.Text);
        hasContent = true;
    }

    if (update.FinishReason is not null)
    {
        finishReason = update.FinishReason;
    }
}

// The model should either respond with tool calls or text content.

Support

Priority place for bugs: https://github.com/tryAGI/Writer/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Writer/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.