From 6c182d1815d1a308dd7c2d4111aa37401cb9a673 Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Tue, 16 Jun 2026 09:17:57 +0200 Subject: [PATCH] WIP --- agent/Dockerfile | 32 ++++++++++++++++++ agent/agent_gsd.py | 73 ++++++++++++++++++++++++++++++++++++++++++ agent/compose.yml | 42 ++++++++++++++++++++++++ agent/local-ai.bash | 35 ++++++++++++++++++++ agent/requirements.txt | 7 ++++ chat-ai/Dockerfile | 5 ++- chat-ai/compose.yml | 2 +- 7 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 agent/Dockerfile create mode 100644 agent/agent_gsd.py create mode 100644 agent/compose.yml create mode 100644 agent/local-ai.bash create mode 100644 agent/requirements.txt diff --git a/agent/Dockerfile b/agent/Dockerfile new file mode 100644 index 0000000..102cc22 --- /dev/null +++ b/agent/Dockerfile @@ -0,0 +1,32 @@ +# Base : Ubuntu avec ROCm 6.0 +FROM rocm/rocm-terminal:6.0 + +# Installer les dépendances pour llama.cpp +RUN apt-get update && apt-get install -y \ + cmake \ + git \ + python3 \ + python3-pip \ + python3-venv \ + && rm -rf /var/lib/apt/lists/* + +# Installer llama.cpp avec support ROCm +RUN git clone https://github.com/ggerganov/llama.cpp /llama.cpp \ + && cd /llama.cpp \ + && git pull \ + && cmake -DLLAMA_HIPBLAS=ON . \ # Active le support ROCm + && make -j$(nproc) + +# Créer un environnement Python +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" +COPY requirements.txt /tmp/ +RUN pip install --no-cache-dir -r /tmp/requirements.txt + +# Copier les scripts et le modèle +COPY scripts/ /app/ +COPY config/model.gguf /models/ +WORKDIR /app + +# Point d'entrée +CMD ["python", "agent_gsd.py"] \ No newline at end of file diff --git a/agent/agent_gsd.py b/agent/agent_gsd.py new file mode 100644 index 0000000..8efe319 --- /dev/null +++ b/agent/agent_gsd.py @@ -0,0 +1,73 @@ +from langchain_community.llms import LlamaCpp +from langchain_core.prompts import ChatPromptTemplate +from crewai import Agent, Task, Crew +import os + +# 1. Charger le modèle avec ROCm (GPU) + CPU +llm = LlamaCpp( + model_path="/models/model.gguf", + n_ctx=4096, # Contexte étendu pour le code + n_gpu_layers=32, # Utilise le GPU pour 32 couches (ajuste selon ta RAM) + n_threads=8, # Utilise 8 threads CPU pour le reste + temperature=0.1, + verbose=True, +) + +# 2. Définir l'agent GSD +code_agent = Agent( + role="Senior Full-Stack Developer", + goal="Développer des fonctionnalités complètes (backend + frontend + DB) en Rust, TypeScript, Kotlin, SQL", + backstory="Tu es un expert en Rust (Actix), TypeScript (Angular), Kotlin (Spring Boot), et SQL (PostgreSQL). " + "Tu utilises la méthodologie GSD : tu décomposes les tâches, génères du code propre, et valides chaque étape.", + tools=[], # On ajoutera des outils plus tard + llm=llm, + verbose=True, +) + +# 3. Prompt personnalisé pour le mode GSD +gsd_prompt = """ +Tu es en mode **Get Shit Done (GSD)**. Voici comment procéder : +1. **Analyse** : Décompose la demande en sous-tâches claires (ex: backend, frontend, DB). +2. **Génération** : Pour chaque sous-tâche, génère le code **complet et fonctionnel** dans le langage demandé. +3. **Validation** : Vérifie que le code est compilable/lintable. Si non, corrige-le. +4. **Retour** : Fournis le code final + des instructions pour l'intégrer. + +**Exemple de demande** : +"J'aimerai rendre configurable la durée de validité des tokens JWT dans mon backend Rust + frontend Angular." + +**Ta réponse doit inclure** : +- [ ] Code Rust (Actix) pour modifier la configuration JWT. +- [ ] Schéma SQL pour stocker la configuration en DB. +- [ ] Endpoint HTTP pour modifier la configuration. +- [ ] Code TypeScript (Angular) pour le formulaire. +- [ ] Instructions pour tester chaque partie. + +**Contraintes** : +- Utilise **Actix-Web** pour Rust. +- Utilise **Angular Material** pour le frontend. +- Pour Kotlin, utilise **Spring Boot 3 + JPA**. +- Pour SQL, utilise **PostgreSQL**. + +**Demande actuelle** : {user_request} +""" + +# 4. Exécuter une tâche GSD +def run_gsd_task(user_request: str): + task = Task( + description=gsd_prompt.format(user_request=user_request), + agent=code_agent, + expected_output="Code complet et fonctionnel pour chaque sous-tâche, avec instructions d'intégration.", + ) + crew = Crew(agents=[code_agent], tasks=[task], verbose=2) + result = crew.kickoff() + return result + +if __name__ == "__main__": + print("Agent GSD démarré. Tape 'quit' pour arrêter.") + while True: + user_request = input("\n> ") + if user_request.lower() == "quit": + break + result = run_gsd_task(user_request) + print("\n--- Résultat ---\n") + print(result) \ No newline at end of file diff --git a/agent/compose.yml b/agent/compose.yml new file mode 100644 index 0000000..4363647 --- /dev/null +++ b/agent/compose.yml @@ -0,0 +1,42 @@ +name: mistral-local + +services: + local-agent: + build: + context: . + dockerfile: Dockerfile + image: local-agent + container_name: local-agent + networks: + - mistral-net + ports: + - "127.0.0.1:8080:8080" + # Limites de ressources + deploy: + resources: + limits: + memory: 12g + cpus: "8" + # Sécurité + read_only: true + security_opt: + - no-new-privileges:true + tmpfs: + - /tmp:size=256m + devices: + - /dev/dri:/dev/dri + group_add: + - video + environment: + - GGML_VK_VISIBLE_DEVICES=0 + volumes: + - ../ai-models/mistral-7b-instruct.gguf:/home/llama/models/mistral-7b-instruct.gguf:ro + - ../workspace:/home/llama/workspace + +networks: + local-agent-net: + name: local-agent-net + driver: bridge + internal: false # pas de passerelle vers Internet + driver_opts: + com.docker.network.bridge.name: br-local-agent \ No newline at end of file diff --git a/agent/local-ai.bash b/agent/local-ai.bash new file mode 100644 index 0000000..13a2258 --- /dev/null +++ b/agent/local-ai.bash @@ -0,0 +1,35 @@ +#!/bin/bash + +action=$1 +args=$2 + +build_image() { + docker build $args -t local-agent . +} + +start_container() { + # Premier démarrage (build + lancement) + docker compose up --build + + # Voir les logs en temps réel + docker compose logs -f + + # Arrêter + docker compose down + + # Vérifier l'état du health check + docker compose ps +} + +main() { + if [[ $action = 'build' ]] then + build_image + elif [[ $action = 'all' ]] then + build_image + start_container + else + start_container + fi +} + +main \ No newline at end of file diff --git a/agent/requirements.txt b/agent/requirements.txt new file mode 100644 index 0000000..5903174 --- /dev/null +++ b/agent/requirements.txt @@ -0,0 +1,7 @@ +langchain==0.2.0 +langchain-community==0.2.0 +crewai==0.1.0 # Pour la méthodologie GSD +sqlmodel==0.0.16 +pydantic==2.6.0 +black==24.2.0 # Pour formater le code généré +ruff==0.3.0 # Linter \ No newline at end of file diff --git a/chat-ai/Dockerfile b/chat-ai/Dockerfile index 04ce05c..95397da 100644 --- a/chat-ai/Dockerfile +++ b/chat-ai/Dockerfile @@ -64,8 +64,7 @@ RUN mkdir -p /home/llama/models EXPOSE 8080 CMD ["llama-server", \ - "--model", "/home/llama/models/mistral-7b-instruct.gguf", \ + "--model", "/home/llama/models/Codestral-22B-v0.1-Q4_K_M.gguf", \ "--host", "0.0.0.0", \ "--port", "8080", \ - "-c", "4096", \ - "-ngl", "33"] \ No newline at end of file + "-c", "4096"] \ No newline at end of file diff --git a/chat-ai/compose.yml b/chat-ai/compose.yml index 2842ac1..36d5d4a 100644 --- a/chat-ai/compose.yml +++ b/chat-ai/compose.yml @@ -30,7 +30,7 @@ services: environment: - GGML_VK_VISIBLE_DEVICES=0 volumes: - - ../ai-models/mistral-7b-instruct.gguf:/home/llama/models/mistral-7b-instruct.gguf:ro + - ../ai-models:/home/llama/models:ro - ../workspace:/home/llama/workspace # Health check — vérifie que le serveur répond