Skip to content

Commit

Permalink
output of ingo is processed to a new note, when initiated from the do…
Browse files Browse the repository at this point in the history
…cument context menu in a case. close #2679
  • Loading branch information
j-dimension committed Nov 26, 2024
1 parent ddf9669 commit 1226305
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ You should also get your employer (if you work as a programmer) or school,
import com.jdimension.jlawyer.ai.ParameterData;
import com.jdimension.jlawyer.client.editors.files.ArchiveFilePanel;
import com.jdimension.jlawyer.client.settings.ClientSettings;
import com.jdimension.jlawyer.client.settings.UserSettings;
import com.jdimension.jlawyer.client.utils.ComponentUtils;
import com.jdimension.jlawyer.client.utils.FrameUtils;
import com.jdimension.jlawyer.client.utils.TemplatesUtil;
Expand Down Expand Up @@ -1288,7 +1289,28 @@ private void cmdCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
private void cmdProcessOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdProcessOutputActionPerformed
if (this.inputAdapter instanceof AssistantFlowAdapter && this.result != null) {
// caller is capable of handling results
//((AssistantFlowAdapter) this.inputAdapter).processOutput(capability, this.result);

if(result.getResponse()!=null && result.getResponse().getOutputData()!=null) {
OutputData intro=new OutputData();
intro.setType(OutputData.TYPE_STRING);
intro.setStringData("Chat-Verlauf: " + System.lineSeparator()+System.lineSeparator());
result.getResponse().getOutputData().add(intro);
for(Message msg: this.messages) {
OutputData od=new OutputData();
od.setType(OutputData.TYPE_STRING);
String role=msg.getRole();
if("user".equalsIgnoreCase(role))
role=UserSettings.getInstance().getCurrentUser().getPrincipalId();
else
role="Assistent Ingo";
od.setStringData(role + ": " + msg.getContent() + System.lineSeparator()+System.lineSeparator());
result.getResponse().getOutputData().add(od);
}
}

((AssistantFlowAdapter) this.inputAdapter).processOutput(capability, this.result);

}
this.setVisible(false);
this.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@
import com.jdimension.jlawyer.client.mail.EmailUtils;
import com.jdimension.jlawyer.client.utils.AudioUtils;
import com.jdimension.jlawyer.client.utils.ThreadUtils;
import com.jdimension.jlawyer.email.CommonMailUtils;
import com.jdimension.jlawyer.services.IntegrationServiceRemote;
import javax.sound.sampled.*;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -836,6 +837,13 @@ public void setFocusToBody() {
this.htmlEditorPanel1.requestFocus();
}

public void appendToBody(String appendText, boolean convertToHtml) {
if(convertToHtml) {
appendText=CommonMailUtils.text2Html(appendText);
}
this.htmlEditorPanel1.setText(this.htmlEditorPanel1.getText() + appendText);
}


public List<InputData> getTranscribeInputs(byte[] wavContent) {
ArrayList<InputData> inputs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,13 @@

import com.iradraconis.shrinkify.ShrinkifyGui;
import com.jdimension.jlawyer.ai.AiCapability;
import com.jdimension.jlawyer.ai.AiRequestStatus;
import com.jdimension.jlawyer.ai.InputData;
import com.jdimension.jlawyer.ai.Message;
import com.jdimension.jlawyer.ai.OutputData;
import com.jdimension.jlawyer.ai.ParameterData;
import com.jdimension.jlawyer.client.assistant.AssistantAccess;
import com.jdimension.jlawyer.client.assistant.AssistantFlowAdapter;
import com.jdimension.jlawyer.client.assistant.AssistantGenerateDialog;
import com.jdimension.jlawyer.client.assistant.AssistantInputAdapter;
import com.jdimension.jlawyer.comparator.ReviewsComparator;
Expand Down Expand Up @@ -815,7 +819,7 @@
*
* @author jens
*/
public class ArchiveFilePanel extends javax.swing.JPanel implements ThemeableEditor, PopulateOptionsEditor, SaveableEditor, SelfValidatingEditor, com.jdimension.jlawyer.client.events.EventConsumer, NewEventPanelListener, NewMessageConsumer, DocumentPreviewSaveCallback, AssistantInputAdapter {
public class ArchiveFilePanel extends javax.swing.JPanel implements ThemeableEditor, PopulateOptionsEditor, SaveableEditor, SelfValidatingEditor, com.jdimension.jlawyer.client.events.EventConsumer, NewEventPanelListener, NewMessageConsumer, DocumentPreviewSaveCallback, AssistantFlowAdapter {

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

Expand Down Expand Up @@ -7748,6 +7752,47 @@ public List<Message> getMessages(AiCapability c) {
return null;
}

@Override
public String getPrompt(AiCapability c) {
return null;
}

@Override
public List<ParameterData> getParameters(AiCapability c) {
return new ArrayList<>();
}

@Override
public void processOutput(AiCapability c, AiRequestStatus status) {
String resultText = "";
if (status != null) {
if (status.getStatus().equalsIgnoreCase("error")) {
// ignore output
} else {
StringBuilder result = new StringBuilder();
for (OutputData o : status.getResponse().getOutputData()) {
if (o.getType().equalsIgnoreCase(OutputData.TYPE_STRING)) {
result.append(o.getStringData()).append(System.lineSeparator()).append(System.lineSeparator());
}

}
resultText = result.toString();
}
}

AddNoteDialog dlg = new AddNoteDialog(EditorsRegistry.getInstance().getMainWindow(), true, this.caseFolderPanel1, this.dto);
dlg.setTitle("Notiz hinzufügen");
dlg.appendToBody(System.lineSeparator() + "Assistent Ingo - Ergebnis (" + c.getName() + ")" + System.lineSeparator()+ System.lineSeparator() +resultText, true);
FrameUtils.centerDialog(dlg, EditorsRegistry.getInstance().getMainWindow());
dlg.setVisible(true);

}

@Override
public void processError(AiCapability c, AiRequestStatus status) {
System.out.println("test");
}

protected class DropTargetHandler implements DropTargetListener {

private JPanel p = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,23 @@ public static Part getAttachmentPart(String name, Object partObject) throws Exce
return null;
}

public static String text2Html(String text) {
if (text == null) {
return null;
}
// Escape HTML and add line breaks
return escapeHtml(text).replace("\n", "<br>");
}

private static String escapeHtml(String text) {
return text
.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&#39;");
}

public static String html2Text(String html) {
try {
if (html == null) {
Expand Down

0 comments on commit 1226305

Please sign in to comment.