ChatGPT, and generative AI in general, can be used to set the tone of a sentence or rephrase content by expanding or shortening it, and offers many interesting applications in the field of document processing. The following sample project shows how to integrate ChatGPT functionality into a document editor to rephrase the sentence at the current input position.
Requirements: OpenAI Account
To use this example, you need to create an OpenAI account with a generated API Key.
Under User -> API Keys, create a new API Key by clicking Create new secret key.
In the example, the additional ribbon group is created as an HTML document located in the wwwroot folder that is dynamically loaded into the DOM:
Calling the Controller
The function basically gets the text of the paragraph at the current input position and sends a ChatGPTRequest object to the RequestAPI method. The return value is used to replace the paragraph text after a successful request.
On the server side, the controller method creates a prompt from predefined prompts for the specific call by combining it with the given text. This prompt is then sent to the OpenAI Completions API.
We have created the following sample prompts as part of the included constants:
You can download the sample project for your own testing from our GitHub repository.