Skip to content

Commit

Permalink
[Bug]: Improve the settings UI for the Language Chat Transform Plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Everitt committed Dec 10, 2024
1 parent 18df953 commit 00a3249
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@

import static org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui.CompositeParameters.Builder.buildCompositeParameters;
import static org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui.i18nUtil.i18n;
import static org.apache.hop.ui.core.PropsUi.getFormMargin;
import static org.apache.hop.ui.core.PropsUi.getMargin;
import static org.apache.hop.ui.core.PropsUi.setLook;
import static org.apache.hop.ui.core.dialog.BaseDialog.defaultShellHandling;
import static org.eclipse.swt.SWT.BORDER;
import static org.eclipse.swt.SWT.DIALOG_TRIM;
import static org.eclipse.swt.SWT.MAX;
import static org.eclipse.swt.SWT.MIN;
import static org.eclipse.swt.SWT.NONE;
import static org.eclipse.swt.SWT.RESIZE;

import java.util.Collection;
import java.util.List;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
import org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui.CancelButton;
import org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui.CompositeParameters.Builder;
Expand Down Expand Up @@ -63,30 +61,35 @@ public class LanguageModelChatDialog extends BaseTransformDialog
private Collection<IDialogComposite> composites;

public LanguageModelChatDialog(
Shell parent, IVariables variables, Object in, PipelineMeta pipelineMeta, String sname) {
super(parent, variables, (BaseTransformMeta) in, pipelineMeta, sname);
input = (LanguageModelChatMeta) in;
Shell parent,
IVariables variables,
LanguageModelChatMeta transformMeta,
PipelineMeta pipelineMeta) {
super(parent, variables, transformMeta, pipelineMeta);
input = transformMeta;
}

