# arquivo: /var/www/html/cagpublico/cag/projeto/gerar_fabiano_embeddings.py

import openai
import json
from dotenv import load_dotenv
import os
import sys

# Força o path da pasta atual para importar fabiano_prompts
sys.path.append("/var/www/html/cagpublico/cag/projeto")

# Carrega a variável de ambiente do .env
load_dotenv("/var/www/html/cagpublico/.env")
openai.api_key = "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"


# Importa os system prompts normalmente
from fabiano_prompts import (
    system_educacional_carga_termica,
    system_cadastro_projeto,
    system_cadastro_ambiente,
    system_lista_ambiente,
    system_biblioteca,
    system_relatorios,
    system_termo_referencia,
    system_geral
)

prompts_dict = {
    "system_educacional_carga_termica": system_educacional_carga_termica,
    "system_cadastro_projeto": system_cadastro_projeto,
    "system_cadastro_ambiente": system_cadastro_ambiente,
    "system_lista_ambiente": system_lista_ambiente,
    "system_biblioteca": system_biblioteca,
    "system_relatorios": system_relatorios,
    "system_termo_referencia": system_termo_referencia,
    "system_geral": system_geral
}

# Gera os embeddings
embeddings = {}
for nome, prompt in prompts_dict.items():
    print(f"Gerando embedding para: {nome}")
    response = openai.Embedding.create(
        input=prompt["content"],
        model="text-embedding-ada-002"
    )
    vector = response["data"][0]["embedding"]
    embeddings[nome] = vector

# Salva no caminho especificado
output_path = "/var/www/html/cagpublico/cag/projeto/fabiano_embeddings.json"
with open(output_path, "w") as f:
    json.dump(embeddings, f)

print(f"✅ Embeddings salvos com sucesso em: {output_path}")
