Я хочу отправить вопрос на сервер, а затем сервер ответит на мой вопрос, и я хочу показать предыдущие вопросы и ответы на основе search.htmlcs
Код: Выделить всё
@* @page
@model SearchModel
@{
ViewData["Title"] = "Search Document";
}
Search your documents
@foreach(string key in Model.ConversationHistory.Keys)
{
@if(key == "userInput")
{
@Model.ConversationHistory[key]
}
else
{
@Model.ConversationHistory[key]
}
}
[i]
[/i]
*@
@page
@model SearchModel
@{
ViewData["Title"] = "Search Document";
}
Search your documents
@foreach (var message in Model.ConversationHistory)
{
@message.Value
}
[i]
[/i]
@section Scripts {
}
I used the Ajax-Query but I think I have problem beacuse when I created my project I difn't use Controller the back-end code in the search.htmlcs.cs
using AzOpenAIChatDemo.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Text;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Text.Json;
using AzOpenAIChatDemo.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace AzOpenAIChatDemo.Pages
{
public class SearchModel : PageModel
{
private readonly IAzOpenAIService _azOpenAIService;
private readonly ILogger _searchLogger;
public Dictionary ConversationHistory { get; set; } = new Dictionary();
public SearchModel(IAzOpenAIService azOpenAIService, ILogger searchLogger)
{
this._azOpenAIService = azOpenAIService;
this._searchLogger = searchLogger;
public void OnGet()
{
public async void OnPost(stringchatInput)
{
ConversationHistory.Add("userInput", ChatInput);
var ответ = _azOpenAIService.GenerateTextAsync(chatInput);
var content = response.Result.Value.Choices[0].Message.Content;
StringBuilder sb = new StringBuilder();
sb.Append("\n\n\n");
sb.Append(content);
sb.Append("\n\n\n");
ConversationHistory.Add("chatResponse", sb.ToString());
}
Источник: https://stackoverflow.com/questions/781 ... d-web-page
Мобильная версия