Make Ollama prompt editable in admin AI settings
- Add prompt column to ai_settings (migration) - AiSetting: DEFAULT_PROMPT constant + getActivePrompt() (falls back to default if empty) - ProcessNailPolishImage: reads prompt from DB instead of hardcoded - Admin view: textarea to edit prompt, shows active prompt, reset-to-default link Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2677ee6f39
commit
f60221d0ef
@@ -19,11 +19,13 @@ class AiSettingController extends Controller
|
||||
$request->validate([
|
||||
'ollama_url' => 'required|url|max:255',
|
||||
'ollama_model' => 'required|string|max:100',
|
||||
'prompt' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$ai = AiSetting::get();
|
||||
$ai->ollama_url = rtrim($request->ollama_url, '/');
|
||||
$ai->ollama_model = $request->ollama_model;
|
||||
$ai->prompt = $request->filled('prompt') ? $request->prompt : null;
|
||||
$ai->save();
|
||||
|
||||
return redirect()->route('admin.ai.show')->with('success', 'KI-Einstellungen gespeichert.');
|
||||
|
||||
@@ -33,20 +33,7 @@ class ProcessNailPolishImage implements ShouldQueue
|
||||
$ai = AiSetting::get();
|
||||
$imageB64 = base64_encode(Storage::disk('public')->get($import->image_path));
|
||||
|
||||
$prompt = <<<PROMPT
|
||||
You are analyzing a nail polish or nail product bottle/container image.
|
||||
Extract exactly these three fields and respond ONLY with a valid JSON object, no explanation, no markdown:
|
||||
{
|
||||
"name": "the full product name or color description (e.g. 'Modeling Base Calcium Neutral Pink', 'Ruby Red', 'French White')",
|
||||
"number": "the product code or article number printed on the label or cap (digits, letters, hyphens only — e.g. '12392-7', '123', 'NP-05')",
|
||||
"manufacturer": "the brand or company name (the logo/brand printed on the product — e.g. 'NEONAIL', 'OPI', 'essie', 'Catrice')"
|
||||
}
|
||||
Rules:
|
||||
- manufacturer = the brand/logo name (usually prominent on the label)
|
||||
- name = the descriptive product/color name (NOT the brand)
|
||||
- number = numeric or alphanumeric code (NOT the color name)
|
||||
- If a value is genuinely not visible, use null
|
||||
PROMPT;
|
||||
$prompt = $ai->getActivePrompt();
|
||||
|
||||
$response = Http::timeout(160)->post("{$ai->ollama_url}/api/generate", [
|
||||
'model' => $ai->ollama_model,
|
||||
|
||||
@@ -8,7 +8,27 @@ class AiSetting extends Model
|
||||
{
|
||||
protected $table = 'ai_settings';
|
||||
|
||||
protected $fillable = ['ollama_url', 'ollama_model'];
|
||||
protected $fillable = ['ollama_url', 'ollama_model', 'prompt'];
|
||||
|
||||
public const DEFAULT_PROMPT = <<<PROMPT
|
||||
You are analyzing a nail polish or nail product bottle/container image.
|
||||
Extract exactly these three fields and respond ONLY with a valid JSON object, no explanation, no markdown:
|
||||
{
|
||||
"name": "the full product name or color description (e.g. 'Modeling Base Calcium Neutral Pink', 'Ruby Red', 'French White')",
|
||||
"number": "the product code or article number printed on the label or cap (digits, letters, hyphens only — e.g. '12392-7', '123', 'NP-05')",
|
||||
"manufacturer": "the brand or company name (the logo/brand printed on the product — e.g. 'NEONAIL', 'OPI', 'essie', 'Catrice')"
|
||||
}
|
||||
Rules:
|
||||
- manufacturer = the brand/logo name (usually prominent on the label)
|
||||
- name = the descriptive product/color name (NOT the brand)
|
||||
- number = numeric or alphanumeric code (NOT the color name)
|
||||
- If a value is genuinely not visible, use null
|
||||
PROMPT;
|
||||
|
||||
public function getActivePrompt(): string
|
||||
{
|
||||
return !empty($this->prompt) ? $this->prompt : self::DEFAULT_PROMPT;
|
||||
}
|
||||
|
||||
public static function get(): self
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user