Build [v1.9.19]
This commit is contained in:
51
backend/scripts/init_settings.py
Normal file
51
backend/scripts/init_settings.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add parent directory to path
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import SessionLocal, engine
|
||||
import models
|
||||
|
||||
def init_settings():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# Default AI Prompt from User Request
|
||||
default_prompt = """identify and summarise the minimal necessary information for a quick description if item. I need the following output - <field name> : the result from you.
|
||||
For any field, do not add comments in parenthesis.
|
||||
|
||||
Item: in three words type of this item
|
||||
Type: what type of item is, like "spare parts", "consumables", "patch cords" etc.
|
||||
Description: description (max 5 words)
|
||||
Category: category, if any
|
||||
Connector: connectors
|
||||
Size: size or length
|
||||
Color: color if useful
|
||||
PartNr: part number if any
|
||||
OCR: identification string for local OCR matching"""
|
||||
|
||||
# We will wrap this in a instruction to return JSON for easier parsing while keeping the user's content
|
||||
final_prompt = f"IMAGE ANALYSIS INSTRUCTIONS:\n{default_prompt}\n\nIMPORTANT: Return ONLY a valid JSON object with the keys: Item, Type, Description, Category, Connector, Size, Color, PartNr, OCR."
|
||||
|
||||
existing = db.query(models.SystemSetting).filter(models.SystemSetting.key == "ai_extraction_prompt").first()
|
||||
if not existing:
|
||||
db.add(models.SystemSetting(key="ai_extraction_prompt", value=final_prompt))
|
||||
print("Added default AI prompt setting.")
|
||||
|
||||
# Add default backup settings if missing
|
||||
defaults = {
|
||||
"backup_retention_count": "10",
|
||||
"backup_schedule_hour": "3",
|
||||
"backup_schedule_freq_days": "1"
|
||||
}
|
||||
for key, val in defaults.items():
|
||||
if not db.query(models.SystemSetting).filter(models.SystemSetting.key == key).first():
|
||||
db.add(models.SystemSetting(key=key, value=val))
|
||||
print(f"Added default setting: {key}")
|
||||
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_settings()
|
||||
Reference in New Issue
Block a user