From e6a234bcb88d8c43451727e309c2307c8bcb4378 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Fri, 26 Jul 2024 16:10:21 +0200 Subject: [PATCH] fixes - imixs-ai upadte --- RELEASENOTES.md | 1 + docker-compose.yml | 8 +- .../ai/PromptExampleAdapterXML.java | 170 ++++++++++++ .../src/main/resources/imixs.properties | 2 +- .../main/webapp/pages/admin/agl_params.xhtml | 2 +- .../pages/admin/analyse_invoicing.xhtml | 5 +- .../webapp/pages/admin/cargosoft_export.xhtml | 37 +-- .../webapp/pages/admin/document_import.xhtml | 2 +- .../main/webapp/pages/admin/kreditor.xhtml | 4 +- .../webapp/pages/admin/oplist_export.xhtml | 33 +-- .../main/webapp/pages/admin/sepa_config.xhtml | 148 +++++----- .../webapp/pages/workitems/agl_archive.xhtml | 2 +- .../parts/alexander/currency_in.xhtml | 4 +- pom.xml | 2 +- reports/sepa/result_sepa01.xml | 4 +- reports/sepa/result_sepa02.xml | 4 +- workflow/posteingang-de-2.0.0.bpmn | 258 +----------------- workflow/prompts/invoice-extract-EN.xml | 2 +- workflow/rechnungseingang-de-1.2.39.bpmn | 31 ++- 19 files changed, 332 insertions(+), 387 deletions(-) create mode 100644 office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ai/PromptExampleAdapterXML.java diff --git a/RELEASENOTES.md b/RELEASENOTES.md index ac9bf6b..5494119 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -8,6 +8,7 @@ - Upgrade Imixs-Workflow 6.7 - Beim XML Invoice Import wird nun auch die Sprache für das Mahnwesen ermittelt (fehlte) - Währungsunabhängigkeit + - Lucen Index: item 'cdtr.name' wurde in den index aufgenommen wegen AI Examples Adapter **Migration** diff --git a/docker-compose.yml b/docker-compose.yml index 24876d8..e6213e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,10 +71,10 @@ services: ############################################### # Imixs-Admin ############################################### - #imixsadmin: - # image: imixs/imixs-admin - # ports: - # - "8888:8080" + imixsadmin: + image: imixs/imixs-admin + ports: + - "8888:8080" ############################################### # Mailgateway diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ai/PromptExampleAdapterXML.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ai/PromptExampleAdapterXML.java new file mode 100644 index 0000000..1f6830d --- /dev/null +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ai/PromptExampleAdapterXML.java @@ -0,0 +1,170 @@ +package com.alexanderlogistics.ai; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.imixs.ai.workflow.ImixsAIPromptEvent; +import org.imixs.workflow.ItemCollection; +import org.imixs.workflow.engine.DocumentService; +import org.imixs.workflow.exceptions.QueryException; + +import jakarta.enterprise.event.Observes; +import jakarta.inject.Inject; + +/** + * The PromptExampleAdapterXML is a CDI bean that creates XML examples based + * on the last 3 invoices. + * + * The adapter only runs if the prompt template contains + * + * <> + * + * Prompt example generated by this Adapter: + * + * Example: + * + *
+ * {@code
+ * 1. Company Data:
+ * - Name and address of the supplier
+ * - Supplier contact information (phone number, email, etc.)
+ * 
+ * 2. Invoice Data:
+ * - Invoice number
+ * - Invoice date
+ * - Order number
+ * - Customer number
+ * - Total invoice amount
+ *
+ * 
+ *   ...
+ *   ... 
+ *   2024-12-31
+ *   2024-12-31
+ *   1234.00
+ *   ...
+ *   ...
+ * 
+* }
+* 
+ * + */ +public class PromptExampleAdapterXML { + private static Logger logger = Logger.getLogger(PromptExampleAdapterXML.class.getName()); + + @Inject + DocumentService documentService; + + /** + * @param event + */ + public void onEvent(@Observes ImixsAIPromptEvent event) { + if (event.getWorkitem() == null) { + return; + } + + String prompt = event.getPromptTemplate(); + if (!prompt.contains("<>")) { + return; + } + + String exampleHeaderData = "\n\n### Example Invoice Data:\n\n"; + String exampleHeaderXML = "\n\n### Example XML Object:\n\n"; + String cdtrName = event.getWorkitem().getItemValueString("document.company"); + List invoices = findLastInvoices(cdtrName, event.getWorkitem().getUniqueID()); + String promptExamples = ""; + if (invoices != null && invoices.size() > 0) { + // Build an example for each invoice + for (ItemCollection invoice : invoices) { + promptExamples = promptExamples + buildExampleDE(invoice, exampleHeaderData, + exampleHeaderXML); + } + } + prompt = prompt.replace("<>", "" + promptExamples); + + // System.out.println(prompt); + event.setPromptTemplate(prompt); + } + + /** + * Helper Method that builds a prompt example out of an existing invoice: + * + *
+     * {@code
+     *
+     * 
+     *   ...
+     *   ... 
+     *   2024-12-31
+     *   2024-12-31
+     *   1234.00
+     *   ...
+     *   ...
+     * 
+    * }
+    * 
+ * + * @param invoice + * @return + */ + private String buildExampleDE(ItemCollection invoice, String dataExampleHeader, String xmlExampleHeader) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + StringBuffer example = new StringBuffer(); + + // add the invoice summary and the example code + if (invoice.hasItem("invoice.summary")) { + example.append(dataExampleHeader); + example.append(invoice.getItemValueString("invoice.summary")); + example.append(xmlExampleHeader); + // add JSON result object: + example.append("\n"); + example.append(" " + invoice.getItemValueString("cdtr.name") + "\n"); + example.append( + " " + invoice.getItemValueString("invoice.number") + "\n"); + if (invoice.getItemValueDate("invoice.date") != null) { + example.append( + " " + dateFormat.format(invoice.getItemValueDate("invoice.date")) + + "\n"); + } + if (invoice.getItemValueDate("payment.date") != null) { + example.append( + " " + dateFormat.format(invoice.getItemValueDate("payment.date")) + + "\n"); + } + example.append(" " + invoice.getItemValueDouble("invoice.total") + + "\n"); + example.append(" " + invoice.getItemValueString("cdtr.iban") + "\n"); + example.append(" " + invoice.getItemValueString("cdtr.bic") + "\n"); + example.append("\n"); + } + return example.toString(); + } + + /** + * Helper method to find the last 3 invoices by cdtr.name + * + * @param cdtrName + * @return + */ + private List findLastInvoices(String cdtrName, String currentID) { + List result = new ArrayList<>(); + + String searchTerm = "(type:workitemarchive) AND ($modelversion:rechnungseingang*) AND ($taskid:5900) AND NOT ($uniqueid:" + + currentID + ") AND (cdtr.name:\"" + + cdtrName + "\")"; + try { + result = documentService.find(searchTerm, 3, 0, "$modified", true); + } catch (QueryException e) { + logger.log(Level.SEVERE, "findLastInvoices - invalid query: {0}", e.getMessage()); + } + + logger.info("Found " + result.size() + " examples for '" + cdtrName + "'"); + return result; + + } + +} diff --git a/office-alexander-logistics-app/src/main/resources/imixs.properties b/office-alexander-logistics-app/src/main/resources/imixs.properties index 7b55f60..bcbf27e 100644 --- a/office-alexander-logistics-app/src/main/resources/imixs.properties +++ b/office-alexander-logistics-app/src/main/resources/imixs.properties @@ -4,7 +4,7 @@ lucence.indexDir=${imixs-office.IndexDir} index.fields=txtsearchstring,txtSubject,txtname,txtEmail,txtUserName,namCreator,txtworkflowgroup,txtworkflowstatus,txtWorkflowAbstract,txtWorkflowSummary,txtworkflowhistory,txtspacename,txtprocessname,_subject,_description,_name,_projectnumber,_projectname,_ordernumber,_contractnumber,datDueDate,txtcommentlog,htmldescription,htmldocumentation,dms,dms_names,invoice.number.stripped,_childitems,$file.names,_VENDOR_NAME,dbtr.number,cdtr.number,invoice.positions index.fields.analyze=txtUsername -index.fields.noanalyze=type,$UniqueIDRef,$created,$modified,$ModelVersion,$participants,namCreator,$ProcessID,datDate,txtWorkflowGroup,txtemail, datdate, datfrom, datto, numsequencenumber,sequencenumber,dms_count,invoice.number,invoice.number.stripped,invoice.date,invoice.duedate,taxonomy.verteilung.stop,taxonomy.sachpruefung.stop,taxonomy.verteilung.start,taxonomy.sachpruefung.start,taxonomy.buchhaltung.start,taxonomy.buchhaltung.stop,dbtr.number,cdtr.number,payment.date,invoice.total,invoice.currency,invoice.positions,$lasteventdate,payment.type +index.fields.noanalyze=type,$UniqueIDRef,$created,$modified,$ModelVersion,$participants,namCreator,$ProcessID,datDate,txtWorkflowGroup,txtemail, datdate, datfrom, datto, numsequencenumber,sequencenumber,dms_count,invoice.number,invoice.number.stripped,invoice.date,invoice.duedate,taxonomy.verteilung.stop,taxonomy.sachpruefung.stop,taxonomy.verteilung.start,taxonomy.sachpruefung.start,taxonomy.buchhaltung.start,taxonomy.buchhaltung.stop,dbtr.number,cdtr.number,payment.date,invoice.total,invoice.currency,invoice.positions,$lasteventdate,payment.type,cdtr.name index.fields.store=process.name,txtProcessName,txtWorkflowImageURL,payment.date,invoice.number,invoice.date,invoice.duedate index.fields.category=space.name,space.ref,taxonomy.verteilung.stop.by,taxonomy.sachpruefung.stop.by,taxonomy.buchhaltung.stop.by office.search.noanalyze=invoice.number,invoice.number.stripped,invoice.positions diff --git a/office-alexander-logistics-app/src/main/webapp/pages/admin/agl_params.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/admin/agl_params.xhtml index 611ab2a..3a97ca7 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/admin/agl_params.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/admin/agl_params.xhtml @@ -13,7 +13,7 @@ - +

Parameter

diff --git a/office-alexander-logistics-app/src/main/webapp/pages/admin/analyse_invoicing.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/admin/analyse_invoicing.xhtml index 3d65f45..0adfbc8 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/admin/analyse_invoicing.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/admin/analyse_invoicing.xhtml @@ -35,10 +35,7 @@ - - - - +
diff --git a/office-alexander-logistics-app/src/main/webapp/pages/admin/cargosoft_export.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/admin/cargosoft_export.xhtml index fa5a403..048a005 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/admin/cargosoft_export.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/admin/cargosoft_export.xhtml @@ -1,11 +1,7 @@ - + @@ -30,7 +26,7 @@

Ausgangsrechnungen

- +
@@ -42,7 +38,7 @@
@@ -50,7 +46,7 @@
- +
@@ -76,8 +72,7 @@ / - @@ -94,17 +89,17 @@ - +

- In diesem Verzeichniss werden die Belegdaten + In diesem Verzeichniss werden + die Belegdaten im DATEV Format abgelegt.

Scheduler

- +
@@ -113,8 +108,7 @@