Мой исходный код был таким (самая важная часть думаю, это тот, у которого есть комментарии):
Код: Выделить всё
@{
foreach (var Interaction in Interactions) {
@Interaction.Prompt
@{
if (Interaction.Answer != null)
{ @Interaction.Answer.Content[0].Text; }
else
{
...
}
}
}
}
path stuff...
@code {
private string UserInput { get; set; } = string.Empty;
private List Interactions = new List();
private async Task SubmitInput()
{
if (!string.IsNullOrEmpty(UserInput))
{
// Add the prompt to the list with a "null" answer initially
var interaction = new GPTInteraction(UserInput, null, Interactions.Count);
Interactions.Add(interaction);
// Clear input field
UserInput = string.Empty;
// Notify the UI
StateHasChanged();
// Get the response asynchronously
var completion = await GPTAPIResultService.LoadGPTResultAsync(interaction.Prompt);
// Update the placeholder with the actual completion
interaction.Answer = completion;
// Notify the UI
StateHasChanged();
}
}
}
Код: Выделить всё
using OpenAI.Chat;
namespace GPTStandards.Data.GPTAPI;
public class GPTInteraction(string prompt, ChatCompletion? completion, int id)
{
public string Prompt { get; set; } = prompt;
public ChatCompletion? Answer { get; set; } = completion;
public int ID { get; set; } = id;
}

Подробнее здесь: https://stackoverflow.com/questions/792 ... nd-part-is