@Override
public String open() {
Shell parent = getParent();
shell = new Shell(parent, DIALOG_TRIM | RESIZE | MAX | MIN);

shell = new Shell(parent, DIALOG_TRIM | RESIZE | MIN | MAX);
setLook(shell);
setShellImage(shell, input);

changed = input.hasChanged();

int margin = getMargin();

FormLayout formLayout = new FormLayout();
formLayout.marginWidth = getFormMargin();
formLayout.marginHeight = getFormMargin();
formLayout.marginWidth = margin;
formLayout.marginHeight = margin;

shell.setLayout(formLayout);
shell.setText(i18n("LanguageModelChatDialog.Shell.Title"));

int margin = getMargin();

// Model Specific Composite
Composite modelComposite = new Composite(shell, NONE);
Composite modelComposite = new Composite(shell, BORDER);

PopulateInputsAdapter modelCompositeInputsAdapter =
new PopulateInputsAdapter() {
Expand All @@ -112,7 +115,7 @@ public void populateInputs() {
// Transform Name Row
IDialogComposite tnc = new TransformNameComposite(params.build());

IDialogComposite gsc = new GeneralSettingsComposite(params.control(tnc.control()).build());
IDialogComposite gsc = new GeneralSettingsComposite(params.control(shell).build());

// Model Specific Composite
modelComposite.setLayout(new FormLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
package org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui;

import static org.apache.hop.pipeline.transforms.languagemodelchat.internals.ui.i18nUtil.i18n;
import static org.apache.hop.ui.core.ConstUi.LARGE_ICON_SIZE;
import static org.apache.hop.ui.core.PropsUi.setLook;
import static org.apache.hop.ui.util.SwtSvgImageUtil.getImage;
import static org.eclipse.swt.SWT.BORDER;
import static org.eclipse.swt.SWT.CENTER;
import static org.eclipse.swt.SWT.HORIZONTAL;
import static org.eclipse.swt.SWT.LEFT;
import static org.eclipse.swt.SWT.RIGHT;
import static org.eclipse.swt.SWT.SEPARATOR;
import static org.eclipse.swt.SWT.SINGLE;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -55,14 +60,37 @@ public TransformNameComposite(CompositeParameters parameters) {

inputField.addModifyListener(e -> meta.setChanged());

// Image
var image =
getImage(
parameters.shell().getDisplay(),
getClass().getClassLoader(),
"languagemodelchat.svg",
LARGE_ICON_SIZE,
LARGE_ICON_SIZE);
Label wIcon = new Label(parameters.shell(), RIGHT);
wIcon.setImage(image);
FormData fdlIcon = new FormData();
fdlIcon.top = new FormAttachment(0, 0);
fdlIcon.right = new FormAttachment(100, 0);
wIcon.setLayoutData(fdlIcon);
setLook(wIcon);

FormData fdlTransformName = new FormData();
fdlTransformName.left = new FormAttachment(0, 0);
fdlTransformName.right = new FormAttachment(parameters.middlePct(), -parameters.margin());
fdlTransformName.top = new FormAttachment(0, parameters.margin());
fdlTransformName.bottom = new FormAttachment(wIcon, 0, CENTER);
FormData fdTransformName = new FormData();
fdTransformName.left = new FormAttachment(parameters.middlePct(), 0);
fdTransformName.top = new FormAttachment(0, parameters.margin());
fdTransformName.right = new FormAttachment(100, 0);
fdTransformName.left = new FormAttachment(label, parameters.margin());
fdTransformName.top = new FormAttachment(label, 0, CENTER);
fdTransformName.right = new FormAttachment(wIcon, 0);

// Draw line separator
Label separator = new Label(parameters.shell(), HORIZONTAL | SEPARATOR);
FormData fdSeparator = new FormData();
fdSeparator.left = new FormAttachment(0, 0);
fdSeparator.top = new FormAttachment(wIcon, 0);
fdSeparator.right = new FormAttachment(100, 0);
separator.setLayoutData(fdSeparator);

label.setLayoutData(fdlTransformName);
inputField.setLayoutData(fdTransformName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected AbstractModelComposite(ModelType modelType, CompositeParameters parame
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
composite.setLayoutData(fd);
setLook(composite);

control = composite;
layout = buildFormData().margin(parameters.margin());
Expand Down Expand Up @@ -108,7 +109,6 @@ protected void prepare(String i18n, Label label, Control input) {
isTrue(input instanceof Button, "Only buttons don't need a label");
((Button) input).setText(i18nKey);
} else {
setLook(label);
label.setText(i18nKey);
label.setLayoutData(layout.left(0, 0).right(middle, -margin).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public class AnthropicComposite extends AbstractModelComposite {
private final TextVar topKInput;
private final Label maxTokensLabel;
private final TextVar maxTokensInput;
private final Label stopSequencesLabel;
private final TextVar stopSequencesInput;
private final Label seedLabel;
private final TextVar seedInput;
// TODO private final Label stopSequencesLabel;
// TODO private final TextVar stopSequencesInput;
// TODO private final Label seedLabel;
// TODO private final TextVar seedInput;
private final Label timeoutLabel;
private final TextVar timeoutInput;
private final Label maxRetriesLabel;
Expand Down Expand Up @@ -99,16 +99,20 @@ public AnthropicComposite(CompositeParameters parameters) {
prepare("MaxTokens", maxTokensLabel, maxTokensInput);

// Stop Sequences
/*
TODO Implement anthropic Stop sequences
stopSequencesLabel = createLabel();
stopSequencesInput = createTextVar();
stopSequencesLabel.setVisible(false);
stopSequencesInput.setVisible(false);
// TODO prepare("StopSequences", stopSequencesLabel, stopSequencesInput);
prepare("StopSequences", stopSequencesLabel, stopSequencesInput);
*/

// Seed
/*
TODO Implement anthropic seed
seedLabel = createLabel();
seedInput = createTextVar();
// TODO prepare("Seed", seedLabel, seedInput);
prepare("Seed", seedLabel, seedInput);
*/

// Timeout
timeoutLabel = createLabel();
Expand Down Expand Up @@ -271,14 +275,6 @@ public TextVar getMaxTokensInput() {
return maxTokensInput;
}

public Label getSeedLabel() {
return seedLabel;
}

public TextVar getSeedInput() {
return seedInput;
}

public Label getTopKLabel() {
return topKLabel;
}
Expand All @@ -303,6 +299,8 @@ public TextVar getMaxRetriesInput() {
return maxRetriesInput;
}

/*
TODO Implement Anthropic stop sequences and seed
public Label getStopSequencesLabel() {
return stopSequencesLabel;
}
Expand All @@ -311,6 +309,15 @@ public TextVar getStopSequencesInput() {
return stopSequencesInput;
}
public Label getSeedLabel() {
return seedLabel;
}
public TextVar getSeedInput() {
return seedInput;
}
*/

public Button getLogRequestsButton() {
return logRequestsButton;
}
Expand Down

0 comments on commit 00a3249

Please sign in to comment.