@dotcms/client
Version:
Official JavaScript library for interacting with DotCMS REST APIs.
66 lines (65 loc) • 2.47 kB
TypeScript
import { DotCMSAISearchParams, DotCMSBasicContentlet, DotCMSClientConfig, DotErrorAISearch, DotHttpClient, DotRequestOptions, DotCMSAISearchResponse } from '@dotcms/types';
import { BaseApiClient } from '../../base/api/base-api';
import { OnFullfilled, OnRejected } from '../shared/types';
/**
* Class for executing AI searches.
*
* @template T - The type of the contentlet.
* @param config - The configuration for the client.
* @param requestOptions - The request options for the client.
* @param httpClient - The HTTP client for the client.
* @param params - The parameters for the search.
* @param prompt - The prompt for the search.
*/
export declare class AISearch<T extends DotCMSBasicContentlet> extends BaseApiClient {
#private;
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient, prompt: string, indexName: string, params?: DotCMSAISearchParams);
/**
* Executes the AI search and returns a promise with the search results.
*
* @param onfulfilled - Callback function to handle the search results.
* @param onrejected - Callback function to handle the search error.
* @returns Promise with the search results or the error.
* @example
* ```typescript
* const results = await client.ai.search('machine learning articles', 'content_index', {
* query: {
* limit: 20,
* contentType: 'BlogPost',
* languageId: '1' // or 1
* },
* config: {
* threshold: 0.7
* }
* });
* ```
* @example
* ```typescript
* client.ai.search('machine learning articles', 'content_index', {
* query: {
* limit: 20,
* contentType: 'BlogPost',
* languageId: '1' // or 1
* },
* config: {
* threshold: 0.7
* }
* }).then((results) => {
* console.log(results);
* }).catch((error) => {
* console.error(error);
* });
* ```
*/
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<DotCMSAISearchResponse<T> | DotErrorAISearch>;
private fetch;
/**
* Builds URLSearchParams from the SDK interface, mapping to backend parameter names.
* Only includes parameters that have values.
*
* @param params - Search parameters with SDK naming
* @returns URLSearchParams with backend parameter names
* @private
*/
private buildSearchParams;
}