Angular Common Types - AIProvider
An object responsible for sending requests to an AI service.
import { AIProvider } from "devextreme/common/ai-integration"
Type:
sendRequest
A function that sends a request to an AI service.
Type:
Function parameters:
params:
Request parameters.
Return Value:
An object with AI response.
app.component.ts
- import { Component } from '@angular/core';
- import { HttpClient, HttpHeaders } from '@angular/common/http';
- import { AIIntegration } from 'devextreme-angular/common/ai-integration';
- // ...
- export class AppComponent {
- constructor(private http: HttpClient) {}
- provider = {
- sendRequest: ({ prompt }) => {
- const headers = new HttpHeaders({
- // Add any custom headers here
- });
- const body = JSON.stringify({ prompt });
- const promise = this.http
- .post<{ output?: string }>('https://example.org/post', body, {
- headers,
- signal: controller.signal,
- })
- .toPromise()
- .then((result) => result.output || '');
- return {
- promise,
- abort: () => {
- // Add an abort request
- },
- };
- },
- };
- aiIntegration = new AIIntegration(provider);
- }