Text Complete
This plugin allows you to auto-complete text and string fields using OpenAI Chat GPT models.
Installation
npm i @adminforth/text-complete --save
npm i @adminforth/completion-adapter-open-ai-chat-gpt --save
Go to https://platform.openai.com/, open Dashboard
-> API keys
-> Create new secret key
. Paste value in your .env
file:
...
OPENAI_API_KEY=your_key
Add plugin installation to any text or string column.
For example let's add it for title and description in aparts
resource configuration which we created in Getting Started tutorial.
./resources/apartments.ts
import TextCompletePlugin from '@adminforth/text-complete';
import CompletionAdapterOpenAIChatGPT from "@adminforth/completion-adapter-open-ai-chat-gpt";
export const admin = new AdminForth({
...
resourceId: 'aparts',
columns: [
...
],
plugins: [
...
new TextCompletePlugin({
openAiApiKey: process.env.OPENAI_API_KEY as string,
fieldName: 'title',
adapter: new CompletionAdapterOpenAIChatGPT({
openAiApiKey: process.env.OPENAI_API_KEY as string,
model: 'gpt-4o', // default "gpt-4o-mini"
expert: {
temperature: 0.7 //Model temperature, default 0.7
}
}),
}),
new TextCompletePlugin({
fieldName: 'description',
adapter: new CompletionAdapterOpenAIChatGPT({
openAiApiKey: process.env.OPENAI_API_KEY as string,
}),
// expert: {
// maxTokens: 50, // token limit to generate for each completion. 50 is default
// promptInputLimit: 500, // Limit in characters of edited field to be passed to Model. 500 is default value
// debounceTime: 300, // Debounce time in milliseconds. 300 is default value
// }
}),
]
...
});
Here is how it looks:
!