1
1
package com .developer .nefarious .zjoule .plugin .login .pages ;
2
2
3
+ import java .io .IOException ;
4
+ import java .util .List ;
5
+
3
6
import org .eclipse .jface .wizard .IWizardPage ;
4
7
import org .eclipse .jface .wizard .WizardPage ;
5
8
import org .eclipse .swt .SWT ;
9
12
import org .eclipse .swt .widgets .Label ;
10
13
import org .eclipse .swt .widgets .Text ;
11
14
15
+ import com .developer .nefarious .zjoule .plugin .login .api .GetOllamaModelsResponse ;
16
+ import com .developer .nefarious .zjoule .plugin .login .api .IOllamaLoginClient ;
17
+ import com .developer .nefarious .zjoule .plugin .login .utils .OllamaModelNamesExtractor ;
18
+
12
19
public class FirstOllamaLoginPage extends WizardPage {
13
20
14
21
public static final String PAGE_ID = "Ollama Login First Page" ;
15
22
23
+ private IOllamaLoginClient ollamaLoginClient ;
24
+
16
25
private Text endpointText ;
17
-
26
+
18
27
private Text errorText ;
19
28
20
- public FirstOllamaLoginPage () {
29
+ public FirstOllamaLoginPage (final IOllamaLoginClient ollamaLoginClient ) {
21
30
super (PAGE_ID );
22
31
23
32
setTitle ("Ollama Setup" );
24
33
setDescription ("Enter the host and port for the local Ollama instance." );
25
34
setPageComplete (false ); // Initially set the page as incomplete
35
+ this .ollamaLoginClient = ollamaLoginClient ;
26
36
}
27
37
28
38
@ Override
@@ -36,39 +46,53 @@ public void createControl(final Composite parent) {
36
46
endpointText = new Text (container , SWT .BORDER );
37
47
endpointText .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
38
48
endpointText .setText ("http://localhost:11434" );
39
-
49
+
40
50
// Hidden error text widget
41
- errorText = new Text (container , SWT .READ_ONLY | SWT .MULTI | SWT .WRAP );
42
- GridData errorTextGridData = new GridData (SWT .FILL , SWT .CENTER , true , false , 2 , 1 );
43
- errorText .setLayoutData (errorTextGridData );
44
- errorText .setForeground (container .getDisplay ().getSystemColor (SWT .COLOR_RED ));
45
- errorText .setVisible (false ); // Initially hidden
51
+ errorText = new Text (container , SWT .READ_ONLY | SWT .MULTI | SWT .WRAP );
52
+ GridData errorTextGridData = new GridData (SWT .FILL , SWT .CENTER , true , false , 2 , 1 );
53
+ errorText .setLayoutData (errorTextGridData );
54
+ errorText .setForeground (container .getDisplay ().getSystemColor (SWT .COLOR_RED ));
55
+ errorText .setVisible (false ); // Initially hidden
46
56
47
57
setControl (container );
48
58
}
49
-
59
+
50
60
@ Override
51
- public boolean canFlipToNextPage () {
52
- return true ;
53
- }
61
+ public boolean canFlipToNextPage () {
62
+ return true ;
63
+ }
54
64
55
65
@ Override
56
66
public IWizardPage getNextPage () {
57
-
58
- String input = endpointText .getText ();
59
-
60
- if (input == null || input .isEmpty () || input .isBlank ()) {
67
+
68
+ String ollamaEndpoint = endpointText .getText ();
69
+
70
+ if (ollamaEndpoint == null || ollamaEndpoint .isEmpty () || ollamaEndpoint .isBlank ()) {
61
71
displayErrorMessage ("Please, enter a local Ollama endpoint to proceed." );
62
72
return null ;
63
73
}
64
-
74
+
75
+ try {
76
+ setAvailableModelsFor (ollamaEndpoint );
77
+ } catch (IllegalArgumentException | IOException | InterruptedException e ) {
78
+ displayErrorMessage ("Local instance of Ollama invalid or doesn't exist in the informed address." );
79
+ return null ;
80
+ }
81
+
65
82
errorText .setVisible (false );
66
83
return super .getNextPage (); // Proceed to the next page
67
84
}
68
-
85
+
86
+ private void setAvailableModelsFor (final String ollamaEndpoint ) throws IOException , InterruptedException {
87
+ GetOllamaModelsResponse response = ollamaLoginClient .getModels (ollamaEndpoint );
88
+ SecondOllamaLoginPage secondPage = (SecondOllamaLoginPage ) getWizard ().getPage (SecondOllamaLoginPage .PAGE_ID );
89
+ List <String > modelsAvailableForSelection = OllamaModelNamesExtractor .extractModelNames (response );
90
+ secondPage .setModelsForSelection (modelsAvailableForSelection );
91
+ }
92
+
69
93
private void displayErrorMessage (final String message ) {
70
94
errorText .setText (message );
71
- errorText .setVisible (true );
95
+ errorText .setVisible (true );
72
96
}
73
97
74
98
}
0 commit comments