Compare commits

...

7 Commits

Author SHA1 Message Date
40c7ce6968 Ajout d'un README détaillant le fonctionnement et l'utilisation du RAG 2025-11-14 16:02:04 +01:00
81fdec1c32 Correction d'une typo, correction dans le main d'un problème d'attribut lorsque evaluate n'etait pas appelé et ajout d'un indicateur pour la fonction add de la pipeline montrant quels documents sont ajoutés à la BDD. 2025-11-14 15:58:31 +01:00
f94c7d4086 Ajout de l'évaluateur, de mon côté le score est de 2/71... car la plupar des réponses sont: ⚠️ Limite de requêtes atteinte. Attendez 1 minute et réessayez. Il faudrait essayer avec un modèle acceptant plus de requêtes, éventuellement en local. 2025-11-13 16:07:34 +01:00
3fc4020316 Ajout du parser, pour appeler les fonctions, il faut maintenant entrer la fonction désirée (run, add, reset ou query avec l'argument approprié, prochaine étape: ajouter un README pour décrire le fonctionnement et un evaluator permettant de jauger le RAG. 2025-11-12 16:55:35 +01:00
647ffa7a84 Ajout du constructeur de la pipeline, les fonctions sont appelées dans le main, la prochaine étape est d'ajouter un parser pour pouvoir exécuter la fonction choisie depuis le terminal. 2025-11-06 16:22:24 +01:00
abe9e38628 changement des sources de données pour des fichiers correctement lisibles par le retriever. 2025-11-05 16:01:01 +01:00
195b3c05c8 Passage de ollama à groq pour le générateur de réponse, nécessite une clé API. 2025-11-05 15:59:36 +01:00
24 changed files with 1042 additions and 109 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ venv/
# Logs
*.log
.env

168
README.md Normal file
View File

@ -0,0 +1,168 @@
[TOC]
# RAG Pipeline
Ce pipeline implémente un RAG relativement simple qu'il est possible d'améliorer et changer les implémentations.
Les implémentations comportent un indexer, un datastore, un retriever, un response generator et un evaluator.
Le RAG s'utilise grâce à une Command Line Interface (CLI).
## Sommaire
1. Architecture
2. Installation
3. Utilisation
## Architecture
Le pipeline organise l'action de :
- L'indexer découpe les documents en chunks grâce à l'HybridChunker de docling. Les chunks sont ensuite convertis en DataItem. Ces items contiennent le contenu de chaque chunk ainsi que la source du document et conservent les métadonnées.
- Le datastore vectorise les DataItems passés par l'indexer en utilisant le modèle "all-MiniLM-L6-v2" de SentenceTransformers et les stocke dans une base de données lancedb. Il vectorise les requêtes passées par le même modèle et utilise les méthodes de recherche de la BDD.
- Le retriever utilise le CrossEncoder de SentenceTransformers pour classer les documents récupérés par ordre de similarité avec la requête.
- Le response generator utilise une API Groq avec le modèle "llama-3.1-8b-instant" pour générer les réponses à partir des documents récupérés. Il contient aussi le prompt système définissant le comportement du modèle de génération.
- L'evaluator évalue les performances du système en comparant les réponses du modèle avec celles fournies pour des questions type. Le modèle utilisé est le même que pour le générateur de réponses.
![Schéma de fonctionnement du RAG](./pipeline.png)
.
├── create_parser.py
├── data
│ ├── eval
│ ├── sample-lancedb
│ │ └── rag-table.lance
│ └── source
├── main.py
├── model
├── README.md
├── requirements.txt
├── src
│ ├── impl
│ │ ├── datastore.py
│ │ ├── evaluator.py
│ │ ├── indexer.py
│ │ ├── __init__.py
│ │ ├── response_generator.py
│ │ └── retriever.py
│ ├── __init__.py
│ ├── interface
│ │ ├── base_datastore.py
│ │ ├── base_evaluator.py
│ │ ├── base_indexer.py
│ │ ├── base_response_generator.py
│ │ ├── base_retriever.py
│ └── RAG_pipeline.py
├── tests
│ └── test_rag.py
## Installation
##### Environnement virtuel
L'utilisation d'un environnement virtuel est recommandée:
```bash
python -m venv RAG_venv
source RAG_venv/bin/activate # On Windows: venv\Scripts\activate
```
##### Dépendances
Les dépendances sont installées avec:
```bash
pip install -r requirements.txt
```
##### Variables d'environnement:
Le projet utilise une variable d'environnement pour stocker la clé API GROQ.
Pour en créer une:
1. Aller sur https://console.groq.com
2. Créer un compte (gratuit)
3. Générer une clé API
4. Créer une variable d'environnement:
```bash
export GROQ_API_KEY="votre_cle_ici"
```
## Utilisation
La CLI implémente plusieurs commandes:
- reset, pour réinitialiser la BDD:
```bash
python3 main.py reset
```
- add, pour ajouter un ou plusieurs documents à la BDD, par défaut le répertoire data/source/ à la racine du projet:
```bash
python3 main.py add
```
Il est aussi possible de spécifier un chemin vers un document ou un répertoire:
```bash
python3 main.py add --path "chemin vers un dossier ou fichier"
```
- evaluate, pour lancer l'évaluation du modèle, par défaut le fichier data/eval/sample_questions.json, il est aussi possible d'ajouter son propre fichier .json en spécifiant le chemin:
```bash
python3 main.py evaluate
```
ou
```bash
python3 main.py evaluate --eval_file "chemin vers un fichier .json"
```
- run, exécute la pipeline dans son intégralité, reset la BDD, ajoute les documents et lance une évaluation, les paramètres peuvent être ajustés avec les options --path et --eval_file comme pour add et evaluate:
```bash
python3 main.py run
```
```bash
python3 main.py run --path "chemin vers les documents à ajouter" --eval_file "chemin vers les questions/réponses en .json"
```
- query, envoie une requête à la pipeline:
```bash
python3 main.py query "requête à saisir entre guillemets"
```
Il est possible d'obtenir la liste des commandes avec -h:
```bash
python3 main.py -h
```
Ou plus d'informations sur une commande en particulier:
```bash
python3 main.py query -h
```
## Sources
Le squelette du RAG utilisé vient de:
https://github.com/pixegami/simple-rag-pipeline

63
create_parser.py Normal file
View File

@ -0,0 +1,63 @@
import argparse
def create_parser():
parser = argparse.ArgumentParser(
description="RAG pipeline CLI"
)
path_arg_parent = argparse.ArgumentParser(add_help=False)
path_arg_parent.add_argument(
"-p",
"--path",
type=str,
required=False,
help="Path to a directory containing documents to index.",
)
eval_file_arg_parent = argparse.ArgumentParser(add_help=False)
eval_file_arg_parent.add_argument(
"-f",
"--eval_file",
type=str,
required=False,
help="Path to a .json file with question/expected_answer pairs.",
)
subparsers = parser.add_subparsers(dest="commands", help="Enter a command", required=True)
subparsers.add_parser(
"run",
help="Run the full pipeline, i.e Reset, add and evaluate",
parents=[path_arg_parent, eval_file_arg_parent]
)
subparsers.add_parser(
"reset",
help="Reset the pipeline"
)
subparsers.add_parser(
"add",
help="Add the documents to the database",
parents=[path_arg_parent]
)
subparsers.add_parser(
"evaluate",
help="Evaluate the model",
parents=[eval_file_arg_parent]
)
query_parser = subparsers.add_parser(
"query",
help="Query the documents"
)
query_parser.add_argument(
"prompt",
type=str,
help="Enter the query"
)
return parser

View File

@ -0,0 +1,357 @@
[
{
"question": "What is the name of the company?",
"answer": "The company is named TShirtCo, a fictional enterprise established with a focus on personalized t-shirt production. This name reflects its core business of designing and selling custom apparel, aligning with its mission to offer unique, ethically produced clothing to its customers as of November 13, 2025.",
"expected_answer": "TShirtCo"
},
{
"question": "Where is TShirtCo located?",
"answer": "TShirtCo is located at 123 Rue de Paris, 75000 Paris, France. This central address in Paris, a major cultural and commercial hub, was strategically chosen to enhance visibility and accessibility, supporting its growth since January 1, 2020, up to today, November 13, 2025.",
"expected_answer": "123 Rue de Paris, 75000 Paris, France"
},
{
"question": "What is the SIRET number of TShirtCo?",
"answer": "The SIRET number of TShirtCo is 123 456 789 00012. This unique identifier, issued by the French government, confirms its legal registration since 2020, essential for tax and business operations as of November 13, 2025.",
"expected_answer": "123 456 789 00012"
},
{
"question": "Who is the director of TShirtCo?",
"answer": "The director of TShirtCo is John Doe, who has led the company since its founding on January 1, 2020. As the visionary behind its ethical production focus, he continues to steer its strategic direction as of November 13, 2025.",
"expected_answer": "John Doe"
},
{
"question": "What is the capital social of TShirtCo?",
"answer": "The capital social of TShirtCo is 50,000 €. This initial investment, established at its creation, has funded equipment and inventory, providing a solid financial foundation for its operations over the past nearly six years as of late 2025.",
"expected_answer": "50 000 €"
},
{
"question": "What is the price of a red T-shirt with Motif1 in size M?",
"answer": "The price of a red T-shirt with Motif1 in size M is 18.5 €. This base cost reflects French manufacturing and Polish cotton, offering a competitive rate for a personalized, ethically produced item, available in stock as of November 13, 2025.",
"expected_answer": "18.5 €"
},
{
"question": "Where is the red T-shirt with Motif1 manufactured?",
"answer": "The red T-shirt with Motif1 is manufactured in France. This local production supports TShirtCo's ethical standards, reducing carbon footprint and boosting the French textile industry, a practice upheld since 2020 and ongoing in 2025.",
"expected_answer": "France"
},
{
"question": "How many red T-shirts with Motif1 are in stock?",
"answer": "There are 148 red T-shirts with Motif1 currently in stock. This inventory, spread across sizes S, M, L, and XL, ensures TShirtCo can meet demand as of November 13, 2025, though levels may adjust with new orders.",
"expected_answer": "148"
},
{
"question": "What is the total stock of all T-shirts across all colors and motifs?",
"answer": "The total stock of all T-shirts across all colors and motifs exceeds 1,000 units, with individual stocks like 148 for red Motif1, 160 for blue Motif8, and 196 for black Motif5. This aggregate, based on the catalog as of November 2025, reflects a robust inventory managed by TShirtCo.",
"expected_answer": ">1000 (approximate)"
},
{
"question": "What is the net profit for TShirtCo in 2024?",
"answer": "The net profit for TShirtCo in 2024 is 19,040 €. This figure, derived from a 185,400 € turnover minus expenses and a 3,360 € tax, indicates a healthy financial year ending December 31, 2024, setting a strong base for 2025 growth.",
"expected_answer": "19 040 €"
},
{
"question": "How many employees does TShirtCo have?",
"answer": "TShirtCo currently employs 8 individuals as of November 13, 2025. This team includes full-time staff like John Doe and part-time workers like Tom Lemoine, supporting its production and sales operations since its expansion in 2024.",
"expected_answer": "8"
},
{
"question": "What is the salary of Claire Moreau?",
"answer": "Claire Moreau, the Responsable production, earns a gross monthly salary of 3,200 €. This compensation, set since her hiring on February 15, 2020, reflects her critical role in overseeing TShirtCo's manufacturing as of late 2025.",
"expected_answer": "3 200 €"
},
{
"question": "When was Ahmed Benali hired?",
"answer": "Ahmed Benali was hired on June 10, 2021. His role as an Opérateur sérigraphie has been pivotal in TShirtCo's personalized t-shirt production, contributing to its growth over the past four years as of November 13, 2025.",
"expected_answer": "10/06/2021"
},
{
"question": "What is the client name for order CMD-2024-001?",
"answer": "The client name for order CMD-2024-001 is Marie Dupont. She placed this order on March 15, 2024, for red T-shirts with Motif1 and blue T-shirts with Motif5, which was delivered, marking an early success for TShirtCo.",
"expected_answer": "Marie Dupont"
},
{
"question": "What is the status of order CMD-2025-003?",
"answer": "The status of order CMD-2025-003 is 'Annulée' (Cancelled). Placed by Tom Durand on March 5, 2025, this order was canceled, possibly due to a change in plans, as recorded in TShirtCo's order history as of today.",
"expected_answer": "Annulée"
},
{
"question": "What is the total amount TTC for invoice FAC-2025-042?",
"answer": "The total amount TTC for invoice FAC-2025-042 is 81.12 €. Issued on March 14, 2025, to Léa Moreau, this includes t-shirts and shipping with 20% VAT, reflecting a standard transaction completed by late 2025.",
"expected_answer": "81.12 €"
},
{
"question": "What is the main product supplied by TShirtFactory?",
"answer": "The main product supplied by TShirtFactory is t-shirts, specifically blancs (white) and colorés (colored). As TShirtCo's primary supplier since 2020, it provides the base garments for personalization, ensuring a consistent production flow as of November 2025.",
"expected_answer": "T-shirts blancs & colorés"
},
{
"question": "What is the stock of green T-shirt with Motif2 in size S?",
"answer": "The stock of green T-shirts with Motif2 in size S is 50 units. This portion of the 190-unit total stock indicates popularity for this size, potentially requiring reordering if demand persists into late 2025.",
"expected_answer": "50"
},
{
"question": "What is the total payroll cost in 2024?",
"answer": "The total payroll cost in 2024 is 38,000 €. This covers salaries for all 8 employees, including John Doe's 5,500 €/month and Tom Lemoine's 800 €/month, reflecting a significant operational expense for the year.",
"expected_answer": "38 000 €"
},
{
"question": "What is the date of the financial report?",
"answer": "The date of the financial report is December 31, 2024. This marks the end of TShirtCo's fiscal year, providing a detailed overview of its 126,320 € in assets and 19,040 € net profit, crucial for 2025 planning.",
"expected_answer": "31/12/2024"
},
{
"question": "What is the total amount HT for CMD-2025-002?",
"answer": "The total amount HT for CMD-2025-002 is 2,090.00 €. This covers 100 blue T-shirts with Motif8 ordered by Entreprise TechWear on February 25, 2025, before VAT, indicating a significant bulk transaction.",
"expected_answer": "2090.00 €"
},
{
"question": "What is the grammage of a violet T-shirt with Motif1?",
"answer": "The grammage of a violet T-shirt with Motif1 is 184 g/m². This medium-weight fabric, paired with German cotton, offers durability and comfort, aligning with TShirtCo's quality standards as of November 2025.",
"expected_answer": "184 g/m²"
},
{
"question": "Based on the 2024 turnover and expenses, what might be the projected profit for 2025 if sales increase by 10%?",
"answer": "Based on a 2024 turnover of 185,400 € and expenses totaling 163,000 € (including 98,200 € purchases, 28,500 € charges, 38,000 € salaries), the 2024 profit was 22,400 € before tax. A 10% sales increase to 203,940 €, with expenses rising proportionally to 179,300 €, suggests a pre-tax profit of approximately 24,640 €, reduced by a 15% tax (3,696 €) to a net profit of about 20,944 € for 2025, assuming stable conditions.",
"expected_answer": "Approx. 20 944 €"
},
{
"question": "If CMD-2025-002 is delayed by one week, how might this affect the stock of blue T-shirts with Motif8?",
"answer": "A one-week delay in CMD-2025-002, originally planned for March 24, 2025, would shift production past the current date of November 13, 2025. With 160 units in stock and 100 ordered, the delay might reduce available stock to 60 units if demand outpaces production, potentially impacting customer satisfaction unless reordering is expedited.",
"expected_answer": "Reduces available stock to 60 units"
},
{
"question": "What should TShirtCo do if the cotton provenance for a new motif is unknown?",
"answer": "If the cotton provenance for a new motif is unknown, TShirtCo should halt production until verified, contact suppliers like CotonBio Europe for clarification, and conduct an audit to ensure ethical sourcing compliance. This proactive approach protects the brand's reputation and aligns with its ethical standards as of late 2025.",
"expected_answer": "Halt production, verify with suppliers, conduct audit"
},
{
"question": "What is the stock of a non-existent motif like Motif11?",
"answer": "Since Motif11 does not exist in TShirtCo's catalog as of November 13, 2025, the stock is 0. The model should recognize this as an error case and return a null or zero value, indicating no available data, rather than fabricating a response.",
"expected_answer": "0"
},
{
"question": "Calculate the average price of all red T-shirts listed.",
"answer": "The red T-shirts listed include prices of 18.5 € (Motif1), 21.5 € (Motif2), 21.6 € (Motif3), 21.4 € (Motif4), 18.5 € (Motif5), 21.5 € (Motif6), 19.8 € (Motif7), 20.1 € (Motif8), 20.1 € (Motif9), and 19.5 € (Motif10). Averaging these 10 prices (199.0 € total) yields approximately 19.9 €, reflecting a consistent pricing strategy as of late 2025.",
"expected_answer": "Approx. 19.9 €"
},
{
"question": "Is CMD-2025-005 deliverable by November 13, 2025, given the current production schedule?",
"answer": "CMD-2025-005, placed on March 28, 2025, with production scheduled for March 25-26, 2025, should be deliverable by now, November 13, 2025, assuming a standard 2-3 week shipping period. The status 'Planifiée' suggests it was on track, likely completed unless delays occurred.",
"expected_answer": "Yes"
},
{
"question": "What is the provenance of the cotton for the blue T-shirt with Motif10?",
"answer": "The provenance of the cotton for the blue T-shirt with Motif10 is Switzerland, labeled as 'Coton de Suisse.' This premium source enhances quality, supporting TShirtCo's ethical standards as of November 13, 2025.",
"expected_answer": "Coton de Suisse"
},
{
"question": "How many t-shirts were ordered in CMD-2025-001?",
"answer": "A total of 3 t-shirts were ordered in CMD-2025-001, placed by Sophie Leroy on January 12, 2025, including 2 gray T-shirts with Motif1 and 1 white T-shirt with Motif3, all successfully paid for as of late 2025.",
"expected_answer": "3"
},
{
"question": "What is the status of order CMD-2024-002?",
"answer": "The status of order CMD-2024-002 is 'Livrée' (Delivered). Placed by Lucas Martin on April 22, 2024, for 5 t-shirts, this order was fulfilled, contributing to TShirtCo's early sales success as recorded by November 2025.",
"expected_answer": "Livrée"
},
{
"question": "What is the total amount TTC for CMD-2024-004?",
"answer": "The total amount TTC for CMD-2024-004 is 1,146.00 €. This covers 50 yellow T-shirts with Motif3 ordered by Association EcoPrint on June 3, 2024, with 20% VAT on 955.00 € HT, reflecting a significant bulk purchase.",
"expected_answer": "1146.00 €"
},
{
"question": "What is the place of fabrication for the gray T-shirt with Motif10?",
"answer": "The gray T-shirt with Motif10 is fabricated in France. This local production ensures quality control and ethical standards, using French cotton, a practice consistent with TShirtCo's operations as of November 2025.",
"expected_answer": "France"
},
{
"question": "How many employees were hired in 2024?",
"answer": "Two employees were hired in 2024: Sarah Klein on November 12, 2023 (effective into 2024) and Tom Lemoine on September 1, 2024. This expansion reflects TShirtCo's growth as of November 13, 2025.",
"expected_answer": "2"
},
{
"question": "What is the total stock of black T-shirts with Motif1?",
"answer": "The total stock of black T-shirts with Motif1 is 141 units. This inventory, across sizes S, M, L, and XL, supports demand with Czech Republic cotton, managed effectively as of late 2025.",
"expected_answer": "141"
},
{
"question": "What is the grammage of a blue T-shirt with Motif2?",
"answer": "The grammage of a blue T-shirt with Motif2 is 181 g/m². This medium-weight fabric, with Belgian cotton, offers comfort and durability, aligning with TShirtCo's quality focus as of November 2025.",
"expected_answer": "181 g/m²"
},
{
"question": "What is the client email for CMD-2024-005?",
"answer": "The client email for CMD-2024-005 is paul.richard@yahoo.com. This personal email, linked to Paul Richard's order on July 18, 2024, facilitated a successful delivery as recorded by late 2025.",
"expected_answer": "paul.richard@yahoo.com"
},
{
"question": "What is the total amount TTC for CMD-2025-002?",
"answer": "The total amount TTC for CMD-2025-002 is 2,508.00 €. This includes 20% VAT on 2,090.00 € HT for 100 blue T-shirts with Motif8, ordered by Entreprise TechWear on February 25, 2025.",
"expected_answer": "2508.00 €"
},
{
"question": "What is the stock of orange T-shirt with Motif5 in size XL?",
"answer": "The stock of orange T-shirts with Motif5 in size XL is 8 units. This limited quantity, part of 120 total units, suggests high demand, potentially requiring a reorder as of November 13, 2025.",
"expected_answer": "8"
},
{
"question": "What is the provenance of the cotton for the yellow T-shirt with Motif9?",
"answer": "The provenance of the cotton for the yellow T-shirt with Motif9 is Norway, labeled as 'Coton de Norvège.' This premium source enhances quality, supporting TShirtCo's ethical reputation as of late 2025.",
"expected_answer": "Coton de Norvège"
},
{
"question": "How many t-shirts are in the reordering on 27/03/2025?",
"answer": "A total of 50 t-shirts are included in the reordering on March 27, 2025. These red T-shirts with Motif1, overseen by Claire Moreau, aim to replenish stock across all sizes, ensuring availability into late 2025.",
"expected_answer": "50"
},
{
"question": "What is the salary of Marc Duval?",
"answer": "The salary of Marc Duval, the Logisticien, is 2,400 € gross per month. This wage, set since April 1, 2023, reflects his role in managing inventory and shipping, including recent dispatches as of November 2025.",
"expected_answer": "2 400 €"
},
{
"question": "What is the total amount of taxes paid in 2024?",
"answer": "The total amount of taxes paid in 2024 is 3,360 €. This 15% corporate tax on the 22,400 € operating profit impacts the net profit of 19,040 €, a key financial detail for the year ending December 31, 2024.",
"expected_answer": "3 360 €"
},
{
"question": "What is the stock of white T-shirt with Motif7 in size XL?",
"answer": "The stock of white T-shirts with Motif7 in size XL is 9 units. This small portion of the 157-unit total suggests high demand, potentially necessitating a reorder to maintain stock levels as of late 2025.",
"expected_answer": "9"
},
{
"question": "What is the price of an orange T-shirt with Motif8 in size XL?",
"answer": "The price of an orange T-shirt with Motif8 in size XL is 20.8 €. This price accounts for additional material and Polish cotton, offering a premium yet affordable option in TShirtCo's catalog as of November 2025.",
"expected_answer": "20.8 €"
},
{
"question": "What is the status of the production on 24/03/2025?",
"answer": "The status of production on March 24, 2025, is 'En cours' (In progress). Ahmed Benali was working on 100 blue T-shirts with Motif8 for CMD-2025-002, a significant order, with completion likely by now, November 13, 2025.",
"expected_answer": "En cours"
},
{
"question": "What is the total amount HT for CMD-2025-005?",
"answer": "The total amount HT for CMD-2025-005 is 780.00 €. This covers 30 violet T-shirts with Motif7 and 20 orange T-shirts with Motif1, ordered by Collectif ArtVif on March 28, 2025, before VAT application.",
"expected_answer": "780.00 €"
},
{
"question": "What is the provenance of the cotton for the rose T-shirt with Motif1?",
"answer": "The provenance of the cotton for the rose T-shirt with Motif1 is Austria, labeled as 'Coton de Autriche.' This high-quality source enhances the t-shirt's texture, aligning with TShirtCo's ethical sourcing as of late 2025.",
"expected_answer": "Coton de Autriche"
},
{
"question": "How many t-shirts were ordered in CMD-2024-002?",
"answer": "A total of 5 t-shirts were ordered in CMD-2024-002. Placed by Lucas Martin on April 22, 2024, this included 3 green T-shirts with Motif2 and 2 white T-shirts with Motif7, all delivered successfully.",
"expected_answer": "5"
},
{
"question": "What is the contact person at Encres ÉcoPrint?",
"answer": "The contact person at Encres ÉcoPrint is M. Klein. This individual manages TShirtCo's supply of ecological screen-printing inks, a key relationship supporting sustainable production as of November 2025.",
"expected_answer": "M. Klein"
},
{
"question": "What is the IBAN for TShirtCo payments?",
"answer": "The IBAN for TShirtCo payments is FR76 1234 5678 9000 1234 5678 901. This account facilitates secure transactions, such as the payment for FAC-2025-042, and is critical for financial operations as of late 2025.",
"expected_answer": "FR76 1234 5678 9000 1234 5678 901"
},
{
"question": "What is the payment term with CotonBio Europe?",
"answer": "The payment term with CotonBio Europe is 45 days. This extended credit period aids TShirtCo's cash flow when purchasing cotton from Poland and Hungary, a practice supporting its ethical supply chain as of November 2025.",
"expected_answer": "45 jours"
},
{
"question": "What is the delivery deadline for invoice FAC-2025-042?",
"answer": "The delivery deadline for invoice FAC-2025-042 is 30 days net from March 14, 2025, meaning payment was due by April 13, 2025. This standard term was met by Léa Moreau, as the order is recorded as delivered by late 2025.",
"expected_answer": "30 days"
},
{
"question": "How many violet T-shirts with Motif7 were ordered in CMD-2025-005?",
"answer": "A total of 30 violet T-shirts with Motif7 were ordered in CMD-2025-005. Placed by Collectif ArtVif on March 28, 2025, this bulk order with a custom design is planned for production, reflecting TShirtCo's versatility.",
"expected_answer": "30"
},
{
"question": "What is the amount of debt to suppliers in 2024?",
"answer": "The amount of debt to suppliers in 2024 is 28,920 €. This liability, owed to partners like TShirtFactory, is managed as part of TShirtCo's cash flow strategy, recorded in the year-end balance of December 31, 2024.",
"expected_answer": "28 920 €"
},
{
"question": "What is the total asset value for TShirtCo in 2024?",
"answer": "The total asset value for TShirtCo in 2024 is 126,320 €. This includes 28,500 € in immobilizations, 42,300 € in stock, and 36,800 € in liquid assets, providing a comprehensive financial overview as of year-end.",
"expected_answer": "126 320 €"
},
{
"question": "What is the position of Sarah Klein?",
"answer": "Sarah Klein holds the position of Commerciale at TShirtCo. Since November 12, 2023, she manages sales and client relationships, earning 2,600 € plus primes, a role vital to the company's market expansion as of 2025.",
"expected_answer": "Commerciale"
},
{
"question": "What is the client name for invoice FAC-2025-042?",
"answer": "The client name for invoice FAC-2025-042 is Léa Moreau. Residing at 45 Avenue des Lilas, 69000 Lyon, she received this invoice on March 14, 2025, for a mix of t-shirts totaling 81.12 € TTC.",
"expected_answer": "Léa Moreau"
},
{
"question": "What is the stock of rose T-shirt with Motif9 in size XL?",
"answer": "The stock of rose T-shirts with Motif9 in size XL is 33 units. This portion of the 144-unit total, with Austrian cotton, indicates a well-distributed inventory, supporting demand as of November 13, 2025.",
"expected_answer": "33"
},
{
"question": "What is the date of the last order in the history?",
"answer": "The date of the last order in the history is March 28, 2025, for CMD-2025-005 by Collectif ArtVif. This recent order, including 30 violet T-shirts, is planned for production, active as of today.",
"expected_answer": "28/03/2025"
},
{
"question": "What is the salary of the graphic design intern?",
"answer": "The salary of the graphic design intern, Tom Lemoine, is 800 € gross per month. This stipend, effective since September 1, 2024, supports his training, aligning with TShirtCo's talent development as of late 2025.",
"expected_answer": "800 €"
},
{
"question": "What is the amount of bank funds in 2024?",
"answer": "The amount of bank funds in 2024 is 35,600 €. This liquid asset, part of the 126,320 € total assets, provides flexibility for operations and debt management as recorded on December 31, 2024.",
"expected_answer": "35 600 €"
},
{
"question": "What is the price of a white T-shirt with Motif3 in size M?",
"answer": "The price of a white T-shirt with Motif3 in size M is 19.3 €. This covers Spanish cotton and French manufacturing, offering a competitive rate for a quality, ethically produced item as of November 2025.",
"expected_answer": "19.3 €"
},
{
"question": "What is the status of order CMD-2025-004?",
"answer": "The status of order CMD-2025-004 is 'Livrée' (Delivered). Placed by Léa Moreau on March 14, 2025, and shipped by March 29, 2025, this order for 3 t-shirts was completed, recorded as of today.",
"expected_answer": "Livrée"
},
{
"question": "What is the total stock of yellow T-shirts across all motifs?",
"answer": "The total stock of yellow T-shirts across all motifs exceeds 1,000 units when aggregated, with examples like 95 for Motif3, 106 for Motif1, and 141 for Motif9, reflecting a diverse and robust inventory as of November 2025.",
"expected_answer": ">1000 (approximate)"
},
{
"question": "How many items are planned for production on 26/03/2025?",
"answer": "A total of 20 items are planned for production on March 26, 2025. These orange T-shirts with Motif1 for CMD-2025-005, overseen by Ahmed Benali, highlight TShirtCo's production capacity as scheduled.",
"expected_answer": "20"
},
{
"question": "What is the social security number of Léa Garnier?",
"answer": "The social security number of Léa Garnier is 2 98 09 75 321 098 76. Assigned since her hiring on September 3, 2022, this identifier supports payroll and benefits compliance as of November 2025.",
"expected_answer": "2 98 09 75 321 098 76"
},
{
"question": "If a supplier delays cotton delivery by 30 days, how might TShirtCo adjust production?",
"answer": "A 30-day delay in cotton delivery, affecting new orders beyond March 2025, might halt production of affected motifs. TShirtCo could prioritize existing stock (e.g., 148 red Motif1 units), expedite alternative suppliers like CotonBio Europe, or inform clients of delays, ensuring minimal disruption as of November 2025.",
"expected_answer": "Prioritize stock, expedite suppliers, inform clients"
},
{
"question": "What is the average grammage of all listed T-shirts?",
"answer": "The average grammage of all listed T-shirts, based on samples like 182 g/m² (blue Motif5), 181 g/m² (blue Motif2), and 190 g/m² (gray Motif5), approximates 182-184 g/m² across the 100 models. This reflects a consistent medium-weight fabric standard as of late 2025.",
"expected_answer": "Approx. 183 g/m²"
},
{
"question": "What is the total debt in 2024?",
"answer": "The total debt in 2024 is 38,920 €, comprising 28,920 € to suppliers, 8,000 € in social/fiscal debts, and a 2,000 € bank loan remainder, managed effectively in the year-end balance as of December 31, 2024.",
"expected_answer": "38 920 €"
},
{
"question": "How many employees are on full-time contracts?",
"answer": "There are 7 employees on full-time contracts at TShirtCo, including John Doe, Claire Moreau, and Ahmed Benali, ensuring a dedicated workforce as of November 13, 2025, with one intern and one apprentice part-time.",
"expected_answer": "7"
}
]

View File

@ -0,0 +1,25 @@
"Category","Item","Value"
"ACTIF","Matériel sérigraphie","18 000"
"ACTIF","Mobilier & informatique","10 500"
"ACTIF","Stocks (marchandises)","42 300"
"ACTIF","Créances clients","18 720"
"ACTIF","Banque","35 600"
"ACTIF","Caisse","1 200"
"ACTIF","TOTAL ACTIF","126 320"
"PASSIF","Capital social","50 000"
"PASSIF","Réserves","15 000"
"PASSIF","Résultat 2024 (bénéfice)","22 400"
"PASSIF","Dettes fournisseurs","28 920"
"PASSIF","Dettes sociales & fiscales","8 000"
"PASSIF","Emprunt bancaire (reste à payer)","2 000"
"PASSIF","TOTAL PASSIF","126 320"
"COMPTE DE RÉSULTAT","Chiffre d'affaires HT","185 400"
"COMPTE DE RÉSULTAT","Achats de marchandises","-98 200"
"COMPTE DE RÉSULTAT","Variation de stock","+5 100"
"COMPTE DE RÉSULTAT","Marge brute","92 300"
"COMPTE DE RÉSULTAT","Charges externes","-28 500"
"COMPTE DE RÉSULTAT","Salaires & charges sociales","-38 000"
"COMPTE DE RÉSULTAT","Dotations aux amortissements","-3 400"
"COMPTE DE RÉSULTAT","Résultat d'exploitation","22 400"
"COMPTE DE RÉSULTAT","Impôt sur les sociétés (15%)","-3 360"
"COMPTE DE RÉSULTAT","RÉSULTAT NET","19 040"
1 Category Item Value
2 ACTIF Matériel sérigraphie 18 000
3 ACTIF Mobilier & informatique 10 500
4 ACTIF Stocks (marchandises) 42 300
5 ACTIF Créances clients 18 720
6 ACTIF Banque 35 600
7 ACTIF Caisse 1 200
8 ACTIF TOTAL ACTIF 126 320
9 PASSIF Capital social 50 000
10 PASSIF Réserves 15 000
11 PASSIF Résultat 2024 (bénéfice) 22 400
12 PASSIF Dettes fournisseurs 28 920
13 PASSIF Dettes sociales & fiscales 8 000
14 PASSIF Emprunt bancaire (reste à payer) 2 000
15 PASSIF TOTAL PASSIF 126 320
16 COMPTE DE RÉSULTAT Chiffre d'affaires HT 185 400
17 COMPTE DE RÉSULTAT Achats de marchandises -98 200
18 COMPTE DE RÉSULTAT Variation de stock +5 100
19 COMPTE DE RÉSULTAT Marge brute 92 300
20 COMPTE DE RÉSULTAT Charges externes -28 500
21 COMPTE DE RÉSULTAT Salaires & charges sociales -38 000
22 COMPTE DE RÉSULTAT Dotations aux amortissements -3 400
23 COMPTE DE RÉSULTAT Résultat d'exploitation 22 400
24 COMPTE DE RÉSULTAT Impôt sur les sociétés (15%) -3 360
25 COMPTE DE RÉSULTAT RÉSULTAT NET 19 040

Binary file not shown.

Binary file not shown.

9
data/source/employes.csv Normal file
View File

@ -0,0 +1,9 @@
"Matricule","Nom Prénom","Poste","Date embauche","Contrat","Salaire brut mensuel (€)","Temps plein","N° Sécurité Sociale"
"EMP001","John Doe","Dirigeant","01/01/2020","CDI","5500","Oui","1 85 01 75 123 456 78"
"EMP002","Claire Moreau","Responsable production","15/02/2020","CDI","3200","Oui","2 92 03 75 987 654 32"
"EMP003","Ahmed Benali","Opérateur sérigraphie","10/06/2021","CDI","2100","Oui","1 97 06 13 456 789 01"
"EMP004","Léa Garnier","Graphiste","03/09/2022","CDI","2800","Oui","2 98 09 75 321 098 76"
"EMP005","Marc Duval","Logisticien","01/04/2023","CDI","2400","Oui","1 85 04 75 654 321 09"
"EMP006","Sarah Klein","Commerciale","12/11/2023","CDI","2600 + primes","Oui","2 93 11 75 123 456 78"
"EMP007","Tom Lemoine","Stagiaire graphisme","01/09/2024","Stage","800","Non","1 04 09 75 987 654 32"
"EMP008","Inès Ferreira","Apprentie logistique","01/09/2024","Apprent.","1200","Non","2 04 09 75 456 789 01"
1 Matricule Nom Prénom Poste Date embauche Contrat Salaire brut mensuel (€) Temps plein N° Sécurité Sociale
2 EMP001 John Doe Dirigeant 01/01/2020 CDI 5500 Oui 1 85 01 75 123 456 78
3 EMP002 Claire Moreau Responsable production 15/02/2020 CDI 3200 Oui 2 92 03 75 987 654 32
4 EMP003 Ahmed Benali Opérateur sérigraphie 10/06/2021 CDI 2100 Oui 1 97 06 13 456 789 01
5 EMP004 Léa Garnier Graphiste 03/09/2022 CDI 2800 Oui 2 98 09 75 321 098 76
6 EMP005 Marc Duval Logisticien 01/04/2023 CDI 2400 Oui 1 85 04 75 654 321 09
7 EMP006 Sarah Klein Commerciale 12/11/2023 CDI 2600 + primes Oui 2 93 11 75 123 456 78
8 EMP007 Tom Lemoine Stagiaire graphisme 01/09/2024 Stage 800 Non 1 04 09 75 987 654 32
9 EMP008 Inès Ferreira Apprentie logistique 01/09/2024 Apprent. 1200 Non 2 04 09 75 456 789 01

Binary file not shown.

View File

@ -0,0 +1,4 @@
"Nom","SIRET","Contact","Produits fournis","Délai paiement","Note"
"TShirtFactory","987 654 321 00056","M. Dupont","T-shirts blancs & colorés","30 jours","5/5"
"CotonBio Europe","456 789 123 00045","Mme Rossi","Coton bio (Pologne, Hongrie)","45 jours","4/5"
"Encres ÉcoPrint","321 098 765 00034","M. Klein","Encres sérigraphie écologiques","30 jours","5/5"
1 Nom SIRET Contact Produits fournis Délai paiement Note
2 TShirtFactory 987 654 321 00056 M. Dupont T-shirts blancs & colorés 30 jours 5/5
3 CotonBio Europe 456 789 123 00045 Mme Rossi Coton bio (Pologne, Hongrie) 45 jours 4/5
4 Encres ÉcoPrint 321 098 765 00034 M. Klein Encres sérigraphie écologiques 30 jours 5/5

Binary file not shown.

View File

@ -0,0 +1,19 @@
"Numéro de Commande","Date","Client","Email","Couleur","Motif","Taille","Quantité","Montant HT (€)","TVA (20%)","Montant TTC (€)","Statut"
"CMD-2024-001","15/03/2024","Marie Dupont","marie.dupont@gmail.com","Rouge","Motif1","M","2","58.50","11.70","70.20","Livrée"
"CMD-2024-001","15/03/2024","Marie Dupont","marie.dupont@gmail.com","Bleu","Motif5","L","1","58.50","11.70","70.20","Livrée"
"CMD-2024-002","22/04/2024","Lucas Martin","lucas.martin@orange.fr","Vert","Motif2","XL","3","80.10","16.02","96.12","Livrée"
"CMD-2024-002","22/04/2024","Lucas Martin","lucas.martin@orange.fr","Blanc","Motif7","S","2","80.10","16.02","96.12","Livrée"
"CMD-2024-003","10/05/2024","Emma Bernard","emma.b@free.fr","Noir","Motif10","L","1","79.20","15.84","95.04","En cours"
"CMD-2024-003","10/05/2024","Emma Bernard","emma.b@free.fr","Rose","Motif9","M","2","79.20","15.84","95.04","En cours"
"CMD-2024-004","03/06/2024","Association EcoPrint","contact@ecoprint.org","Jaune","Motif3","M","50 (personnalisé)","955.00","191.00","1146.00","Livrée"
"CMD-2024-005","18/07/2024","Paul Richard","paul.richard@yahoo.com","Orange","Motif5","XL","1","39.60","7.92","47.52","Livrée"
"CMD-2024-005","18/07/2024","Paul Richard","paul.richard@yahoo.com","Violet","Motif4","S","1","39.60","7.92","47.52","Livrée"
"CMD-2025-001","12/01/2025","Sophie Leroy","sophie.leroy@outlook.com","Gris","Motif1","L","2","58.10","11.62","69.72","Payée"
"CMD-2025-001","12/01/2025","Sophie Leroy","sophie.leroy@outlook.com","Blanc","Motif3","M","1","58.10","11.62","69.72","Payée"
"CMD-2025-002","25/02/2025","Entreprise TechWear","rh@techwear.fr","Bleu","Motif8","XL","100 (logo entreprise)","2090.00","418.00","2508.00","En préparation"
"CMD-2025-003","05/03/2025","Tom Durand","tom.durand@gmail.com","Rouge","Motif4","S","1","39.40","7.88","47.28","Annulée"
"CMD-2025-003","05/03/2025","Tom Durand","tom.durand@gmail.com","Vert","Motif10","M","1","39.40","7.88","47.28","Annulée"
"CMD-2025-004","14/03/2025","Léa Moreau","lea.moreau@wanadoo.fr","Rose","Motif6","L","2","59.60","11.92","71.52","Livrée"
"CMD-2025-004","14/03/2025","Léa Moreau","lea.moreau@wanadoo.fr","Jaune","Motif8","M","1","59.60","11.92","71.52","Livrée"
"CMD-2025-005","28/03/2025","Collectif ArtVif","artvif@asso.fr","Violet","Motif7","M","30","780.00","156.00","936.00","Planifiée"
"CMD-2025-005","28/03/2025","Collectif ArtVif","artvif@asso.fr","Orange","Motif1","L","20","780.00","156.00","936.00","Planifiée"
1 Numéro de Commande Date Client Email Couleur Motif Taille Quantité Montant HT (€) TVA (20%) Montant TTC (€) Statut
2 CMD-2024-001 15/03/2024 Marie Dupont marie.dupont@gmail.com Rouge Motif1 M 2 58.50 11.70 70.20 Livrée
3 CMD-2024-001 15/03/2024 Marie Dupont marie.dupont@gmail.com Bleu Motif5 L 1 58.50 11.70 70.20 Livrée
4 CMD-2024-002 22/04/2024 Lucas Martin lucas.martin@orange.fr Vert Motif2 XL 3 80.10 16.02 96.12 Livrée
5 CMD-2024-002 22/04/2024 Lucas Martin lucas.martin@orange.fr Blanc Motif7 S 2 80.10 16.02 96.12 Livrée
6 CMD-2024-003 10/05/2024 Emma Bernard emma.b@free.fr Noir Motif10 L 1 79.20 15.84 95.04 En cours
7 CMD-2024-003 10/05/2024 Emma Bernard emma.b@free.fr Rose Motif9 M 2 79.20 15.84 95.04 En cours
8 CMD-2024-004 03/06/2024 Association EcoPrint contact@ecoprint.org Jaune Motif3 M 50 (personnalisé) 955.00 191.00 1146.00 Livrée
9 CMD-2024-005 18/07/2024 Paul Richard paul.richard@yahoo.com Orange Motif5 XL 1 39.60 7.92 47.52 Livrée
10 CMD-2024-005 18/07/2024 Paul Richard paul.richard@yahoo.com Violet Motif4 S 1 39.60 7.92 47.52 Livrée
11 CMD-2025-001 12/01/2025 Sophie Leroy sophie.leroy@outlook.com Gris Motif1 L 2 58.10 11.62 69.72 Payée
12 CMD-2025-001 12/01/2025 Sophie Leroy sophie.leroy@outlook.com Blanc Motif3 M 1 58.10 11.62 69.72 Payée
13 CMD-2025-002 25/02/2025 Entreprise TechWear rh@techwear.fr Bleu Motif8 XL 100 (logo entreprise) 2090.00 418.00 2508.00 En préparation
14 CMD-2025-003 05/03/2025 Tom Durand tom.durand@gmail.com Rouge Motif4 S 1 39.40 7.88 47.28 Annulée
15 CMD-2025-003 05/03/2025 Tom Durand tom.durand@gmail.com Vert Motif10 M 1 39.40 7.88 47.28 Annulée
16 CMD-2025-004 14/03/2025 Léa Moreau lea.moreau@wanadoo.fr Rose Motif6 L 2 59.60 11.92 71.52 Livrée
17 CMD-2025-004 14/03/2025 Léa Moreau lea.moreau@wanadoo.fr Jaune Motif8 M 1 59.60 11.92 71.52 Livrée
18 CMD-2025-005 28/03/2025 Collectif ArtVif artvif@asso.fr Violet Motif7 M 30 780.00 156.00 936.00 Planifiée
19 CMD-2025-005 28/03/2025 Collectif ArtVif artvif@asso.fr Orange Motif1 L 20 780.00 156.00 936.00 Planifiée

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
"Date","Opérateur","Commande","Article","Motif personnalisé","Qté","Statut"
"24/03","Ahmed Benali","CMD-2025-002","Bleu","Motif8","100","En cours"
"25/03","Ahmed + Marc","CMD-2025-005","Violet","Motif7","30","Planifié"
"26/03","Ahmed Benali","CMD-2025-005","Orange","Motif1","20","Planifié"
"27/03","Claire Moreau","Stock","Rouge","Motif1","50","Validé"
"28/03","Ahmed + Léa","CMD-2025-001","Gris","Motif1","2","Terminé"
"29/03","Marc Duval","Expédition","CMD-2025-004","2 colis (Léa + Sophie)","-","Expédié"
1 Date Opérateur Commande Article Motif personnalisé Qté Statut
2 24/03 Ahmed Benali CMD-2025-002 Bleu Motif8 100 En cours
3 25/03 Ahmed + Marc CMD-2025-005 Violet Motif7 30 Planifié
4 26/03 Ahmed Benali CMD-2025-005 Orange Motif1 20 Planifié
5 27/03 Claire Moreau Stock Rouge Motif1 50 Validé
6 28/03 Ahmed + Léa CMD-2025-001 Gris Motif1 2 Terminé
7 29/03 Marc Duval Expédition CMD-2025-004 2 colis (Léa + Sophie) - Expédié

View File

@ -0,0 +1,101 @@
Couleur;Motif;Fabrique;Prix (€);Grammage (g/m²);Stock;Endroit de fabrication;Provenance des matériaux;Taille disponible
Rouge;Motif1;TShirtFactory;18.5;148;182;France;Coton de Pologne;S, M, L, XL
Rouge;Motif2;TShirtFactory;21.5;155;178;France;Coton de Hongrie;S, M, L, XL
Rouge;Motif3;TShirtFactory;21.6;74;190;France;Coton de Suisse;S, M, L, XL
Rouge;Motif4;TShirtFactory;21.4;161;176;France;Coton de Hongrie;S, M, L, XL
Rouge;Motif5;TShirtFactory;18.5;120;183;France;Coton de Suisse;S, M, L, XL
Rouge;Motif6;TShirtFactory;21.5;166;176;France;Coton de Autriche;S, M, L, XL
Rouge;Motif7;TShirtFactory;19.8;172;102;France;Coton de République tchèque;S, M, L, XL
Rouge;Motif8;TShirtFactory;20.1;91;179;France;Coton de Norvège;S, M, L, XL
Rouge;Motif9;TShirtFactory;20.1;191;172;France;Coton de Pologne;S, M, L, XL
Rouge;Motif10;TShirtFactory;19.5;103;185;France;Coton de Hongrie;S, M, L, XL
Bleu;Motif1;TShirtFactory;21.4;149;186;France;Coton de Autriche;S, M, L, XL
Bleu;Motif2;TShirtFactory;21.0;169;181;France;Coton de Belgique;S, M, L, XL
Bleu;Motif3;TShirtFactory;19.6;156;180;France;Coton de Espagne;S, M, L, XL
Bleu;Motif4;TShirtFactory;20.3;100;170;France;Coton de Portugal;S, M, L, XL
Bleu;Motif5;TShirtFactory;18.7;71;173;France;Coton de Hongrie;S, M, L, XL
Bleu;Motif6;TShirtFactory;20.0;72;179;France;Coton de Grèce;S, M, L, XL
Bleu;Motif7;TShirtFactory;18.2;66;177;France;Coton de Danemark;S, M, L, XL
Bleu;Motif8;TShirtFactory;20.9;160;186;France;Coton de Espagne;S, M, L, XL
Bleu;Motif9;TShirtFactory;20.7;177;145;France;Coton de République tchèque;S, M, L, XL
Bleu;Motif10;TShirtFactory;20.7;70;171;France;Coton de Suède;S, M, L, XL
Vert;Motif1;TShirtFactory;18.8;62;175;France;Coton de Pays-Bas;S, M, L, XL
Vert;Motif2;TShirtFactory;19.8;190;172;France;Coton de Suède;S, M, L, XL
Vert;Motif3;TShirtFactory;21.8;160;182;France;Coton de Autriche;S, M, L, XL
Vert;Motif4;TShirtFactory;20.6;181;181;France;Coton de France;S, M, L, XL
Vert;Motif5;TShirtFactory;20.6;162;175;France;Coton de Finlande;S, M, L, XL
Vert;Motif6;TShirtFactory;21.0;179;174;France;Coton de Italie;S, M, L, XL
Vert;Motif7;TShirtFactory;21.1;90;171;France;Coton de Hongrie;S, M, L, XL
Vert;Motif8;TShirtFactory;21.5;194;172;France;Coton de Pologne;S, M, L, XL
Vert;Motif9;TShirtFactory;18.8;166;173;France;Coton de Belgique;S, M, L, XL
Vert;Motif10;TShirtFactory;18.0;154;173;France;Coton de Hongrie;S, M, L, XL
Jaune;Motif1;TShirtFactory;20.9;106;187;France;Coton de Suède;S, M, L, XL
Jaune;Motif2;TShirtFactory;20.7;97;182;France;Coton de Grèce;S, M, L, XL
Jaune;Motif3;TShirtFactory;19.1;194;189;France;Coton de Allemagne;S, M, L, XL
Jaune;Motif4;TShirtFactory;20.2;136;173;France;Coton de Norvège;S, M, L, XL
Jaune;Motif5;TShirtFactory;19.2;169;171;France;Coton de Pays-Bas;S, M, L, XL
Jaune;Motif6;TShirtFactory;19.1;99;182;France;Coton de Pays-Bas;S, M, L, XL
Jaune;Motif7;TShirtFactory;19.6;98;181;France;Coton de Grèce;S, M, L, XL
Jaune;Motif8;TShirtFactory;20.0;146;188;France;Coton de Italie;S, M, L, XL
Jaune;Motif9;TShirtFactory;20.0;61;171;France;Coton de Allemagne;S, M, L, XL
Jaune;Motif10;TShirtFactory;21.6;76;172;France;Coton de Suisse;S, M, L, XL
Noir;Motif1;TShirtFactory;21.7;185;141;France;Coton de République tchèque;S, M, L, XL
Noir;Motif2;TShirtFactory;18.3;94;173;France;Coton de Suède;S, M, L, XL
Noir;Motif3;TShirtFactory;21.2;109;173;France;Coton de France;S, M, L, XL
Noir;Motif4;TShirtFactory;20.3;56;184;France;Coton de Suisse;S, M, L, XL
Noir;Motif5;TShirtFactory;19.6;196;187;France;Coton de Hongrie;S, M, L, XL
Noir;Motif6;TShirtFactory;19.3;62;184;France;Coton de Espagne;S, M, L, XL
Noir;Motif7;TShirtFactory;19.3;65;177;France;Coton de Pays-Bas;S, M, L, XL
Noir;Motif8;TShirtFactory;19.0;110;187;France;Coton de Pologne;S, M, L, XL
Noir;Motif9;TShirtFactory;18.5;80;177;France;Coton de Danemark;S, M, L, XL
Noir;Motif10;TShirtFactory;21.9;152;184;France;Coton de Suède;S, M, L, XL
Blanc;Motif1;TShirtFactory;18.4;99;183;France;Coton de Hongrie;S, M, L, XL
Blanc;Motif2;TShirtFactory;19.8;120;185;France;Coton de Finlande;S, M, L, XL
Blanc;Motif3;TShirtFactory;19.3;95;181;France;Coton de Espagne;S, M, L, XL
Blanc;Motif4;TShirtFactory;18.7;187;189;France;Coton de Portugal;S, M, L, XL
Blanc;Motif5;TShirtFactory;20.7;178;157;France;Coton de République tchèque;S, M, L, XL
Blanc;Motif6;TShirtFactory;21.4;119;185;France;Coton de Italie;S, M, L, XL
Blanc;Motif7;TShirtFactory;21.1;59;187;France;Coton de Autriche;S, M, L, XL
Blanc;Motif8;TShirtFactory;18.7;165;186;France;Coton de Suisse;S, M, L, XL
Blanc;Motif9;TShirtFactory;20.2;141;171;France;Coton de Suède;S, M, L, XL
Blanc;Motif10;TShirtFactory;18.3;136;186;France;Coton de Suisse;S, M, L, XL
Orange;Motif1;TShirtFactory;19.4;140;171;France;Coton de Suisse;S, M, L, XL
Orange;Motif2;TShirtFactory;18.1;189;186;France;Coton de Finlande;S, M, L, XL
Orange;Motif3;TShirtFactory;18.4;164;182;France;Coton de Danemark;S, M, L, XL
Orange;Motif4;TShirtFactory;19.5;72;181;France;Coton de Hongrie;S, M, L, XL
Orange;Motif5;TShirtFactory;21.3;105;177;France;Coton de France;S, M, L, XL
Orange;Motif6;TShirtFactory;18.8;186;184;France;Coton de Autriche;S, M, L, XL
Orange;Motif7;TShirtFactory;20.1;54;185;France;Coton de Suède;S, M, L, XL
Orange;Motif8;TShirtFactory;20.8;145;190;France;Coton de Pologne;S, M, L, XL
Orange;Motif9;TShirtFactory;19.3;141;187;France;Coton de Norvège;S, M, L, XL
Orange;Motif10;TShirtFactory;20.3;106;174;France;Coton de Pologne;S, M, L, XL
Violet;Motif1;TShirtFactory;18.6;138;184;France;Coton de Allemagne;S, M, L, XL
Violet;Motif2;TShirtFactory;20.0;150;183;France;Coton de Pologne;S, M, L, XL
Violet;Motif3;TShirtFactory;21.4;189;177;France;Coton de Pays-Bas;S, M, L, XL
Violet;Motif4;TShirtFactory;18.1;182;183;France;Coton de Finlande;S, M, L, XL
Violet;Motif5;TShirtFactory;18.5;134;184;France;Coton de Autriche;S, M, L, XL
Violet;Motif6;TShirtFactory;20.6;175;174;France;Coton de Danemark;S, M, L, XL
Violet;Motif7;TShirtFactory;18.4;183;187;France;Coton de Pologne;S, M, L, XL
Violet;Motif8;TShirtFactory;18.5;179;179;France;Coton de Allemagne;S, M, L, XL
Violet;Motif9;TShirtFactory;18.5;114;180;France;Coton de Belgique;S, M, L, XL
Violet;Motif10;TShirtFactory;18.0;114;175;France;Coton de Autriche;S, M, L, XL
Rose;Motif1;TShirtFactory;19.8;144;190;France;Coton de Autriche;S, M, L, XL
Rose;Motif2;TShirtFactory;18.8;59;179;France;Coton de Pays-Bas;S, M, L, XL
Rose;Motif3;TShirtFactory;21.4;110;174;France;Coton de Hongrie;S, M, L, XL
Rose;Motif4;TShirtFactory;19.7;59;176;France;Coton de Belgique;S, M, L, XL
Rose;Motif5;TShirtFactory;19.8;92;170;France;Coton de Autriche;S, M, L, XL
Rose;Motif6;TShirtFactory;19.6;67;177;France;Coton de Allemagne;S, M, L, XL
Rose;Motif7;TShirtFactory;20.6;89;173;France;Coton de Hongrie;S, M, L, XL
Rose;Motif8;TShirtFactory;21.8;132;190;France;Coton de Pologne;S, M, L, XL
Rose;Motif9;TShirtFactory;19.7;183;191;France;Coton de République tchèque;S, M, L, XL
Rose;Motif10;TShirtFactory;20.5;110;175;France;Coton de Suède;S, M, L, XL
Gris;Motif1;TShirtFactory;20.2;117;171;France;Coton de Danemark;S, M, L, XL
Gris;Motif2;TShirtFactory;21.6;146;171;France;Coton de Danemark;S, M, L, XL
Gris;Motif3;TShirtFactory;18.8;154;170;France;Coton de Hongrie;S, M, L, XL
Gris;Motif4;TShirtFactory;21.1;88;172;France;Coton de Allemagne;S, M, L, XL
Gris;Motif5;TShirtFactory;19.6;124;190;France;Coton de Hongrie;S, M, L, XL
Gris;Motif6;TShirtFactory;21.1;179;77;France;Coton de République tchèque;S, M, L, XL
Gris;Motif7;TShirtFactory;18.4;57;188;France;Coton de Italie;S, M, L, XL
Gris;Motif8;TShirtFactory;20.9;179;170;France;Coton de Allemagne;S, M, L, XL
Gris;Motif9;TShirtFactory;20.0;132;173;France;Coton de Espagne;S, M, L, XL
Gris;Motif10;TShirtFactory;19.5;72;177;France;Coton de Allemagne;S, M, L, XL
1 Couleur Motif Fabrique Prix (€) Grammage (g/m²) Stock Endroit de fabrication Provenance des matériaux Taille disponible
2 Rouge Motif1 TShirtFactory 18.5 148 182 France Coton de Pologne S, M, L, XL
3 Rouge Motif2 TShirtFactory 21.5 155 178 France Coton de Hongrie S, M, L, XL
4 Rouge Motif3 TShirtFactory 21.6 74 190 France Coton de Suisse S, M, L, XL
5 Rouge Motif4 TShirtFactory 21.4 161 176 France Coton de Hongrie S, M, L, XL
6 Rouge Motif5 TShirtFactory 18.5 120 183 France Coton de Suisse S, M, L, XL
7 Rouge Motif6 TShirtFactory 21.5 166 176 France Coton de Autriche S, M, L, XL
8 Rouge Motif7 TShirtFactory 19.8 172 102 France Coton de République tchèque S, M, L, XL
9 Rouge Motif8 TShirtFactory 20.1 91 179 France Coton de Norvège S, M, L, XL
10 Rouge Motif9 TShirtFactory 20.1 191 172 France Coton de Pologne S, M, L, XL
11 Rouge Motif10 TShirtFactory 19.5 103 185 France Coton de Hongrie S, M, L, XL
12 Bleu Motif1 TShirtFactory 21.4 149 186 France Coton de Autriche S, M, L, XL
13 Bleu Motif2 TShirtFactory 21.0 169 181 France Coton de Belgique S, M, L, XL
14 Bleu Motif3 TShirtFactory 19.6 156 180 France Coton de Espagne S, M, L, XL
15 Bleu Motif4 TShirtFactory 20.3 100 170 France Coton de Portugal S, M, L, XL
16 Bleu Motif5 TShirtFactory 18.7 71 173 France Coton de Hongrie S, M, L, XL
17 Bleu Motif6 TShirtFactory 20.0 72 179 France Coton de Grèce S, M, L, XL
18 Bleu Motif7 TShirtFactory 18.2 66 177 France Coton de Danemark S, M, L, XL
19 Bleu Motif8 TShirtFactory 20.9 160 186 France Coton de Espagne S, M, L, XL
20 Bleu Motif9 TShirtFactory 20.7 177 145 France Coton de République tchèque S, M, L, XL
21 Bleu Motif10 TShirtFactory 20.7 70 171 France Coton de Suède S, M, L, XL
22 Vert Motif1 TShirtFactory 18.8 62 175 France Coton de Pays-Bas S, M, L, XL
23 Vert Motif2 TShirtFactory 19.8 190 172 France Coton de Suède S, M, L, XL
24 Vert Motif3 TShirtFactory 21.8 160 182 France Coton de Autriche S, M, L, XL
25 Vert Motif4 TShirtFactory 20.6 181 181 France Coton de France S, M, L, XL
26 Vert Motif5 TShirtFactory 20.6 162 175 France Coton de Finlande S, M, L, XL
27 Vert Motif6 TShirtFactory 21.0 179 174 France Coton de Italie S, M, L, XL
28 Vert Motif7 TShirtFactory 21.1 90 171 France Coton de Hongrie S, M, L, XL
29 Vert Motif8 TShirtFactory 21.5 194 172 France Coton de Pologne S, M, L, XL
30 Vert Motif9 TShirtFactory 18.8 166 173 France Coton de Belgique S, M, L, XL
31 Vert Motif10 TShirtFactory 18.0 154 173 France Coton de Hongrie S, M, L, XL
32 Jaune Motif1 TShirtFactory 20.9 106 187 France Coton de Suède S, M, L, XL
33 Jaune Motif2 TShirtFactory 20.7 97 182 France Coton de Grèce S, M, L, XL
34 Jaune Motif3 TShirtFactory 19.1 194 189 France Coton de Allemagne S, M, L, XL
35 Jaune Motif4 TShirtFactory 20.2 136 173 France Coton de Norvège S, M, L, XL
36 Jaune Motif5 TShirtFactory 19.2 169 171 France Coton de Pays-Bas S, M, L, XL
37 Jaune Motif6 TShirtFactory 19.1 99 182 France Coton de Pays-Bas S, M, L, XL
38 Jaune Motif7 TShirtFactory 19.6 98 181 France Coton de Grèce S, M, L, XL
39 Jaune Motif8 TShirtFactory 20.0 146 188 France Coton de Italie S, M, L, XL
40 Jaune Motif9 TShirtFactory 20.0 61 171 France Coton de Allemagne S, M, L, XL
41 Jaune Motif10 TShirtFactory 21.6 76 172 France Coton de Suisse S, M, L, XL
42 Noir Motif1 TShirtFactory 21.7 185 141 France Coton de République tchèque S, M, L, XL
43 Noir Motif2 TShirtFactory 18.3 94 173 France Coton de Suède S, M, L, XL
44 Noir Motif3 TShirtFactory 21.2 109 173 France Coton de France S, M, L, XL
45 Noir Motif4 TShirtFactory 20.3 56 184 France Coton de Suisse S, M, L, XL
46 Noir Motif5 TShirtFactory 19.6 196 187 France Coton de Hongrie S, M, L, XL
47 Noir Motif6 TShirtFactory 19.3 62 184 France Coton de Espagne S, M, L, XL
48 Noir Motif7 TShirtFactory 19.3 65 177 France Coton de Pays-Bas S, M, L, XL
49 Noir Motif8 TShirtFactory 19.0 110 187 France Coton de Pologne S, M, L, XL
50 Noir Motif9 TShirtFactory 18.5 80 177 France Coton de Danemark S, M, L, XL
51 Noir Motif10 TShirtFactory 21.9 152 184 France Coton de Suède S, M, L, XL
52 Blanc Motif1 TShirtFactory 18.4 99 183 France Coton de Hongrie S, M, L, XL
53 Blanc Motif2 TShirtFactory 19.8 120 185 France Coton de Finlande S, M, L, XL
54 Blanc Motif3 TShirtFactory 19.3 95 181 France Coton de Espagne S, M, L, XL
55 Blanc Motif4 TShirtFactory 18.7 187 189 France Coton de Portugal S, M, L, XL
56 Blanc Motif5 TShirtFactory 20.7 178 157 France Coton de République tchèque S, M, L, XL
57 Blanc Motif6 TShirtFactory 21.4 119 185 France Coton de Italie S, M, L, XL
58 Blanc Motif7 TShirtFactory 21.1 59 187 France Coton de Autriche S, M, L, XL
59 Blanc Motif8 TShirtFactory 18.7 165 186 France Coton de Suisse S, M, L, XL
60 Blanc Motif9 TShirtFactory 20.2 141 171 France Coton de Suède S, M, L, XL
61 Blanc Motif10 TShirtFactory 18.3 136 186 France Coton de Suisse S, M, L, XL
62 Orange Motif1 TShirtFactory 19.4 140 171 France Coton de Suisse S, M, L, XL
63 Orange Motif2 TShirtFactory 18.1 189 186 France Coton de Finlande S, M, L, XL
64 Orange Motif3 TShirtFactory 18.4 164 182 France Coton de Danemark S, M, L, XL
65 Orange Motif4 TShirtFactory 19.5 72 181 France Coton de Hongrie S, M, L, XL
66 Orange Motif5 TShirtFactory 21.3 105 177 France Coton de France S, M, L, XL
67 Orange Motif6 TShirtFactory 18.8 186 184 France Coton de Autriche S, M, L, XL
68 Orange Motif7 TShirtFactory 20.1 54 185 France Coton de Suède S, M, L, XL
69 Orange Motif8 TShirtFactory 20.8 145 190 France Coton de Pologne S, M, L, XL
70 Orange Motif9 TShirtFactory 19.3 141 187 France Coton de Norvège S, M, L, XL
71 Orange Motif10 TShirtFactory 20.3 106 174 France Coton de Pologne S, M, L, XL
72 Violet Motif1 TShirtFactory 18.6 138 184 France Coton de Allemagne S, M, L, XL
73 Violet Motif2 TShirtFactory 20.0 150 183 France Coton de Pologne S, M, L, XL
74 Violet Motif3 TShirtFactory 21.4 189 177 France Coton de Pays-Bas S, M, L, XL
75 Violet Motif4 TShirtFactory 18.1 182 183 France Coton de Finlande S, M, L, XL
76 Violet Motif5 TShirtFactory 18.5 134 184 France Coton de Autriche S, M, L, XL
77 Violet Motif6 TShirtFactory 20.6 175 174 France Coton de Danemark S, M, L, XL
78 Violet Motif7 TShirtFactory 18.4 183 187 France Coton de Pologne S, M, L, XL
79 Violet Motif8 TShirtFactory 18.5 179 179 France Coton de Allemagne S, M, L, XL
80 Violet Motif9 TShirtFactory 18.5 114 180 France Coton de Belgique S, M, L, XL
81 Violet Motif10 TShirtFactory 18.0 114 175 France Coton de Autriche S, M, L, XL
82 Rose Motif1 TShirtFactory 19.8 144 190 France Coton de Autriche S, M, L, XL
83 Rose Motif2 TShirtFactory 18.8 59 179 France Coton de Pays-Bas S, M, L, XL
84 Rose Motif3 TShirtFactory 21.4 110 174 France Coton de Hongrie S, M, L, XL
85 Rose Motif4 TShirtFactory 19.7 59 176 France Coton de Belgique S, M, L, XL
86 Rose Motif5 TShirtFactory 19.8 92 170 France Coton de Autriche S, M, L, XL
87 Rose Motif6 TShirtFactory 19.6 67 177 France Coton de Allemagne S, M, L, XL
88 Rose Motif7 TShirtFactory 20.6 89 173 France Coton de Hongrie S, M, L, XL
89 Rose Motif8 TShirtFactory 21.8 132 190 France Coton de Pologne S, M, L, XL
90 Rose Motif9 TShirtFactory 19.7 183 191 France Coton de République tchèque S, M, L, XL
91 Rose Motif10 TShirtFactory 20.5 110 175 France Coton de Suède S, M, L, XL
92 Gris Motif1 TShirtFactory 20.2 117 171 France Coton de Danemark S, M, L, XL
93 Gris Motif2 TShirtFactory 21.6 146 171 France Coton de Danemark S, M, L, XL
94 Gris Motif3 TShirtFactory 18.8 154 170 France Coton de Hongrie S, M, L, XL
95 Gris Motif4 TShirtFactory 21.1 88 172 France Coton de Allemagne S, M, L, XL
96 Gris Motif5 TShirtFactory 19.6 124 190 France Coton de Hongrie S, M, L, XL
97 Gris Motif6 TShirtFactory 21.1 179 77 France Coton de République tchèque S, M, L, XL
98 Gris Motif7 TShirtFactory 18.4 57 188 France Coton de Italie S, M, L, XL
99 Gris Motif8 TShirtFactory 20.9 179 170 France Coton de Allemagne S, M, L, XL
100 Gris Motif9 TShirtFactory 20.0 132 173 France Coton de Espagne S, M, L, XL
101 Gris Motif10 TShirtFactory 19.5 72 177 France Coton de Allemagne S, M, L, XL

99
main.py

File diff suppressed because one or more lines are too long

BIN
pipeline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -13,4 +13,4 @@ pydantic>=2.0.0 # For data validation
lancedb==0.6.13
docling==2.31.0
cohere==5.15.0
requests>=2.31.0

98
src/RAG_pipeline.py Normal file
View File

@ -0,0 +1,98 @@
from typing import List, Optional, Dict
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from .interface.base_datastore import BaseDatastore
from .interface.base_evaluator import BaseEvaluator, EvaluationResult
from .interface.base_indexer import BaseIndexer
from .interface.base_response_generator import BaseResponseGenerator
from .interface.base_retriever import BaseRetriever
@dataclass
class RAGpipeline:
indexer: BaseIndexer
datastore: BaseDatastore
retriever: BaseRetriever
response_generator: BaseResponseGenerator
evaluator: Optional[BaseEvaluator] = None
def reset(self) -> None:
print("🗑️ Resetting the database...")
self.datastore.reset_table()
return
def add_documents(self, documents_path : List[str]) -> None:
items = self.indexer.index(documents_path)
print(f"🔍 Adding documents: {documents_path}")
self.datastore.add_items(items= items)
return
def evaluate(self, sample_questions: List[Dict[str, str]]) -> List[EvaluationResult]:
"""A compléter lors de l'ajout de l'évaluateur
"""
questions = [ item["question"] for item in sample_questions]
expected_answers = [ item["answer"] for item in sample_questions]
with ThreadPoolExecutor(max_workers=5) as executor:
results: List[EvaluationResult] = list(
executor.map(
self.evaluate_single_question,
questions,
expected_answers,
)
)
for i, result in enumerate(results):
result_emoji = "" if result.is_correct else ""
print(f"{result_emoji} Q {i+1}: {result.question}: \n")
print(f"Response: {result.response}\n")
print(f"Expected Answer: {result.expected_answer}\n")
print(f"Reasoning: {result.reasoning}\n")
print("--------------------------------")
number_correct= sum(result.is_correct for result in results)
print(f"✨ Total Score: {number_correct}/{len(results)}")
return results
def evaluate_single_question(self, question: str, expected_answer: str):
"""Appelle le générateur de réponse sur la question pour comparer le résultat avec
la réponse attendue.
Args:
question (str): Question de l'évaluateur, à poser au modèle
expected_answer (str): Réponse de l'évaluateur
"""
model_response = self.process_query(query=question)
return self.evaluator.evaluate(query= question, response= model_response, expected_answer= expected_answer)
def run(self, documents_path: List[str], arg2 = None) -> None:
self.reset()
self.add_documents(documents_path =documents_path)
if arg2 :
self.evaluate(arg2)
return
def process_query(self, query: str, top_k: int = 5, source: bool = False) -> str:
"""Génère la réponse à la requête à partir du contexte récupéré.
Affiche éventuellement les sources.
Args:
query (str): Requête
top_k (int, optional): Nombre de documents à renvoyer. Defaults to 5.
source (bool, optional): Afficher ou non les sources. Default to false
Returns:
str: Réponse générée
"""
print(f"[DEBUG] Traitement de la requête: {query}")
context = self.retriever.search_retriever(query, top_k= top_k)
if( source):
for i, doc in enumerate(context):
print(f"Based on the document {i+1}: {doc} \n")
response = self.response_generator.generate_response(query= query, context= context)
#print(f"Reponse: {response}")
return response

View File

@ -1,12 +1,27 @@
from ..interface.base_evaluator import EvaluationResult, BaseEvaluator
import requests
from dotenv import load_dotenv
from groq import Groq
from typing import Optional
import os
import re
class Evaluator(BaseEvaluator):
def __init__(self, model_name: str = "llama3.2:3b", base_url: str = "http://localhost:11434"):
self.base_url = base_url
self.model_name = model_name
def __init__(self, api_key: Optional[str] = None):
try :
load_dotenv()
self.api_key = api_key or os.getenv("GROQ_API_KEY")
print("Clé API récupérée avec succès \n")
except Exception as e:
raise ValueError(f"erreur avec la clé API: {e}")
try:
self.client = Groq(api_key=self.api_key)
self.model = "llama-3.1-8b-instant" # Rapide et gratuit
print("✅ Générateur Groq initialisé avec succès")
except Exception as e:
raise ValueError(f"❌ Erreur lors de l'initialisation de Groq: {e}")
SYSTEM_PROMPT = """
You are a system that evaluates the correctness of a response to a question.
@ -23,23 +38,63 @@ Then return the result in <result>...</result> tags — either as 'true' or 'fal
def evaluate(self, query: str, response: str, expected_answer: str) -> EvaluationResult:
user_prompt = f"""
<questions> \n{query} </question>
<question> \n{query} </question>
<response> \n{response} </response>
<expected_answer> \n{expected_answer} </expected_answer>
"""
response_content = requests.post(
f"{self.base_url}/api/generate",
json={
"model": self.model_name,
"prompt": user_prompt,
"stream": False,
"options": {
"temperature": 0.7,
"top_p": 0.9,
}
}
return super().evaluate(query, response, expected_answer)
try:
chat_completion = self.client.chat.completions.create(
messages = [
{
"role": "system",
"content": self.SYSTEM_PROMPT
},
{
"role": "user",
"content": user_prompt
}
],
model=self.model,
temperature=0.3,
max_tokens=1000,
)
response_text = chat_completion.choices[0].message.content
reasoning_match = re.search(r'<reasoning>(.*?)</reasoning>', response_text, re.DOTALL)
result_match = re.search(r'<result>(.*?)</result>', response_text, re.DOTALL)
reasoning = reasoning_match.group(1).strip() if reasoning_match else "Pas de raisonnement fourni"
result_str = result_match.group(1).strip().lower() if result_match else "false"
is_correct = result_str == "true"
return EvaluationResult(
question=query,
response= response,
expected_answer=expected_answer,
is_correct= is_correct,
reasoning= reasoning
)
except Exception as e:
error_msg = str(e).lower()
# Gestion des erreurs spécifiques
if "rate" in error_msg or "limit" in error_msg:
error_text = "⚠️ Limite de requêtes atteinte. Attendez et réessayez."
elif "authentication" in error_msg or "api" in error_msg or "401" in error_msg:
error_text = "❌ Erreur d'authentification. Vérifiez votre clé API dans le fichier .env"
else:
error_text = f"❌ Erreur lors de l'évaluation: {str(e)}"
return EvaluationResult(
question=query,
response= response,
expected_answer=expected_answer,
is_correct=False,
reasoning=error_text
)

View File

@ -1,7 +1,8 @@
from typing import List
from typing import List, Optional
from ..interface.base_response_generator import BaseResponseGenerator
import requests
import json
from groq import Groq
import os
from dotenv import load_dotenv
SYSTEM_PROMPT = """Tu es un assistant intelligent qui répond aux questions en te basant sur le contexte fourni.
@ -14,13 +15,34 @@ Règles importantes:
class ResponseGenerator(BaseResponseGenerator):
def __init__(self, model_name: str = "llama3.2:3b", base_url: str = "http://localhost:11434"):
self.model_name = model_name
self.base_url = base_url
def __init__(self, api_key: Optional[str] = None):
try :
load_dotenv()
self.api_key = api_key or os.getenv("GROQ_API_KEY")
print("Clé API récupérée avec succès \n")
except Exception as e:
raise ValueError(f"erreur avec la clé API: {e}")
def generate_response(self, query: str, context: List[str]) -> str:
"""Génère une réponse basée sur la requête et le contexte."""
try:
self.client = Groq(api_key=self.api_key)
self.model = "llama-3.1-8b-instant" # Rapide et gratuit
print("✅ Générateur Groq initialisé avec succès")
except Exception as e:
raise ValueError(f"❌ Erreur lors de l'initialisation de Groq: {e}")
def generate_response(self, query: str, context: List[str], max_tokens: int = 512) -> str:
"""
Génère une réponse basée sur la requête et le contexte.
Args:
query: Question de l'utilisateur
context: Liste de documents pertinents
max_tokens: Longueur maximale de la réponse
Returns:
Réponse générée
"""
# Formater le contexte
formatted_context = "\n\n".join([f"Document {i+1}:\n{doc}" for i, doc in enumerate(context)])
@ -36,48 +58,31 @@ class ResponseGenerator(BaseResponseGenerator):
# Appeler Ollama via l'API
try:
response = requests.post(
f"{self.base_url}/api/generate",
json={
"model": self.model_name,
"prompt": prompt,
"stream": False,
"options": {
"temperature": 0.7,
"top_p": 0.9,
}
}
response = self.client.chat.completions.create(
model=self.model,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": prompt}
],
temperature=0.7,
max_tokens=max_tokens,
)
# Vérifier le statut de la réponse
response.raise_for_status()
# Parser le JSON
result = response.json()
answer = response.choices[0].message.content.strip()
# DEBUG: Afficher la structure de la réponse
print(f"DEBUG - Structure de la réponse: {result.keys()}")
if not answer:
return "⚠️ Le modèle n'a pas pu générer de réponse."
# Vérifier les différentes clés possibles
if "response" in result:
return result["response"]
elif "message" in result:
return result["message"]
elif "content" in result:
return result["content"]
else:
# Si aucune clé attendue n'est trouvée
print(f"DEBUG - Réponse complète: {result}")
return f"Erreur: Format de réponse inattendu. Clés disponibles: {list(result.keys())}"
except requests.exceptions.ConnectionError:
return "❌ Impossible de se connecter au serveur Ollama. Vérifiez qu'Ollama est en cours d'exécution avec: ollama serve"
except requests.exceptions.Timeout:
return "⚠️ La génération a pris trop de temps. Essayez avec un modèle plus petit."
except requests.exceptions.HTTPError as e:
return f"❌ Erreur HTTP {response.status_code}: {e}"
return answer
except Exception as e:
return f"❌ Erreur lors de la génération: {str(e)}"
error_msg = str(e).lower()
# Erreurs spécifiques
if "rate" in error_msg or "limit" in error_msg:
return "⚠️ Limite de requêtes atteinte. Attendez 1 minute et réessayez."
elif "authentication" in error_msg or "api" in error_msg:
return "❌ Erreur d'authentification. Vérifiez votre clé API dans le fichier .env"
else:
return f"❌ Erreur lors de la génération: {str(e)}"

View File

@ -1,7 +1,7 @@
from abc import ABC,abstractmethod
from typing import List
from pydantic import BaseModel
from lancedb.table import Table
class DataItem(BaseModel):
content: str = ""
@ -9,6 +9,10 @@ class DataItem(BaseModel):
class BaseDatastore(ABC):
@abstractmethod
def reset_table(self) -> Table:
pass
@abstractmethod
def add_items(self, items: List[DataItem]) -> None:
pass