How can i pass the value from the webpage to a controller and display the results on webpage
HTML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Search.aspx.vb" Inherits="CHATGPTVB2023.Search" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 { width: 62%; }
.auto-style2 { width: 412px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:TextBox ID="Searchtx" runat="server" Width="416px"></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Style="font-weight: 700" Text="Search" Width="103px" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="AnserDisplay" runat="server"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Namespaces
VB.Net
Imports System.Data.SqlClient
Imports System.Net
Imports System.Web.Http
Imports OpenAI_API
Imports OpenAI_API.Completions
Code
VB.Net
Namespace Controllers
Public Class OpenAIController Inherits ApiController <Route("api/OpenAI/GetResult")>
Public Function GetResult(prompt As String) As IHttpActionResult 'your OpenAI API key
Dim apiKey As String = "sk-VDQT9nR9bor8MuwifUe1T3"
Dim answer As String = String.Empty
Dim openai As New OpenAIAPI(apiKey)
Dim completion As New CompletionRequest()
completion.Prompt = prompt
completion.Model = OpenAI_API.Models.Model.DavinciText
completion.MaxTokens = 4000
Dim result As Object = openai.Completions.CreateCompletionAsync(completion)
If result IsNot Nothing Then
For Each item As Object In result.Result.Completions
answer = item.Text
Next
Return Ok(answer)
Else
Return BadRequest("Not found")
End If
End Function
End Class
End Namespace