Instructor.NET is a .NET implementation of the Instructor pattern for structured outputs from LLMs.
$ dotnet add package Instructor.NETA .NET port of the Python Instructor library for structured outputs from large language models.
dotnet add package Instructor.NET
ResponseModel:public class UserProfile : ResponseModel
{
public string Name { get; set; } = string.Empty;
public int Age { get; set; }
public string Email { get; set; } = string.Empty;
[JsonPropertyName("preferred_language")]
public string PreferredLanguage { get; set; } = string.Empty;
}
var client = new InstructorClient("your-api-key-here");
var userProfile = await client.CreateStructuredOutput<UserProfile>(
"Create a profile for a software developer named Alice who is 28 years old, " +
"uses alice@example.com, and prefers JavaScript"
);
Console.WriteLine($"Name: {userProfile.Name}");
Console.WriteLine($"Age: {userProfile.Age}");
Console.WriteLine($"Email: {userProfile.Email}");
Console.WriteLine($"Preferred Language: {userProfile.PreferredLanguage}");
var profile = await client.CreateStructuredOutput<UserProfile>(
"Create a profile for an experienced developer",
temperature: 0.9f,
maxTokens: 1000
);
var client = new InstructorClient(
"your-api-key-here",
"https://your-resource-name.openai.azure.com/"
);
var profile = await client.CreateStructuredOutput<UserProfile>(prompt);
Console.WriteLine($"Raw JSON response: {profile.RawResponse}");
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.