Spaces:
Sleeping
Sleeping
| from langchain_mistralai import ChatMistralAI | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from langchain_core.output_parsers import StrOutputParser | |
| prompt_ecommerce = ChatPromptTemplate.from_template(""" | |
| Tu es un expert en e-commerce. | |
| L'utilisateur va te donner une liste de produits sous forme de texte naturel, par exemple : | |
| "Montre à 10 € avec lien https://..., sac à main à 20 € lien https://..." | |
| Ta mission : | |
| 1. Pour chaque produit détecté dans ce texte : | |
| - Estime un coût total (prix donné + livraison estimée 5 € + pub 5 €) | |
| - Calcule un prix de vente rentable avec une marge de 30 % | |
| - Donne un bénéfice estimé | |
| - Fais une petite analyse marketing | |
| 2. À la fin, crée un tableau récapitulatif avec : | |
| - Nom du produit | |
| - Coût total | |
| - Prix conseillé | |
| - Bénéfice | |
| - Lien | |
| Voici la liste de produits à analyser : | |
| {produits} | |
| """) | |
| def analyser_produits_via_agent(produits_texte, api_key): | |
| try: | |
| llm = ChatMistralAI( | |
| model="mistral-small", | |
| temperature=0.4, | |
| max_tokens=1500, | |
| api_key=api_key | |
| ) | |
| chain_ecommerce = prompt_ecommerce | llm | StrOutputParser() | |
| result = chain_ecommerce.invoke({"produits": produits_texte}) | |
| return result | |
| except Exception as e: | |
| return f"Erreur : {e}" | |