- Add ELAI avatar seed data (7 avatars with codes, URLs, voice configs) from the original backend's avatars.json - Add missing system parameters: encoach.aws_region (eu-west-1), encoach.whisper_workers (4) - Add training tips import script with pathways_2_rw.json data source - Add action_compute_embeddings() method to training tip model for computing sentence-transformer embeddings on demand Made-with: Cursor
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""Import training tips from pathways JSON into encoach.training.tip model.
|
|
|
|
Run inside the Odoo container via:
|
|
odoo shell -d encoach < /mnt/custom/scripts/import_training_tips.py
|
|
|
|
This script:
|
|
1. Reads pathways_2_rw.json
|
|
2. Creates encoach.training.tip records (tip_id, category, content)
|
|
3. Computes sentence-transformer embeddings and stores them
|
|
"""
|
|
import json
|
|
import os
|
|
import pickle
|
|
import sys
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
JSON_PATH = os.path.join(SCRIPT_DIR, "pathways_2_rw.json")
|
|
|
|
|
|
def main():
|
|
with open(JSON_PATH, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
|
|
TipModel = env["encoach.training.tip"].sudo()
|
|
|
|
tips_data = []
|
|
for unit in data["units"]:
|
|
for page in unit["pages"]:
|
|
for tip in page["tips"]:
|
|
category = tip["category"].lower().replace(" ", "_")
|
|
tips_data.append({
|
|
"tip_id": tip["id"],
|
|
"category": category,
|
|
"content": tip["text"],
|
|
})
|
|
|
|
created = 0
|
|
skipped = 0
|
|
for td in tips_data:
|
|
existing = TipModel.search([("tip_id", "=", td["tip_id"])], limit=1)
|
|
if existing:
|
|
skipped += 1
|
|
continue
|
|
TipModel.create(td)
|
|
created += 1
|
|
|
|
env.cr.commit()
|
|
print(f"Tips import complete: {created} created, {skipped} skipped (already exist)")
|
|
|
|
try:
|
|
from sentence_transformers import SentenceTransformer
|
|
import numpy as np
|
|
|
|
print("Computing embeddings with all-MiniLM-L6-v2...")
|
|
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
|
|
tips = TipModel.search([("embedding", "=", False)])
|
|
if not tips:
|
|
print("All tips already have embeddings.")
|
|
return
|
|
|
|
for i, tip in enumerate(tips):
|
|
vec = model.encode([tip.content]).astype(np.float32)[0]
|
|
tip.embedding = pickle.dumps(vec)
|
|
if (i + 1) % 10 == 0:
|
|
print(f" Embedded {i + 1}/{len(tips)} tips...")
|
|
|
|
env.cr.commit()
|
|
print(f"Embeddings computed for {len(tips)} tips.")
|
|
|
|
except ImportError:
|
|
print("WARNING: sentence-transformers not available. Tips created without embeddings.")
|
|
print("Embeddings can be computed later by re-running this script.")
|
|
|
|
|
|
main()
|