Files
Beam/Beam.Temporary.Cli/QuickAndDirtyJanitor.cs
T

26 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenAI;
using OpenAI.Chat;
namespace Beam.Temporary.Cli {
public class QuickAndDirtyJanitor {
static OpenAIClient client;
static QuickAndDirtyJanitor() {
var key = Environment.GetEnvironmentVariable("OPEN_AI_KEY");
client = new OpenAIClient(key);
}
public static async Task<IDocument> TranslateAsync(IDocument document) {
var chatCompletion = await client.GetChatClient("gpt-4.1").CompleteChatAsync(
ChatMessage.CreateSystemMessage("Translate the following text into english. If any part of the text has no direct English translation, you may choose to leave it as is. In either case, make sure to leave footnotes for any difficult to translate words. You must translate the whole text and output only your translation and footnotes. No other comments are necessary."),
ChatMessage.CreateUserMessage("From UNKNOWN to ENGLISH.\n" + document.ToString()));
return new StringDocument(document.Filename, chatCompletion.Value.Content.DefaultIfEmpty().Select((x) => x?.Text).Aggregate((x,y) => $"{x}{y}"));
}
}
}