Skip to content

Commit

Permalink
Merge pull request #23 from Nael-Sayegh/default-description-prompt
Browse files Browse the repository at this point in the history
Possibility to customize the default prompt text to describe an image
  • Loading branch information
aaclause committed Dec 9, 2023
2 parents b8ac62b + 48846bc commit 5bf78b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
38 changes: 35 additions & 3 deletions addon/globalPlugins/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"maxWidth": "integer(min=0, default=0)",
"quality": "integer(min=0, max=100, default=85)",
"resize": "boolean(default=False)",
"resizeInfoDisplayed": "boolean(default=False)"
"resizeInfoDisplayed": "boolean(default=False)",
"useCustomPrompt": "boolean(default=False)",
"customPromptText": 'string(default="")'
},
"renewClient": "boolean(default=False)",
"debug": "boolean(default=False)"
Expand Down Expand Up @@ -170,7 +172,7 @@ def makeSettings(self, settingsSizer):

sHelper.addItem(TTSSizer)

imageGroupLabel = _("Images")
imageGroupLabel = _("Image description")
imageSizer = wx.StaticBoxSizer(wx.VERTICAL, self, label=imageGroupLabel)
imageBox = imageSizer.GetStaticBox()
imageGroup = gui.guiHelper.BoxSizerHelper(self, sizer=imageSizer)
Expand Down Expand Up @@ -215,6 +217,26 @@ def makeSettings(self, settingsSizer):
)
self.quality.SetValue(conf["images"]["quality"])

self.useCustomPrompt = imageGroup.addItem(
wx.CheckBox(
imageBox,
label=_("Customize default text &prompt")
)
)
self.useCustomPrompt.Bind(wx.EVT_CHECKBOX, self.onDefaultPrompt)
self.useCustomPrompt.SetValue(conf["images"]["useCustomPrompt"])
self.customPromptText = imageGroup.addLabeledControl(
_("Default &text prompt:"),
wxCtrlClass=wx.TextCtrl,
style=wx.TE_MULTILINE
)
self.customPromptText.SetMinSize((250, -1))
self.customPromptText.Enable(False)
if conf["images"]["useCustomPrompt"]:
self.useCustomPrompt.SetValue(True)
self.customPromptText.SetValue(conf["images"]["customPromptText"])
self.customPromptText.Enable()

sHelper.addItem(imageSizer)

sHelper.addItem(mainDialogSizer)
Expand All @@ -230,6 +252,12 @@ def onResize(self, evt):
self.maxWidth.Enable(self.resize.GetValue())
self.maxHeight.Enable(self.resize.GetValue())
self.quality.Enable(self.resize.GetValue())
def onDefaultPrompt(self, evt):
if self.useCustomPrompt.GetValue():
self.customPromptText.Enable()
self.customPromptText.SetValue(conf["images"]["customPromptText"])
else:
self.customPromptText.Enable(False)

def onSave(self):
api_key = self.APIKey.GetValue().strip()
Expand Down Expand Up @@ -261,7 +289,11 @@ def onSave(self):
conf["images"]["maxWidth"] = self.maxWidth.GetValue()
conf["images"]["maxHeight"] = self.maxHeight.GetValue()
conf["images"]["quality"] = self.quality.GetValue()

if self.useCustomPrompt.GetValue():
conf["images"]["useCustomPrompt"] = True
conf["images"]["customPromptText"] = self.customPromptText.GetValue()
else:
conf["images"]["useCustomPrompt"] = False

class GlobalPlugin(globalPluginHandler.GlobalPlugin):

Expand Down
5 changes: 4 additions & 1 deletion addon/globalPlugins/openai/maindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

addonHandler.initTranslation()

DEFAULT_PROMPT_IMAGE_DESCRIPTION = _("Describe the images in as much detail as possible.")
TTS_FILE_NAME = os.path.join(DATA_DIR, "tts.wav")
DATA_JSON_FP = os.path.join(DATA_DIR, "data.json")

Expand Down Expand Up @@ -380,6 +379,10 @@ def __init__(
):
if not client or not conf:
return
if conf["images"]["useCustomPrompt"]:
DEFAULT_PROMPT_IMAGE_DESCRIPTION = conf["images"]["customPromptText"]
else:
DEFAULT_PROMPT_IMAGE_DESCRIPTION = _("Describe the images in as much detail as possible.")
self.client = client
self.conf = conf
self.data = self.loadData()
Expand Down

0 comments on commit 5bf78b4

Please sign in to comment.