-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpreferences.py
362 lines (313 loc) · 12.9 KB
/
preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import bpy
from .backend import Backend
from .tools import LlamaMeshModelManager
from .utils import get_available_models
def get_downloaded_models(self, context):
items = []
for model in get_available_models():
items.append((model, model, f"Use {model} for local inference"))
if not items:
items.append(("", "No models downloaded", "Download a model first"))
return items
def reset_backend(self, context):
backend = Backend.instance()
backend.reset()
props = bpy.context.scene.meshgen_props
props.state = "READY"
props.history.clear()
for window in bpy.context.window_manager.windows:
for area in window.screen.areas:
if area.type in ["PREFERENCES", "VIEW_3D"]:
area.tag_redraw()
class MeshGenPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
__annotations__ = {
"backend_type": bpy.props.EnumProperty(
name="Backend type",
description="Select the backend type to use for generation",
items=[
(
"LOCAL",
"Local",
"Use local integrated llama_cpp_python backend for inference",
),
(
"REMOTE",
"Remote",
"Use a remote API for inference (Ollama, OpenAI, etc.)",
),
],
default="REMOTE",
update=reset_backend,
),
"current_model": bpy.props.EnumProperty(
name="Current model",
description="Select model for local inference",
items=get_downloaded_models,
update=reset_backend,
),
"download_repo_id": bpy.props.StringProperty(
name="Repository ID",
description="Hugging Face repository ID for the model",
default="bartowski/Meta-Llama-3.1-8B-Instruct-GGUF",
),
"download_filename": bpy.props.StringProperty(
name="Filename",
description="Filename of the model to download",
default="Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
),
"llm_provider": bpy.props.EnumProperty(
name="Provider",
description="Select the provider to use for remote inference",
items=[
(
"huggingface",
"Hugging Face",
"Use the Hugging Face API for inference",
),
("ollama", "Ollama", "Use an Ollama server for inference"),
("anthropic", "Anthropic", "Use the Anthropic API for inference"),
("openai", "OpenAI", "Use the OpenAI API for inference"),
],
default="huggingface",
update=reset_backend,
),
"huggingface_model_id": bpy.props.StringProperty(
name="Model ID",
description="ID of the model to use",
default="meta-llama/Llama-3.3-70B-Instruct",
update=reset_backend,
),
"huggingface_api_key": bpy.props.StringProperty(
name="API key",
description="Hugging Face API key",
default="",
subtype="PASSWORD",
update=reset_backend,
),
"ollama_endpoint": bpy.props.StringProperty(
name="Endpoint",
description="Base URL for the Ollama server",
default="http://localhost:11434",
update=reset_backend,
),
"ollama_model_name": bpy.props.StringProperty(
name="Model name",
description="Name of the model to use",
default="gemma3",
update=reset_backend,
),
"ollama_api_key": bpy.props.StringProperty(
name="API key (optional)",
description="Ollama API key (optional, used for private models)",
default="",
subtype="PASSWORD",
update=reset_backend,
),
"anthropic_model_id": bpy.props.StringProperty(
name="Model ID",
description="ID of the model to use",
default="claude-3-5-sonnet-latest",
update=reset_backend,
),
"anthropic_api_key": bpy.props.StringProperty(
name="API key",
description="Anthropic API key",
default="",
subtype="PASSWORD",
update=reset_backend,
),
"openai_model_id": bpy.props.StringProperty(
name="Model ID",
description="ID of the model to use",
default="gpt-4o",
update=reset_backend,
),
"openai_api_key": bpy.props.StringProperty(
name="API key",
description="OpenAI API key",
default="",
subtype="PASSWORD",
update=reset_backend,
),
"downloading": bpy.props.BoolProperty(default=False),
"download_progress": bpy.props.FloatProperty(
subtype="PERCENTAGE",
min=0.0,
max=100.0,
precision=0,
),
"show_generation_settings": bpy.props.BoolProperty(
name="Show Generation Settings",
description="Show or hide generation settings",
default=False,
),
"temperature": bpy.props.FloatProperty(
name="Temperature",
description="Controls randomness in generation (higher = more creative, lower = more predictable)",
default=0.7,
min=0.0,
max=1.0,
),
"context_length": bpy.props.IntProperty(
name="Context Length",
description="Controls the maximum number of tokens in the context window",
default=32768,
min=1024,
max=65536,
),
"show_integrations_settings": bpy.props.BoolProperty(
name="Show Integrations Settings",
description="Show or hide integrations settings",
default=False,
),
"enable_hyper3d": bpy.props.BoolProperty(
name="Enable Hyper3D",
description="Enable Hyper3D for mesh generation",
default=False,
),
"hyper3d_api_key": bpy.props.StringProperty(
name="API key",
description="Hyper3D API key",
default="awesomemcp",
subtype="PASSWORD",
),
}
def draw(self, context):
layout = self.layout
backend_box = layout.box()
backend_box.label(text="Backend", icon="SETTINGS")
backend_box.prop(self, "backend_type", expand=True)
if self.backend_type == "LOCAL":
info_box = backend_box.box()
info_box.label(text="Run models directly in Blender.", icon="INFO")
col = info_box.column(align=True)
col.label(text="Requires at least 8GB VRAM.")
col.label(text="Small local models may struggle with agentic behaviors.")
local_box = layout.box()
header = local_box.row(align=True)
header.label(text="Downloaded models", icon="PACKAGE")
header.operator("meshgen.open_models_folder", text="", icon="FILE_FOLDER")
models = get_available_models()
if models:
local_box.prop(self, "current_model")
elif not self.downloading:
local_box.label(text="No models downloaded.", icon="INFO")
op = local_box.operator(
"meshgen.download_model",
text="Download Recommended Model",
icon="IMPORT",
)
op.repo_id = self.download_repo_id
op.filename = self.download_filename
if self.downloading:
row = local_box.row(align=True)
row.label(text="Downloading...")
row.prop(self, "download_progress", slider=True, text="")
else:
remote_box = layout.box()
remote_box.prop(self, "llm_provider")
remote_box.separator()
if self.llm_provider == "ollama":
info_box = remote_box.box()
info_box.label(
text="Run models with a local Ollama server.", icon="INFO"
)
col = info_box.column(align=True)
col.label(text="1. Download and install Ollama from ollama.com")
col.label(text="2. Run `ollama serve` in the terminal")
remote_box.separator()
remote_box.prop(self, "ollama_endpoint")
remote_box.prop(self, "ollama_model_name")
remote_box.prop(self, "ollama_api_key")
elif self.llm_provider == "huggingface":
info_box = remote_box.box()
info_box.label(
text="Run models with the Hugging Face API.", icon="INFO"
)
col = info_box.column(align=True)
col.label(text="1. Create an account on hf.co")
col.label(text="2. Go to hf.co/settings/tokens and create a new token")
col.label(text="3. Paste the token into the API key field")
remote_box.separator()
remote_box.prop(self, "huggingface_model_id")
remote_box.prop(self, "huggingface_api_key")
elif self.llm_provider == "anthropic":
info_box = remote_box.box()
info_box.label(text="Run models with the Anthropic API.", icon="INFO")
col = info_box.column(align=True)
col.label(text="1. Create an account on console.anthropic.com")
col.label(
text="2. Go to console.anthropic.com/settings/keys and create a key"
)
col.label(text="3. Paste the key into the API key field")
remote_box.separator()
remote_box.prop(self, "anthropic_model_id")
remote_box.prop(self, "anthropic_api_key")
elif self.llm_provider == "openai":
info_box = remote_box.box()
info_box.label(text="Run models with the OpenAI API.", icon="INFO")
col = info_box.column(align=True)
col.label(text="1. Create an account on platform.openai.com")
col.label(
text="2. Go to platform.openai.com/api-keys and create a new secret key"
)
col.label(text="3. Paste the secret key into the API key field")
remote_box.separator()
remote_box.prop(self, "openai_model_id")
remote_box.prop(self, "openai_api_key")
options_box = layout.box()
header = options_box.row(align=True)
header.prop(
self,
"show_generation_settings",
icon="TRIA_DOWN" if self.show_generation_settings else "TRIA_RIGHT",
icon_only=True,
emboss=False,
)
header.label(text="Generation Settings")
if self.show_generation_settings:
options_box.prop(self, "temperature", slider=True)
options_box.prop(self, "context_length", slider=True)
plugin_box = layout.box()
header = plugin_box.row(align=True)
header.prop(
self,
"show_integrations_settings",
icon="TRIA_DOWN" if self.show_integrations_settings else "TRIA_RIGHT",
icon_only=True,
emboss=False,
)
header.label(text="Integrations")
if self.show_integrations_settings:
llama_mesh_box = plugin_box.box()
llama_mesh_box.label(text="LLaMA-Mesh", icon="PACKAGE")
llama_mesh_box.label(
text="Use LLaMA-Mesh for local mesh generation and understanding.",
)
if LlamaMeshModelManager.instance().is_loaded:
llama_mesh_box.label(text="LLaMA-Mesh is loaded", icon="CHECKBOX_HLT")
llama_mesh_box.operator(
"meshgen.unload_llama_mesh", text="Unload LLaMA-Mesh", icon="X"
)
else:
if self.backend_type == "LOCAL":
llama_mesh_box.label(
text="Requires 5GB additional VRAM. Not recommended with local backend.",
icon="ERROR",
)
llama_mesh_box.operator(
"meshgen.load_llama_mesh", text="Load LLaMA-Mesh", icon="IMPORT"
)
hyper3d_box = plugin_box.box()
hyper3d_box.label(text="Hyper3D", icon="PACKAGE")
hyper3d_box.label(
text="Use Hyper3D (Rodin) API for mesh generation.",
)
hyper3d_box.prop(self, "enable_hyper3d")
if self.enable_hyper3d:
hyper3d_box.prop(self, "hyper3d_api_key")
def register():
bpy.utils.register_class(MeshGenPreferences)
def unregister():
bpy.utils.unregister_class(MeshGenPreferences)