1
1
using UnityEditor ;
2
2
using UnityEngine ;
3
3
using System . Linq ;
4
- using System . Diagnostics ;
5
- using Debug = UnityEngine . Debug ;
6
- using System . Text . RegularExpressions ;
4
+ using Debug = UnityEngine . Debug ;
7
5
8
- public class OllamaSupportWindow : EditorWindow
6
+ namespace Neocortex
9
7
{
10
- private OllamaSupport ollama ;
11
- private Texture2D logo ;
12
-
13
- private int selectedModelIndex ;
14
-
15
- private bool isDownloading ;
16
-
17
- [ MenuItem ( "Tools/Neocortex/Ollama Support" ) ]
18
- public static void ShowWindow ( )
8
+ public class OllamaSupportWindow : EditorWindow
19
9
{
20
- var window = GetWindow < OllamaSupportWindow > ( false , "Neocortex Ollama Support" , true ) ;
21
- window . minSize = new Vector2 ( 512 , 352 ) ;
22
- window . maxSize = new Vector2 ( 512 , 352 ) ;
23
- }
10
+ private OllamaSupport ollama ;
11
+ private Texture2D logo ;
24
12
25
- private void OnEnable ( )
26
- {
27
- ollama = new OllamaSupport ( ) ;
28
- logo = Resources . Load < Texture2D > ( "Visuals/ollama_x_neocortex" ) ;
29
- ollama . CheckOllamaInstallation ( ) ;
30
- ollama . CheckInstalledModels ( ) ;
31
- ollama . SetPlatformDependedStrings ( ) ;
32
- }
13
+ private int selectedModelIndex ;
33
14
34
- private async void OnGUI ( )
35
- {
36
- if ( logo )
15
+ private bool isDownloading ;
16
+
17
+ [ MenuItem ( "Tools/Neocortex/Ollama Support" ) ]
18
+ public static void ShowWindow ( )
37
19
{
38
- float x = ( position . width - 512 ) / 2 ;
39
- GUILayout . BeginHorizontal ( ) ;
40
- GUILayout . Space ( x ) ;
41
- GUILayout . Label ( logo , GUILayout . Width ( 512 ) , GUILayout . Height ( 132 ) ) ;
42
- GUILayout . Space ( x ) ;
43
- GUILayout . EndHorizontal ( ) ;
20
+ var window = GetWindow < OllamaSupportWindow > ( false , "Neocortex Ollama Support" , true ) ;
21
+ window . minSize = new Vector2 ( 512 , 352 ) ;
22
+ window . maxSize = new Vector2 ( 512 , 352 ) ;
44
23
}
45
- else
24
+
25
+ private void OnEnable ( )
46
26
{
47
- EditorGUILayout . LabelField ( "Logo not found" , EditorStyles . boldLabel , GUILayout . ExpandWidth ( true ) ) ;
27
+ ollama = new OllamaSupport ( ) ;
28
+ logo = Resources . Load < Texture2D > ( "Visuals/ollama_x_neocortex" ) ;
29
+ ollama . CheckOllamaInstallation ( ) ;
30
+ ollama . CheckInstalledModels ( ) ;
31
+ ollama . SetPlatformDependedStrings ( ) ;
48
32
}
49
33
50
- EditorGUILayout . BeginVertical ( "Box" ) ;
51
-
52
- EditorGUILayout . HelpBox ( "This window provides support for Ollama.\n Click the button below to download the necessary tools." , MessageType . Info ) ;
53
-
54
- string buttonMessage = ollama . IsOllamaInstalled ? "Ollama is Already Installed" : $ "Download Ollama for { ollama . PlatformName } ";
55
-
56
- GUI . enabled = ! ollama . IsOllamaInstalled ;
57
- if ( GUILayout . Button ( buttonMessage , GUILayout . Height ( 30 ) ) )
34
+ private async void OnGUI ( )
58
35
{
59
- Application . OpenURL ( ollama . DownloadUrl ) ;
60
- }
61
- GUI . enabled = true ;
36
+ if ( logo )
37
+ {
38
+ float x = ( position . width - 512 ) / 2 ;
39
+ GUILayout . BeginHorizontal ( ) ;
40
+ GUILayout . Space ( x ) ;
41
+ GUILayout . Label ( logo , GUILayout . Width ( 512 ) , GUILayout . Height ( 132 ) ) ;
42
+ GUILayout . Space ( x ) ;
43
+ GUILayout . EndHorizontal ( ) ;
44
+ }
45
+ else
46
+ {
47
+ EditorGUILayout . LabelField ( "Logo not found" , EditorStyles . boldLabel , GUILayout . ExpandWidth ( true ) ) ;
48
+ }
62
49
63
- GUILayout . Space ( 10 ) ;
50
+ EditorGUILayout . BeginVertical ( "Box" ) ;
64
51
65
- EditorGUILayout . HelpBox (
66
- "At least 8 GB RAM is needed for 7B models, 16 GB for 13B models, and 32 GB for 33B models." +
67
- $ "\n Current Device: VRAM: { SystemInfo . graphicsMemorySize / 1024f : F1} GB, RAM: { SystemInfo . systemMemorySize / 1024f : F1} GB",
68
- MessageType . Warning ) ;
52
+ EditorGUILayout . HelpBox (
53
+ "This window provides support for Ollama.\n Click the button below to download the necessary tools." ,
54
+ MessageType . Info ) ;
69
55
70
- selectedModelIndex = EditorGUILayout . Popup ( "Select Model:" , selectedModelIndex , ollama . Models . Select ( m => m . DisplayName ) . ToArray ( ) ) ;
56
+ string buttonMessage = ollama . IsOllamaInstalled
57
+ ? "Ollama is Already Installed"
58
+ : $ "Download Ollama for { ollama . PlatformName } ";
71
59
72
- bool isSelectedModelDownloaded = ollama . Models [ selectedModelIndex ] . isDownloaded ;
73
- GUI . enabled = ! isSelectedModelDownloaded ;
74
- if ( GUILayout . Button ( "Download Model" , GUILayout . Height ( 30 ) ) )
75
- {
76
- if ( isDownloading )
60
+ GUI . enabled = ! ollama . IsOllamaInstalled ;
61
+ if ( GUILayout . Button ( buttonMessage , GUILayout . Height ( 30 ) ) )
77
62
{
78
- Debug . LogWarning ( "A download is already in progress." ) ;
63
+ Application . OpenURL ( ollama . DownloadUrl ) ;
79
64
}
80
- else
65
+
66
+ GUI . enabled = true ;
67
+
68
+ GUILayout . Space ( 10 ) ;
69
+
70
+ EditorGUILayout . HelpBox (
71
+ "At least 8 GB RAM is needed for 7B models, 16 GB for 13B models, and 32 GB for 33B models." +
72
+ $ "\n Current Device: VRAM: { SystemInfo . graphicsMemorySize / 1024f : F1} GB, RAM: { SystemInfo . systemMemorySize / 1024f : F1} GB",
73
+ MessageType . Warning ) ;
74
+
75
+ GUI . enabled = ollama . IsOllamaInstalled ;
76
+ selectedModelIndex = EditorGUILayout . Popup ( "Select Model:" , selectedModelIndex ,
77
+ ollama . Models . Select ( m => m . DisplayName ) . ToArray ( ) ) ;
78
+ GUI . enabled = true ;
79
+
80
+ bool isSelectedModelDownloaded = ollama . Models [ selectedModelIndex ] . isDownloaded ;
81
+ GUI . enabled = ! isSelectedModelDownloaded && ollama . IsOllamaInstalled ;
82
+ if ( GUILayout . Button ( "Download Model" , GUILayout . Height ( 30 ) ) )
81
83
{
82
- EditorApplication . update += UpdateProgressBar ;
83
- isDownloading = true ;
84
- ollama . DownloadModel ( selectedModelIndex , ( ) =>
84
+ if ( isDownloading )
85
85
{
86
- isDownloading = false ;
87
- ollama . CheckInstalledModels ( ) ;
88
- } ) ;
86
+ Debug . LogWarning ( "A download is already in progress." ) ;
87
+ }
88
+ else
89
+ {
90
+ EditorApplication . update += UpdateProgressBar ;
91
+ isDownloading = true ;
92
+ ollama . DownloadModel ( selectedModelIndex , ( ) =>
93
+ {
94
+ isDownloading = false ;
95
+ ollama . CheckInstalledModels ( ) ;
96
+ } ) ;
97
+ }
89
98
}
90
- }
91
- GUI . enabled = true ;
92
-
93
- GUI . enabled = isSelectedModelDownloaded ;
94
- if ( GUILayout . Button ( "Delete Model" , GUILayout . Height ( 30 ) ) )
95
- {
96
- ollama . DeleteModel ( selectedModelIndex ) ;
97
- ollama . CheckInstalledModels ( ) ;
98
- }
99
- GUI . enabled = true ;
100
99
101
- EditorGUILayout . EndVertical ( ) ;
102
- }
103
-
104
- private void UpdateProgressBar ( )
105
- {
106
- if ( isDownloading )
107
- {
108
- if ( EditorUtility . DisplayCancelableProgressBar ( "Downloading Model" , ollama . ProgressText , ollama . ProgressValue ) )
100
+ GUI . enabled = true ;
101
+
102
+ GUI . enabled = isSelectedModelDownloaded && ollama . IsOllamaInstalled ;
103
+ if ( GUILayout . Button ( "Delete Model" , GUILayout . Height ( 30 ) ) )
109
104
{
110
- isDownloading = false ;
111
- ollama . CancelRequest ( ) ;
105
+ ollama . DeleteModel ( selectedModelIndex ) ;
106
+ ollama . CheckInstalledModels ( ) ;
112
107
}
108
+
109
+ GUI . enabled = true ;
110
+
111
+ EditorGUILayout . EndVertical ( ) ;
113
112
}
114
- else
113
+
114
+ private void UpdateProgressBar ( )
115
115
{
116
- EditorUtility . ClearProgressBar ( ) ;
116
+ if ( isDownloading )
117
+ {
118
+ if ( EditorUtility . DisplayCancelableProgressBar ( "Downloading Model" , ollama . ProgressText ,
119
+ ollama . ProgressValue ) )
120
+ {
121
+ isDownloading = false ;
122
+ ollama . CancelRequest ( ) ;
123
+ }
124
+ }
125
+ else
126
+ {
127
+ EditorUtility . ClearProgressBar ( ) ;
128
+ }
117
129
}
118
130
}
119
- }
131
+ }
0 commit comments