Arebis.Core.Services.Translation.OpenAI
8.0.2
dotnet add package Arebis.Core.Services.Translation.OpenAI --version 8.0.2
NuGet\Install-Package Arebis.Core.Services.Translation.OpenAI -Version 8.0.2
<PackageReference Include="Arebis.Core.Services.Translation.OpenAI" Version="8.0.2" />
<PackageVersion Include="Arebis.Core.Services.Translation.OpenAI" Version="8.0.2" />
<PackageReference Include="Arebis.Core.Services.Translation.OpenAI" />
paket add Arebis.Core.Services.Translation.OpenAI --version 8.0.2
#r "nuget: Arebis.Core.Services.Translation.OpenAI, 8.0.2"
#:package Arebis.Core.Services.Translation.OpenAI@8.0.2
#addin nuget:?package=Arebis.Core.Services.Translation.OpenAI&version=8.0.2
#tool nuget:?package=Arebis.Core.Services.Translation.OpenAI&version=8.0.2
Arebis.Core.Services.Translation.OpenAI
.NET Core translation service implementation based on OpenAI's GPT models.
Translation Services
OpenAITranslationService
Add the OpenAI client library to your .NET project by installing the NuGet package via your IDE or by running the following command in the .NET CLI:
dotnet add package OpenAI
Next, register the ChatClient and OpenAITranslationServices the following way:
builder.Services.AddSingleton<ChatClient>(serviceProvider =>
{
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
var model = "gpt-5.2";
return new ChatClient(model, apiKey);
});
builder.Services.AddTransient<ITranslationService, OpenAITranslationService>();
In configuration, 3 prompts can be overridden:
- OpenAI:JsonPrompt
- OpenAI:Translation:TranslationPrompt
- OpenAI:Translation:FormatPrompt
The JsonPrompt is used to enforce JSON output.
The TranslationPrompt is used to set the overall behavior of the model.
The FormatPrompt is used to specify the output format (JSON schema and languages).
The FormatPrompt must contain substitution fields {fromLanguage}, {toLanguages} and {mimeType}.
Here an example containing the default prompts:
{
"OpenAI": {
"JsonPrompt": "You are a non-interactive backend processor.
Respond exclusively with raw JSON. [no prose]
Any output that is not valid JSON is a failure.
Never include markdown, comments, or natural language.
Never engage in dialogue.
If an error occurs, return { \"error\": \"<description>\" }.",
"Translation": {
"TranslationPrompt": "You are a professional translator that translates text from one language to another while preserving the original meaning, tone and context.",
"FormatPrompt": "Return only the translation in a single machine processable JSON output with for each target language a property named with the language code (e.g. \"fr-FR\")
and as value the full translated text.
If the input is valid HTML, translate only the human-readable text nodes to the target languages, keeping the translated text as HTML.
All tags, attributes, whitespace, entities, and structure must remain unchanged except for translated text nodes.
Do not normalize, prettify, or reformat the markup.
No prose. No markdown. No dialogue.
Translate the following source in \"{fromLanguage}\" with MIME-type \"{mimeType}\" into the following target languages: {toLanguages}:"
}
}
}
In a typical scenario, you would only override the TranslationPrompt to provide additional role and context information.
See also:
Related developer resources:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Arebis.Core (>= 8.0.7)
- Arebis.Core.Services.Interfaces (>= 6.1.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- OpenAI (>= 2.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.