In many business applications, users enter or receive unstructured text: customer feedback, internal notes, support tickets, reports, and more. This content represents valuable information, but it’s difficult to leverage without specific processing.
This is where artificial intelligence becomes a powerful tool: by automatically analyzing the written content of a 4D Write Pro document, it can extract useful metadata for understanding, sorting, or prioritizing.
In this demonstration, we’ve implemented a complete scenario of automatic analysis of 4D Write Pro documents using AI. From a simple text, the AI is capable of:
- Generating a concise title reflecting the content
- Identifying the tone (positive, negative, informative, urgent…)
- Suggesting classification tags
- Evaluating the document’s writing quality
The goal is clear: automatically enrich documents with usable metadata, without changing the user experience.
This feature is useful in many real-world situations:
- Automatic sorting of incoming messages: based on tone and urgency
- Document classification: by type, theme, or business domain
- Detection of content to improve: low quality score = alert
- Statistics on customer sentiment: track trends in feedback
How does it work?
The user types or pastes text into a 4D Write Pro-based interface. By clicking the “Save” button, the document is stored in the database and automatically analyzed via AI. The results of the analysis are then saved to the database and can be displayed in the interface to enrich the document.
HDI: Categorize 4D Write Pro documents
Here’s the metadata we want to extract automatically using AI:
- Title: A concise title that reflects the subject and tone of the document
- Tone: Positive, negative, neutral, informative, urgent, etc., with an emoji for quick visual reference
- Tags: 1 to 3 business or thematic categories related to the content
- Writing quality: A score out of 5 based on clarity, structure, and spelling, with an explanatory comment
Technical Details
1. Analysis triggered upon saving
When the user clicks the “Save” button, a method launches the document analysis via AI. Then it saves both the document and the AI-generated metadata in the database:
var $infos : Object
$infos := cs.ChatManagement.new().computeInfo(WP Get text($doc); $apiKey)
var $ent : cs.DocumentEntity
$ent:=ds.Document.new()
$ent.WP:=$doc
$ent.Title:=$infos.title
$ent.Tone:=$infos.tone
$ent.Tone_Emoji:=$infos.tone_emoji
$ent.Tags:=$infos.tags
$ent.Quality_Score:=$infos.quality_score
$ent.Quality_Comment:=$infos.quality_comment
$ent.save()
2. Prompt construction
The computeInfo method builds both the system prompt and the user prompt to query the AI.
The system prompt explains and guides the AI in its analysis and response. The user prompt contains only the 4D Write Pro document content to be analyzed.
$systemPrompt:="Analyze the following text and provide the following information: \n"
$systemPrompt+="1. Suggest a short and relevant title for the document..."
$systemPrompt+="...\n"
$systemPrompt+="Respond in the following JSON format (no balise code):\n"
$systemPrompt+="{\"title\": \"string\", ... }"
$messages.push({role: "system"; content: $systemPrompt})
$messages.push({role: "user"; content: $document})
$result:=cs.AIManagement.new($apiKey).generateInfo($messages)
return $result
3. OpenAI call class
The AIManagement class encapsulates the logic for calling OpenAI using the gpt-4o-mini model with 4D AIKit:
Class constructor($openAIKey : Text)
This.clientAI:=cs.AIKit.OpenAI.new($openAIKey)
Function generateInfo($messages : Collection) : Object
var $result:=This.clientAI.chat.completions.create($messages; {model: "gpt-4o-mini"})
return JSON Parse($result.choice.message.text)
4. Example AI result
Here’s an example of a response returned by the AI:
{
"title": "Disappointment After Latest Product Update",
"tone": "Negative",
"tone_emoji": "😠",
"tags": "Product Feedback, Software, Support",
"quality_score": 5,
"quality_comment": "Well-written and structured message, clear and professional."
}
Next
This demonstration shows how easily you can integrate an AI layer into your 4D Write Pro documents to automatically enrich them and extract structured data.
The model presented here is modular, adaptable, and reusable. It can be applied to various types of content, including emails, support tickets, internal notes, and user comments.
It integrates seamlessly into your existing 4D applications, without altering the user experience, while opening new possibilities for automation, sorting, and analysis. Here, AI acts as an invisible assistant, able to automatically enrich your documents and simplify their processing.
And you, what kind of intelligence would you like to add to your application or documents? Share your ideas, use cases, or questions on the 4D forum; the community is there to collaborate and inspire!
