Skip to content

Commit

Permalink
added assistant to documents context menu, e.g. to trigger a summariz…
Browse files Browse the repository at this point in the history
…ation for a document. issue #2395
  • Loading branch information
j-dimension committed Aug 7, 2024
1 parent 98f0a67 commit 2f4e7fe
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
Binary file modified j-lawyer-client/lib/j-lawyer-cloud/j-lawyer-cloud.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ You should also get your employer (if you work as a programmer) or school,
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -817,5 +818,23 @@ public void populateMenu(JPopupMenu menu, Map<AssistantConfig, List<AiCapability
}

}

public void populateMenu(JMenu menu, Map<AssistantConfig, List<AiCapability>> capabilities, AssistantInputAdapter adapter) {

for (AssistantConfig config : capabilities.keySet()) {
for (AiCapability c : capabilities.get(config)) {
JMenuItem mi = new JMenuItem();
mi.setText(c.getName());
mi.setToolTipText(c.getDescription() + " (" + config.getName() + ")");
mi.addActionListener((ActionEvent e) -> {
GenericAssistantDialog dlg = new GenericAssistantDialog(config, c, adapter, !c.hasParameters(), EditorsRegistry.getInstance().getMainWindow(), false);
FrameUtils.centerDialogOnParentMonitor(dlg, EditorsRegistry.getInstance().getMainWindow().getLocation());
dlg.setVisible(true);
});
menu.add(mi);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator4">
</Component>
<Menu class="javax.swing.JMenu" name="mnuAssistant">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons16/material/j-lawyer-ai.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Assistent Ingo"/>
</Properties>
</Menu>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator10">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="mnuSendEpostLetter">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,10 @@
*/
package com.jdimension.jlawyer.client.editors.files;

import com.jdimension.jlawyer.ai.AiCapability;
import com.jdimension.jlawyer.ai.InputData;
import com.jdimension.jlawyer.client.assistant.AssistantAccess;
import com.jdimension.jlawyer.client.assistant.AssistantInputAdapter;
import com.jdimension.jlawyer.comparator.ReviewsComparator;
import com.jdimension.jlawyer.client.bea.BeaAccess;
import com.jdimension.jlawyer.client.bea.BeaInboxPanel;
Expand Down Expand Up @@ -803,7 +807,7 @@
*
* @author jens
*/
public class ArchiveFilePanel extends javax.swing.JPanel implements ThemeableEditor, PopulateOptionsEditor, SaveableEditor, SelfValidatingEditor, com.jdimension.jlawyer.client.events.EventConsumer, NewEventPanelListener, NewMessageConsumer, DocumentPreviewSaveCallback {
public class ArchiveFilePanel extends javax.swing.JPanel implements ThemeableEditor, PopulateOptionsEditor, SaveableEditor, SelfValidatingEditor, com.jdimension.jlawyer.client.events.EventConsumer, NewEventPanelListener, NewMessageConsumer, DocumentPreviewSaveCallback, AssistantInputAdapter {

private static final Logger log = Logger.getLogger(ArchiveFilePanel.class.getName());

Expand Down Expand Up @@ -1043,6 +1047,15 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
TableRowSorter htrs = new TableRowSorter(this.tblAccountEntries.getModel());
htrs.setComparator(0, dtComparator);
this.tblAccountEntries.setRowSorter(htrs);

AssistantAccess ingo = AssistantAccess.getInstance();
try {
Map<AssistantConfig, List<AiCapability>> capabilities2 = ingo.filterCapabilities(AiCapability.REQUESTTYPE_SUMMARIZE, AiCapability.INPUTTYPE_STRING);
ingo.populateMenu(this.mnuAssistant, capabilities2, (AssistantInputAdapter)this);
} catch (Exception ex) {
log.error(ex);
JOptionPane.showMessageDialog(this, "" + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE);
}

EventBroker b = EventBroker.getInstance();
b.subscribeConsumer(this, Event.TYPE_DOCUMENTADDED);
Expand Down Expand Up @@ -1765,6 +1778,8 @@ private void initComponents() {
mnuSendDocumentFax = new javax.swing.JMenuItem();
mnuDirectPrint = new javax.swing.JMenuItem();
jSeparator4 = new javax.swing.JPopupMenu.Separator();
mnuAssistant = new javax.swing.JMenu();
jSeparator10 = new javax.swing.JPopupMenu.Separator();
mnuSendEpostLetter = new javax.swing.JMenuItem();
jSeparator9 = new javax.swing.JPopupMenu.Separator();
mnuDrebis = new javax.swing.JMenu();
Expand Down Expand Up @@ -2252,6 +2267,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
documentsPopup.add(mnuDirectPrint);
documentsPopup.add(jSeparator4);

mnuAssistant.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/j-lawyer-ai.png"))); // NOI18N
mnuAssistant.setText("Assistent Ingo");
documentsPopup.add(mnuAssistant);
documentsPopup.add(jSeparator10);

mnuSendEpostLetter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jdimension/jlawyer/client/voip/DP_Logo_SZ_MF_rgb.png"))); // NOI18N
mnuSendEpostLetter.setText("per E-POST versenden");
mnuSendEpostLetter.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -7329,6 +7349,43 @@ public void savePreview(String documentId, String fileName, byte[] data) {
}
}

@Override
public List<InputData> getInputs(AiCapability c) {
ArrayList<InputData> inputs = new ArrayList<>();
try {
ClientSettings settings = ClientSettings.getInstance();
JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties());
ArchiveFileServiceRemote remote = locator.lookupArchiveFileServiceRemote();

ArrayList<ArchiveFileDocumentsBean> selected = this.caseFolderPanel1.getSelectedDocuments();

if (selected.isEmpty()) {
return inputs;
}
if(selected.size()!=1) {
return inputs;
}

ArchiveFileDocumentsBean doc = selected.get(0);
String docText=remote.getDocumentPreview(doc.getId());


InputData i = new InputData();
//i.setFileName("sound.wav");
i.setType("string");
i.setBase64(false);
//i.setData(selectedText);
i.setStringData(docText);
inputs.add(i);
return inputs;

} catch (Exception ioe) {
log.error("Error getting document as text", ioe);
JOptionPane.showMessageDialog(this, "Fehler bei der Textextraktion: " + ioe.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE);
return null;
}
}

protected class DropTargetHandler implements DropTargetListener {

private JPanel p = null;
Expand Down Expand Up @@ -7526,6 +7583,7 @@ public void drop(DropTargetDropEvent dtde) {
private javax.swing.JScrollPane jScrollPane8;
private javax.swing.JScrollPane jScrollPane9;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator10;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JPopupMenu.Separator jSeparator3;
private javax.swing.JPopupMenu.Separator jSeparator4;
Expand Down Expand Up @@ -7553,6 +7611,7 @@ public void drop(DropTargetDropEvent dtde) {
protected javax.swing.JLabel lblPanelTitle;
private javax.swing.JLabel lblSpendings;
private com.jdimension.jlawyer.client.messenger.MessageSendPanel messageSendPanel1;
private javax.swing.JMenu mnuAssistant;
private javax.swing.JMenuItem mnuCopyDocumentToOtherCase;
private javax.swing.JMenuItem mnuCopyExtIdToClipboard;
private javax.swing.JMenuItem mnuCopyFilesToClipboard;
Expand Down
Binary file modified j-lawyer-server/j-lawyer-server-ejb/lib/j-lawyer-cloud.jar
Binary file not shown.

0 comments on commit 2f4e7fe

Please sign in to comment.