Methods in Angular AI AssistView component
22 Aug 20257 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 a String
You can add a response as a string by passing it as an argument to the addPromptResponse('Response') method. This will append the response to the last prompt added to the conversation.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<button id="addStringResponse" (click)="buttonClick()">Add String Response</button>
<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component 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.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
public buttonClick = () => {
this.aiAssistViewComponent.addPromptResponse('Dynamic response');
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Adding Responses as object
You can add an object response by passing the prompt and response as a collection to the addPromptResponse({prompt: 'Prompt text', response: 'Response text'}) method. This will add a new prompt and its corresponding response to the AI AssistView.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<button id="addObjectResponse" (click)="buttonClick()">Add Object Response</button>
<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component 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.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
public buttonClick = () => {
this.aiAssistViewComponent.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.' });
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));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.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<button id="executePrompt" (click)="buttonClick()">Execute Prompt</button>
<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component 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.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
public buttonClick = () => {
this.aiAssistViewComponent.executePrompt('What is the current temperature?');
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));