|
10 | 10 | import org.eclipse.ui.IWorkbench;
|
11 | 11 | import org.eclipse.ui.IWorkbenchPreferencePage;
|
12 | 12 |
|
| 13 | +import com.developer.nefarious.zjoule.plugin.auth.SessionManager; |
13 | 14 | import com.developer.nefarious.zjoule.plugin.core.Activator;
|
| 15 | +import com.developer.nefarious.zjoule.plugin.memory.MemoryDeployment; |
| 16 | +import com.developer.nefarious.zjoule.plugin.memory.MemoryOllamaEndpoint; |
| 17 | +import com.developer.nefarious.zjoule.plugin.memory.MemoryOllamaModel; |
| 18 | +import com.developer.nefarious.zjoule.plugin.memory.MemoryResourceGroup; |
14 | 19 |
|
15 | 20 | public class PluginPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
|
16 | 21 |
|
| 22 | + private static final int SPACER_SIZE = 10; |
| 23 | + |
| 24 | + private static final int SPACER_WIDTH = 10; |
| 25 | + |
| 26 | + private static final int SPACER_HEIGHT = 10; |
| 27 | + |
17 | 28 | public PluginPreferencesPage() {
|
18 |
| - super(GRID); |
19 |
| - setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
20 |
| - } |
| 29 | + super(GRID); |
| 30 | + } |
21 | 31 |
|
22 | 32 | @Override
|
23 |
| - public void init(final IWorkbench workbench) { } |
| 33 | + public void init(final IWorkbench workbench) { |
| 34 | + setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
| 35 | + } |
24 | 36 |
|
25 | 37 | @Override
|
26 | 38 | protected void createFieldEditors() {
|
27 |
| - |
28 |
| - Group group = new Group(getFieldEditorParent(), SWT.NONE); |
29 |
| - group.setText("Chat Settings"); |
30 |
| - group.setLayout(new GridLayout(1, false)); |
31 |
| - group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
32 | 39 |
|
33 |
| - Composite groupContent = new Composite(group, SWT.NONE); |
34 |
| - groupContent.setLayout(new GridLayout(1, false)); |
35 |
| - groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 40 | + displayInstructionsInput(); |
| 41 | + |
| 42 | + createSpacer(); |
| 43 | + |
| 44 | + if (SessionManager.isSapSession()) { |
| 45 | + displaySapSettings(); |
| 46 | + } else if (SessionManager.isOllamaSession()) { |
| 47 | + displayOllamaSettings(); |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | + private void displayInstructionsInput() { |
| 53 | + Group group = new Group(getFieldEditorParent(), SWT.NONE); |
| 54 | + group.setText("Chat Settings"); |
| 55 | + group.setLayout(new GridLayout(1, false)); |
| 56 | + group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
| 57 | + |
| 58 | + Composite groupContent = new Composite(group, SWT.NONE); |
| 59 | + groupContent.setLayout(new GridLayout(1, false)); |
| 60 | + groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 61 | + |
| 62 | + addField(new InputField(Instruction.KEY, "Instructions:", groupContent)); |
| 63 | + } |
36 | 64 |
|
37 |
| - addField(new StringFieldEditor(Instruction.KEY, "Instructions:", groupContent)); |
| 65 | + private void createSpacer() { |
| 66 | + Composite spacer = new Composite(getFieldEditorParent(), SWT.NONE); |
| 67 | + GridData gridData = new GridData(SPACER_WIDTH,SPACER_HEIGHT); |
| 68 | + gridData.heightHint = SPACER_SIZE; |
| 69 | + spacer.setLayoutData(gridData); |
| 70 | + } |
| 71 | + |
| 72 | + private Composite createContentContainer(final String title) { |
| 73 | + Group group = new Group(getFieldEditorParent(), SWT.NONE); |
| 74 | + group.setText(title); |
| 75 | + group.setLayout(new GridLayout(1, false)); |
| 76 | + group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
| 77 | + |
| 78 | + Composite groupContent = new Composite(group, SWT.NONE); |
| 79 | + groupContent.setLayout(new GridLayout(1, false)); |
| 80 | + groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 81 | + return groupContent; |
| 82 | + } |
| 83 | + |
| 84 | + private void displaySapSettings() { |
| 85 | + Composite contentContainer = createContentContainer("SAP AI Core Configuration Parameters"); |
| 86 | + |
| 87 | + class OutputFieldFactory { |
| 88 | + StringFieldEditor create(final String key, final String value) { |
| 89 | + return new OutputField(key, value, contentContainer); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + OutputFieldFactory outputFieldFactory = new OutputFieldFactory(); |
| 94 | + |
| 95 | + String resourceGroup = MemoryResourceGroup.getInstance().load(); |
| 96 | + addField(outputFieldFactory.create("Resource Group:", resourceGroup)); |
| 97 | + |
| 98 | + String configurationName = MemoryDeployment.getInstance().load().getConfigurationName(); |
| 99 | + addField(outputFieldFactory.create("Configuration Name:", configurationName)); |
| 100 | + |
| 101 | + String model = MemoryDeployment.getInstance().load().getModelName(); |
| 102 | + addField(outputFieldFactory.create("Model:", model)); |
| 103 | + |
| 104 | + String deploymentUrl = MemoryDeployment.getInstance().load().getDeploymentUrl(); |
| 105 | + addField(outputFieldFactory.create("Deployment Url:", deploymentUrl)); |
| 106 | + } |
| 107 | + |
| 108 | + private void displayOllamaSettings() { |
| 109 | + Composite contentContainer = createContentContainer("Ollama Configuration Parameters"); |
| 110 | + |
| 111 | + class OutputFieldFactory { |
| 112 | + StringFieldEditor create(final String key, final String value) { |
| 113 | + return new OutputField(key, value, contentContainer); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + OutputFieldFactory outputFieldFactory = new OutputFieldFactory(); |
| 118 | + |
| 119 | + String endpoint = MemoryOllamaEndpoint.getInstance().load(); |
| 120 | + addField(outputFieldFactory.create("Endpoint:", endpoint)); |
| 121 | + |
| 122 | + String name = MemoryOllamaModel.getInstance().load().getName(); |
| 123 | + addField(outputFieldFactory.create("Name:", name)); |
| 124 | + |
| 125 | + String model = MemoryOllamaModel.getInstance().load().getModel(); |
| 126 | + addField(outputFieldFactory.create("Model:", model)); |
| 127 | + |
| 128 | + String format = MemoryOllamaModel.getInstance().load().getFormat(); |
| 129 | + addField(outputFieldFactory.create("Format:", format)); |
| 130 | + |
| 131 | + String family = MemoryOllamaModel.getInstance().load().getFamily(); |
| 132 | + addField(outputFieldFactory.create("Family:", family)); |
| 133 | + |
| 134 | + String parameterSize = MemoryOllamaModel.getInstance().load().getParameterSize(); |
| 135 | + addField(outputFieldFactory.create("Parameter Size:", parameterSize)); |
38 | 136 |
|
| 137 | + String quantizationLevel = MemoryOllamaModel.getInstance().load().getQuantizationLevel(); |
| 138 | + addField(outputFieldFactory.create("Quantization Level:", quantizationLevel)); |
39 | 139 | }
|
40 | 140 |
|
41 | 141 | }
|
0 commit comments