React Common Types - AIProvider

An object responsible for sending requests to an AI service.

import { AIProvider } from "devextreme/common/ai-integration"
Type:

Object

sendRequest

A function that sends a request to an AI service.

Type:

Function

Function parameters:
params:

RequestParams

Request parameters.

Return Value:

Response

An object with AI response.

App.tsx
  • import { AIIntegration } from 'devextreme-react/common/ai-integration';
  •  
  • const provider = {
  • sendRequest: ({ prompt }) => {
  • const headers = {
  • 'Content-Type': 'application/json',
  • // Add any custom headers here
  • };
  •  
  • const promise = fetch('https://example.org/post', {
  • method: 'POST',
  • headers,
  • body: JSON.stringify({ prompt }),
  • signal: controller.signal,
  • })
  • .then(async (response) => {
  • const result = await response.json();
  • return result.output || '';
  • });
  •  
  • return {
  • promise,
  • abort: () => {
  • // Add an abort request
  • },
  • };
  • },
  • };
  • const aiIntegration = new AIIntegration(provider);