Skip to content

Commit

Permalink
DeepL API token provided by client, not stored in Ingo backend. issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Sep 16, 2024
1 parent 2448fc6 commit db734fb
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ You should also get your employer (if you work as a programmer) or school,
import com.jdimension.jlawyer.services.JLawyerServiceLocator;
import com.jdimension.jlawyer.ai.AiCapability;
import com.jdimension.jlawyer.ai.AiRequestStatus;
import com.jdimension.jlawyer.ai.ConfigurationData;
import com.jdimension.jlawyer.ai.Input;
import com.jdimension.jlawyer.ai.ParameterData;
import com.jdimension.jlawyer.ai.Prompt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,10 @@ protected Void doInBackground() throws Exception {

} catch (Throwable t) {
log.error("Error processing AI request", t);
AiRequestStatus status = new AiRequestStatus();
status.setStatus("ERROR");
status.setStatusDetails(t.getMessage());
resultRef.set(status);
}
cmdExecutePrompt.setEnabled(true);
cmdInterrupt.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,10 @@ protected Void doInBackground() throws Exception {

} catch (Throwable t) {
log.error("Error processing AI request", t);
AiRequestStatus status=new AiRequestStatus();
status.setStatus("ERROR");
status.setStatusDetails(t.getMessage());
resultRef.set(status);
}
cmdSubmit.setEnabled(true);
cmdInterrupt.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="cmdClose" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" pref="44" max="-2" attributes="0"/>
<Component id="jLabel11" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtUrl" max="32767" attributes="0"/>
<Component id="txtName" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel9" min="-2" max="-2" attributes="0"/>
<Component id="jLabel10" min="-2" pref="51" max="-2" attributes="0"/>
<Component id="jLabel10" alignment="0" min="-2" pref="51" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
Expand All @@ -62,10 +60,14 @@
<Component id="jLabel12" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="242" max="32767" attributes="0"/>
<EmptySpace min="0" pref="200" max="32767" attributes="0"/>
</Group>
<Component id="txtConfigurations" alignment="0" max="32767" attributes="0"/>
<Component id="txtName" alignment="1" max="32767" attributes="0"/>
<Component id="txtUrl" alignment="0" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -124,7 +126,12 @@
<Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel13" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtConfigurations" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/>
<Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -383,5 +390,12 @@
<Property name="text" type="java.lang.String" value="Sekunden"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtConfigurations">
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Konfigurationen:"/>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ private void resetDetails() {
this.txtUrl.setText("");
this.txtPwd.setText("");
this.txtUser.setText("");
this.txtConfigurations.setText("");
this.spnConnectTimeout.setValue(3);
this.spnReadTimeout.setValue(5);

Expand Down Expand Up @@ -769,6 +770,8 @@ private void initComponents() {
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
txtConfigurations = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Assistent Ingo");
Expand Down Expand Up @@ -894,6 +897,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

jLabel13.setText("Sekunden");

jLabel2.setText("Konfigurationen:");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -906,17 +911,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(cmdClose))
.addComponent(jSeparator1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtUrl)
.addComponent(txtName)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel11)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
Expand All @@ -930,7 +933,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(spnConnectTimeout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel12)))
.addGap(0, 242, Short.MAX_VALUE))))
.addGap(0, 200, Short.MAX_VALUE))
.addComponent(txtConfigurations, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtName)
.addComponent(txtUrl, javax.swing.GroupLayout.Alignment.LEADING)))
.addComponent(jSeparator1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
Expand Down Expand Up @@ -976,7 +983,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(spnReadTimeout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtConfigurations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(62, 62, 62)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
Expand All @@ -995,8 +1006,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addContainerGap())
);

getAccessibleContext().setAccessibleName("Assistent Ingo");

pack();
}// </editor-fold>//GEN-END:initComponents

Expand Down Expand Up @@ -1038,6 +1047,7 @@ private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
ac.setReadTimeout(5);
ac.setUserName(null);
ac.setPassword(null);
ac.setConfiguration("");

AssistantConfig savedAssistant = locator.lookupIntegrationServiceRemote().addAssistantConfig(ac);

