Skip to content

Commit 94a2414

Browse files
committed
feat: allow model/prompt overriding for vision per field
1 parent 95f5d90 commit 94a2414

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

assets/components/modai/js/mgr/autosummary.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ Ext.onReady(function() {
326326
timeout: 0,
327327
params: {
328328
action: 'modAI\\Processors\\Prompt\\Vision',
329-
image: base64Data
329+
image: base64Data,
330+
fieldName
330331
},
331332
listeners: {
332333
success: {

core/components/modai/src/Processors/Prompt/Vision.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,17 @@ public function process()
1212
{
1313
set_time_limit(0);
1414

15+
$field = $this->getProperty('fieldName');
16+
1517
$image = $this->getProperty('image');
1618
if (empty($image)) {
1719
return $this->failure('Image is required');
1820
}
1921

20-
$model = Settings::getSetting($this->modx, 'vision.model');
21-
if (empty($model)) {
22-
return $this->failure('vision.model setting is required');
23-
}
24-
25-
$prompt = Settings::getSetting($this->modx, 'vision.prompt');
26-
if (empty($prompt)) {
27-
return $this->failure('vision.prompt setting is required');
28-
}
29-
3022
try {
23+
$model = Settings::getVisionFieldSetting($this->modx, $field, 'model');
24+
$prompt = Settings::getVisionFieldSetting($this->modx, $field, 'prompt');
25+
3126
$aiService = AIServiceFactory::new($model, $this->modx);
3227
$result = $aiService->getVision($prompt, $image, VisionConfig::new($model));
3328

core/components/modai/src/Settings.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,21 @@ public static function getImageFieldSetting(modX $modx, string $field, string $s
5252

5353
return $value;
5454
}
55+
56+
/**
57+
* @throws RequiredSettingException
58+
*/
59+
public static function getVisionFieldSetting(modX $modx, string $field, string $setting, bool $required = true): string {
60+
if (!empty($field)) {
61+
$value = $modx->getOption("modai.vision.$field.$setting", null, $modx->getOption("modai.vision.$setting"), true);
62+
} else {
63+
$value = $modx->getOption("modai.vision.$setting");
64+
}
65+
66+
if ($required && empty($value)) {
67+
throw new RequiredSettingException("modai.vision.$setting");
68+
}
69+
70+
return $value;
71+
}
5572
}

0 commit comments

Comments
 (0)