следующий код дает базовую подсказку о том, что и на какой язык следует перевести
Код: Выделить всё
public async Task TranslateVariant(TranslateModel model)
{
_model = new TranslateModel()
{
Default = model.Default,
Variant = model.Variant,
Property = model.Property,
Id = model.Id
};
_textModel = new GenerateTextModel()
{
Prompt = $"Translate the following text from {_model.Default} to the language of the language code {_model.Variant} Only answer with the translation for that specific text nothing else. This is the text you should translate: {_model.Property} "
};
var choices = await _chatGPTService.CreateMultipleOptionsForTranslation(_textModel);
return choices;
}
Код: Выделить всё
{
var api = new OpenAIAPI(_settings.ApiKey);
var choices = new List();
for (int i = 0; i < 3; i++)
{
var result = await api.Chat.CreateChatCompletionAsync(new ChatRequest()
{
Model = _model,
NumChoicesPerMessage = 1,
Temperature = 0.7,
MaxTokens = 2000,
PresencePenalty = 0.7,
Messages = new ChatMessage[]
{
new ChatMessage(ChatMessageRole.User, model.Prompt)
}
});
var choice = result.Choices[0].Message.Content.Trim();
bool isDuplicate = choices.Contains(choice);
if (!isDuplicate)
{
choices.Add(choice);
var optionNumber = choices.Count;
model.Prompt += $"{(optionNumber > 1 ? "and " : "")}Make it different than the previous translation {optionNumber}: {choice}";
}
}
return choices;
}
Подробнее здесь: https://stackoverflow.com/questions/764 ... and-prompt
Мобильная версия