2023-12-30 01:40:29 +00:00
|
|
|
import bpy
|
2023-05-27 07:25:41 +00:00
|
|
|
from bpy import props
|
|
|
|
from bpy.types import AddonPreferences
|
2023-12-30 01:40:29 +00:00
|
|
|
from .gpt_cst import UI
|
2023-05-27 07:25:41 +00:00
|
|
|
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-05-27 07:25:41 +00:00
|
|
|
class BLENDERGPT_AddonPreferences(AddonPreferences):
|
2023-05-29 05:12:29 +00:00
|
|
|
bl_idname = "blender-gpt"
|
2023-05-28 16:23:43 +00:00
|
|
|
|
|
|
|
openai_key: props.StringProperty(
|
|
|
|
name="OPENAI API Key",
|
2023-05-27 07:25:41 +00:00
|
|
|
description="Enter your OpenAI API Key",
|
|
|
|
default="",
|
|
|
|
subtype="PASSWORD",
|
|
|
|
)
|
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
languages = [
|
|
|
|
('en', "English", ""),
|
|
|
|
('es', "Español", ""),
|
|
|
|
('zh', "繁體中文", ""),
|
|
|
|
('cn', "简体中文", ""),
|
|
|
|
('fr', "Français", ""),
|
|
|
|
]
|
|
|
|
language: props.EnumProperty(
|
|
|
|
name="Language",
|
|
|
|
items=languages,
|
|
|
|
default='en',
|
2023-12-30 02:54:59 +00:00
|
|
|
description="Select your preferred language",
|
|
|
|
update=lambda self, context: self.update_language(context)
|
2023-12-30 01:40:29 +00:00
|
|
|
)
|
|
|
|
|
2023-05-27 07:25:41 +00:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
2023-05-28 16:23:43 +00:00
|
|
|
layout.prop(self, "openai_key")
|
2023-12-30 01:40:29 +00:00
|
|
|
layout.prop(self, "language", text="Language")
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
def update_language(self, context):
|
2023-12-30 05:35:46 +00:00
|
|
|
if 'blender-gpt' not in bpy.context.preferences.addons.keys():
|
|
|
|
return
|
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
prefs = context.preferences.addons['blender-gpt'].preferences
|
|
|
|
lan = prefs.language
|
|
|
|
|
|
|
|
# model
|
|
|
|
current_model = getattr(context.scene, "model", "gpt-3.5-turbo")
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
bpy.types.Scene.model = bpy.props.EnumProperty(
|
|
|
|
name=UI['label_model'][lan],
|
|
|
|
description=UI['label_model_description'][lan],
|
|
|
|
items=[
|
2023-12-30 02:54:59 +00:00
|
|
|
("gpt-3.5-turbo", UI['model_options'][lan]
|
|
|
|
['gpt3.5'], UI['model_options'][lan]['gpt3.5']),
|
|
|
|
("gpt-4", UI['model_options'][lan]['gpt4'],
|
|
|
|
UI['model_options'][lan]['gpt4']),
|
2023-12-30 01:40:29 +00:00
|
|
|
],
|
|
|
|
default=current_model,
|
|
|
|
)
|
|
|
|
setattr(context.scene, "model", current_model)
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
# prompt_input
|
|
|
|
current_prompt_input = getattr(context.scene, "prompt_input", "")
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
bpy.types.Scene.prompt_input = bpy.props.StringProperty(
|
|
|
|
name=UI['command'][lan],
|
|
|
|
description=UI['command_instruction'][lan],
|
|
|
|
default=current_prompt_input,
|
|
|
|
)
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
setattr(context.scene, "prompt_input", current_prompt_input)
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
# creativity
|
|
|
|
current_creativity = getattr(context.scene, "creativity", 0)
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
bpy.types.Scene.creativity = bpy.props.FloatProperty(
|
|
|
|
name=UI['creativity'][lan],
|
|
|
|
description=UI['creativity'][lan],
|
|
|
|
default=current_creativity,
|
|
|
|
min=0,
|
|
|
|
max=1,
|
|
|
|
)
|
2023-12-30 02:54:59 +00:00
|
|
|
|
2023-12-30 01:40:29 +00:00
|
|
|
setattr(context.scene, "creativity", current_creativity)
|