- Adding prompt response
- Executing prompt
Contact Support
Methods in ASP.NET CORE AI AssistView control
17 Sep 20246 minutes to read
Adding prompt response
You can use the addPromptResponse
public method to add the prompts and responses to the AI AssistView. You can add the it either as a string
or object
collection.
Adding responses as string.
You can add string response, by passing it as argument for the addPromptResponse('Response')
method which adds as the response of last added prompt.
@using Syncfusion.EJ2.InteractiveChat;
<div class="aiassist-container" style="height: 350px; width: 650px;">
<button id="addStringResponse">Add String Response</button>
<ejs-aiassistview id="aiAssistView" promptRequest="onPromptRequest" created="onCreated"></ejs-aiassistview>
</div>
<script>
var assistObj;
function onCreated() {
assistObj = this;
}
function onPromptRequest(args) {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AI AssistView control to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
assistObj.addPromptResponse(defaultResponse);
}, 2000);
}
document.addEventListener('click', function (event) {
if (event.target && event.target.id === 'addStringResponse') {
assistObj.addPromptResponse('Dynamic response');
}
});
</script>
<style>
#addStringResponse {
margin-bottom: 10px;
}
</style>
Adding responses as object.
You can add object response, by passing the prompt and response as a collection as argument for the addPromptResponse({prompt: 'Prompt text', response: 'Response text'})
method which adds as a new prompt and response in the AI AssistView.
@using Syncfusion.EJ2.InteractiveChat;
<div class="aiassist-container" style="height: 350px; width: 650px;">
<button id="addObjectResponse">Add Object Response</button>
<ejs-aiassistview id="aiAssistView" promptRequest="onPromptRequest" created="onCreated"></ejs-aiassistview>
</div>
<script>
var assistObj;
function onCreated() {
assistObj = this;
}
function onPromptRequest() {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AI AssistView control to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
assistObj.addPromptResponse(defaultResponse);
}, 2000);
}
document.addEventListener('click', function (event) {
if (event.target && event.target.id === 'addObjectResponse') {
assistObj.addPromptResponse({ prompt: 'What is AI?', response: 'AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.' });
}
});
</script>
<style>
#addObjectResponse {
margin-bottom: 10px;
}
</style>
Executing prompt
You can use the executePrompt
method to execute the prompts dynamically in the AI AssistView. It accepts prompts as string values, which triggers the promptRequest
event and performs the callback actions.
@using Syncfusion.EJ2.InteractiveChat;
<div class="aiassist-container" style="height: 350px; width: 650px;">
<button id="executePrompt">Execute Prompt</button>
<ejs-aiassistview id="aiAssistView" promptRequest="onPromptRequest" created="onCreated"></ejs-aiassistview>
</div>
<script>
var assistObj;
var prompts = @Html.Raw(promptsJson);
function onCreated() {
assistObj = this;
}
function onPromptRequest(args) {
setTimeout(() => {
var defaultResponse = 'For real-time prompt processing, connect the AI AssistView control to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
assistObj.addPromptResponse(defaultResponse);
}, 2000);
}
document.addEventListener('click', function (event) {
if (event.target && event.target.id === 'executePrompt') {
assistObj.executePrompt('What is the current temperature?');
}
});
</script>
<style>
#executePrompt {
margin-bottom: 10px;
}
</style>