Interface

OpenAITextAdapterConfig (ai/adapters)

@ckeditor/ckeditor5-ai/src/adapters/openaitextadapter

interface

The configuration for the OpenAI adapter.

The properties defined in this config are set in the config.ai.openAI namespace.

ClassicEditor
	.create( editorElement, {
		ai: {
		    openAI: {
		        requestHeaders: {
		            Authorization: 'Bearer OPENAI_API_KEY'
		        }
		    }
		}
	} )
	.then( ... )
	.catch( ... );

See the full AI configuration.

See all editor options.

Filtering

Properties

  • apiUrl : string | undefined

    The URL to which the AI service request will be sent.

    By default, requests are sent to the OpenAI API service. Change this value to make requests to Azure OpenAI API or use proxy endpoint in your application instead.

    Defaults to 'https://api.openai.com/v1/chat/completions'.

  • requestHeaders : RequestHeaders | undefined

    Object with headers to set in the request to the AI service API.

    If the provided value is an object, it is simply used as provided.

    If you are connecting directly to the OpenAI API, use your OpenAI API key in the following way:

    {
    	ai: {
    		openAI: {
    			requestHeaders: {
    		 		'Authorization': 'Bearer YOUR_API_KEY'
    			}
    			// ...
    		}
    	// ..
    	}
    }
    

    Important: use your API key ONLY in a development environment or for testing purposes! In the production environment, pass your request through a proxy endpoint.

    If you are using a proxy service to send requests to the OpenAI API, requestHeaders can be used to implement authorization for your requests.

    If the provided value is a function, it should be a function that returns a Promise which resolves with the headers object. This way, you can perform an authorization request to your application and receive the authorization token (and also implement any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.

    The function is passed actionId parameter to make it possible to further customize the headers.

    {
    	ai: {
    		openAI: {
    			requestHeaders: async () => {
    				const jwt = await fetch( 'https://example.com/jwt-endpoint' );
    
    				return {
    					'Authorization': 'Bearer ' + jwt
    				};
    			}
    			// ...
    		}
    	}
    }
    

    If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display an error notification.

  • requestParameters : RequestParameters | undefined

    Additional configuration parameters for the AI service request. Use it to customize how the AI service generates responses. Note that the value you will set here will fully overwrite the default value.

    See OpenAI API reference to learn more about available parameters.

    If the provided value is an object, it is passed to the request as provided.

    If the provided value is a function, it should be a function that returns a Promise which resolves with the request parameters object. This gives you more flexibility to provide parameters for the AI model.

    The function is passed actionId parameter to make it possible to further customize the parameters.

    If the function fails for any reason, the promise should be rejected. In this case, the feature that made the request should display an error notification.

    Defaults to:

    {
    	model: 'gpt-3.5-turbo',
    	max_tokens: 2000,
    	temperature: 1,
    	top_p: 1,
    	stream: true
    }