Expand All @@ -1060,9 +1070,10 @@ private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
AssistantConfig ac = (AssistantConfig) this.tblAssistants.getValueAt(row, 0);
ac.setName(this.txtName.getText());
ac.setUserName(this.txtUser.getText());
ac.setConnectionTimeout(((Number) this.spnConnectTimeout.getValue()).longValue());
ac.setReadTimeout(((Number) this.spnReadTimeout.getValue()).longValue());
ac.setConnectionTimeout(((Number) this.spnConnectTimeout.getValue()).intValue());
ac.setReadTimeout(((Number) this.spnReadTimeout.getValue()).intValue());
ac.setUrl(this.txtUrl.getText());
ac.setConfiguration(this.txtConfigurations.getText());
try {
if (this.txtPwd.getPassword().length > 0) {
ac.setPassword(CryptoProvider.defaultCrypto().encrypt(new String(this.txtPwd.getPassword())));
Expand Down Expand Up @@ -1146,6 +1157,7 @@ private void updatedUI(AssistantConfig ac) {
this.txtUser.setText(ac.getUserName());
this.spnConnectTimeout.setValue(ac.getConnectionTimeout());
this.spnReadTimeout.setValue(ac.getReadTimeout());
this.txtConfigurations.setText(ac.getConfiguration());

}

Expand Down Expand Up @@ -1203,6 +1215,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
Expand All @@ -1215,6 +1228,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
private javax.swing.JSpinner spnConnectTimeout;
private javax.swing.JSpinner spnReadTimeout;
private javax.swing.JTable tblAssistants;
private javax.swing.JTextField txtConfigurations;
private javax.swing.JTextField txtName;
private javax.swing.JPasswordField txtPwd;
private javax.swing.JTextField txtUrl;
Expand Down
16 changes: 16 additions & 0 deletions j-lawyer-fax/src/com/jdimension/jlawyer/ai/AiCapability.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class AiCapability implements Serializable {

private Prompt defaultPrompt=null;

private List<Configuration> configurations=new ArrayList<>();

private List<Parameter> parameters=new ArrayList<>();

private List<Input> input=new ArrayList<>();
Expand Down Expand Up @@ -216,6 +218,20 @@ public boolean isCustomPrompts() {
public void setCustomPrompts(boolean customPrompts) {
this.customPrompts = customPrompts;
}

/**
* @return the configurations
*/
public List<Configuration> getConfigurations() {
return configurations;
}

/**
* @param configurations the configurations to set
*/
public void setConfigurations(List<Configuration> configurations) {
this.configurations = configurations;
}


}
43 changes: 35 additions & 8 deletions j-lawyer-fax/src/com/jdimension/jlawyer/ai/AssistantAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ private String getAuthString() {
return encoder.encode(authString.getBytes());
}

public AiRequestStatus submitRequest(String requestType, String modelType, String prompt, List<ParameterData> params, List<InputData> inputs) throws AssistantException {
public AiRequestStatus submitRequest(String requestType, String modelType, String prompt, List<ConfigurationData> configurations, List<ParameterData> params, List<InputData> inputs) throws AssistantException {
log.info("submitting j-lawyer.AI request");


Expand Down Expand Up @@ -768,15 +768,30 @@ public AiRequestStatus submitRequest(String requestType, String modelType, Strin

jsonQuery.append("],");
}
if (params != null && !params.isEmpty()) {
jsonQuery.append("\"parameterData\": [");

for (int i = 0; i < params.size(); i++) {
// if (params != null && !params.isEmpty()) {
// jsonQuery.append("\"parameterData\": [");
//
// for (int i = 0; i < params.size(); i++) {
// jsonQuery.append("{");
// jsonQuery.append("\"id\": \"").append(Jsoner.escape(params.get(i).getId())).append("\",");
// jsonQuery.append("\"value\": \"").append(Jsoner.escape(params.get(i).getValue())).append("\"");
// jsonQuery.append("}");
// if (i < params.size() - 1) {
// jsonQuery.append(",");
// }
// }
//
// jsonQuery.append("],");
// }
if (configurations != null && !configurations.isEmpty()) {
jsonQuery.append("\"configurationData\": [");

for (int i = 0; i < configurations.size(); i++) {
jsonQuery.append("{");
jsonQuery.append("\"id\": \"").append(Jsoner.escape(params.get(i).getId())).append("\",");
jsonQuery.append("\"value\": \"").append(Jsoner.escape(params.get(i).getValue())).append("\"");
jsonQuery.append("\"id\": \"").append(Jsoner.escape(configurations.get(i).getId())).append("\",");
jsonQuery.append("\"value\": \"").append(Jsoner.escape(configurations.get(i).getValue())).append("\"");
jsonQuery.append("}");
if (i < params.size() - 1) {
if (i < configurations.size() - 1) {
jsonQuery.append(",");
}
}
Expand Down Expand Up @@ -988,6 +1003,18 @@ public List<AiCapability> getCapabilities() throws AssistantException {
capability.getParameters().add(parameter);
}
}

Object configurations = c.getCollection(Jsoner.mintJsonKey("configurations", null));
if (configurations != null && configurations instanceof JsonArray) {
JsonArray configurationsArray = (JsonArray) configurations;
for (Object oObj : configurationsArray) {
JsonObject o = (JsonObject) oObj;
Configuration config = new Configuration();
config.setId(o.getString(Jsoner.mintJsonKey("id", null)));
config.setDescription(o.getString(Jsoner.mintJsonKey("description", null)));
capability.getConfigurations().add(config);
}
}

stringKey = Jsoner.mintJsonKey("requestType", null);
capability.setRequestType(c.getString(stringKey));
Expand Down
48 changes: 48 additions & 0 deletions j-lawyer-fax/src/com/jdimension/jlawyer/ai/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.jdimension.jlawyer.ai;

import java.io.Serializable;

public class Configuration implements Serializable {

protected static long serialVersionUID = 1L;

private String id;
private String description;

/**
* @return the id
*/
public String getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the description
*/
public String getDescription() {
return description;
}

/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}





}
Loading

0 comments on commit db734fb

Please sign in to comment.