![]() |
VOOZH | about |
dotnet add package Aspose.LLApi --version 1.3.0
NuGet\Install-Package Aspose.LLApi -Version 1.3.0
<PackageReference Include="Aspose.LLApi" Version="1.3.0" />
<PackageVersion Include="Aspose.LLApi" Version="1.3.0" />Directory.Packages.props
<PackageReference Include="Aspose.LLApi" />Project file
paket add Aspose.LLApi --version 1.3.0
#r "nuget: Aspose.LLApi, 1.3.0"
#:package Aspose.LLApi@1.3.0
#addin nuget:?package=Aspose.LLApi&version=1.3.0Install as a Cake Addin
#tool nuget:?package=Aspose.LLApi&version=1.3.0Install as a Cake Tool
Aspose.LLApi is a robust .NET library designed for interacting seamlessly with Large Language Model (LLM) backends. It provides intuitive clients for various operations such as Chat Completion, Tokenization, Embeddings, Document Reranking, Slots management, LoRA adapters, and advanced structured prompt composition.
Install via NuGet:
dotnet add package Aspose.LLApi
Or install from a local package:
dotnet add package Aspose.LLApi --source ./nupkg
Instantiate the main client LLaMACppClient:
using Aspose.LLaMACpp;
var client = new LLaMACppClient("https://llm-server.example.com/v1", "optional-api-key");
var chatClient = client.GetChatCompletionsClient();
var request = new ChatCompletionRequest
{
Model = "my-model",
Messages = [
new ChatCompletionMessage { Role = "user", Content = "Tell me a joke!" }
]
};
var response = await chatClient.CreateChatCompletionAsync(request);
Console.WriteLine(response.Choices[0].Message.Content);
Provides methods for chat-based interactions with streaming support, structured data responses, and flexible message composition.
CreateChatCompletionAsync(ChatCompletionRequest request)
Retrieves standard chat completions.
CreateChatCompletionAsync(string model, string prompt)
Simplified method for quick interactions.
CreateChatCompletionAsync<T>(string model, string prompt)
Automatically deserializes structured JSON responses into custom types.
CreateChatCompletionAsStreamAsync(ChatCompletionRequest request)
Supports streaming responses for incremental output.
var request = new ChatCompletionRequest
{
Model = "structured-model",
Messages = [
new ChatCompletionMessage { Role = "user", Content = "List three programming languages." }
],
Stream = true
};
await foreach (var chunk in chatClient.CreateChatCompletionAsStreamAsync(request))
{
Console.Write(chunk);
}
The AIPrompt class hierarchy (AIText, AIInstructions) is specifically designed to isolate textual data clearly
from instructional content when communicating with LLMs. This isolation ensures that even less sophisticated language
models distinctly recognize the difference between commands they should execute (instructions) and content they should
merely reference or use as context (text).
This structured separation is critical when incorporating unpredictable user inputs into your prompts, allowing you to safely wrap arbitrary user-provided text within precise, well-defined instructions. The result is significantly improved reliability and clarity in model responses.
Explicit Prompt Roles:
AIText clearly labels user or context content as non-instructional, preventing unintended execution by the model.
Conversely, AIInstructions explicitly mark segments as commands that the LLM must interpret and act upon.
Recursive Composition:
AIPrompt supports nesting and placeholders ({0}, {1}) that allow structured, hierarchical prompt assembly. This
recursive approach simplifies dynamic prompt generation while maintaining strict isolation between instructions and
textual data.
Metadata and Prefixes:
Each prompt subclass (e.g., AIText, AIInstructions) has metadata defining prefix symbols and system-level
interpretation guidelines, further aiding even basic language models in correctly distinguishing between instruction
layers and plain text.
AIText:
Marks purely informational or user-provided text, explicitly preventing accidental interpretation as executable
instructions.
AIInstructions:
Represents explicit commands and directives intended to instruct the model's behavior.
Here's how you clearly wrap unpredictable user input (AIText) within carefully structured instructions (
AIInstructions), ensuring safe and clear execution:
// Raw user input safely isolated as text
var userQuestion = new AIText(userProvidedInput);
// Clearly defined instruction wrapping user content
var structuredPrompt = new AIInstructions(
"You are an expert developer answering user questions. Respond briefly and clearly to this question:
{0}",
userQuestion
);
// Generate the final request
var request = new ChatCompletionRequest
{
Model = "expert-dev-model",
Messages = [
new ChatCompletionMessage { Role = "user", Content = structuredPrompt.ToString() }
]
};
var response = await chatClient.CreateChatCompletionAsync(request);
Console.WriteLine(response.Choices[0].Message.Content);
In this scenario, AIText ensures the user's potentially ambiguous input is never mistaken for instructions, while
AIInstructions gives the LLM clear guidance on exactly how to handle that input.
ChatCompletionRequest: Structure for chat requests.ChatCompletionResponse: Response containing generated content.ChatCompletionMessage: Individual messages for interaction.TokenizeRequest/DetokenizeRequest: Requests for token conversions.NonOaiEmbeddingRequest/NonOaiEmbeddingResponse: Text embedding structures.AIPrompt) for complex prompt-building.Aspose.LLApi is distributed under the .
For NuGet packaging, include the license file named exactly as:
LICENSE.txt
in the root directory of your NuGet package.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Aspose.LLApi:
| Package | Downloads |
|---|---|
|
Aspose.MeetingNotes
SDK for converting meeting audio into structured text notes and actionable tasks |
This package is not used by any popular GitHub repositories.