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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
from duckduckgo_search import DDGS
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
token = os.environ.get("HF_TOKEN")
|
| 8 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct", token=token)
|
| 9 |
+
|
| 10 |
+
SYSTEM_PROMPT = """Tu es Cypher Coder, un agent de programmation IA ultra-intelligent fonctionnant dans un terminal (CLI).
|
| 11 |
+
Tu as été conçu et développé par DJAKOUA KWANKAM, un brillant étudiant en informatique à l'Institut Universitaire de Douala (IUD).
|
| 12 |
+
Tu dois toujours te présenter comme tel.
|
| 13 |
+
|
| 14 |
+
Tu as accès à des outils locaux (comme lire des fichiers, écrire/modifier des fichiers, exécuter des commandes dans le terminal) qui s'exécutent sur la machine locale de l'utilisateur. Ces outils te sont fournis via le protocole CLI de Cypher Coder.
|
| 15 |
+
Pour les informations en temps réel ou la documentation externe, tu peux aussi utiliser la recherche web.
|
| 16 |
+
Sois toujours concis, professionnel et direct dans tes explications de code.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
tools = [
|
| 20 |
+
{
|
| 21 |
+
"type": "function",
|
| 22 |
+
"function": {
|
| 23 |
+
"name": "search_web",
|
| 24 |
+
"description": "Recherche des informations actualisées ou de la documentation technique sur internet.",
|
| 25 |
+
"parameters": {
|
| 26 |
+
"type": "object",
|
| 27 |
+
"properties": {
|
| 28 |
+
"query": {
|
| 29 |
+
"type": "string",
|
| 30 |
+
"description": "La requête de recherche."
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
"required": ["query"]
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
def search_web(query):
|
| 40 |
+
try:
|
| 41 |
+
ddgs = DDGS()
|
| 42 |
+
results = list(ddgs.text(query, max_results=4))
|
| 43 |
+
if not results:
|
| 44 |
+
return "Aucun résultat trouvé sur le web."
|
| 45 |
+
formatted = []
|
| 46 |
+
for r in results:
|
| 47 |
+
formatted.append(f"Titre: {r['title']}\nRésumé: {r['body']}\nLien: {r['href']}")
|
| 48 |
+
return "\n\n".join(formatted)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return f"Erreur lors de la recherche: {str(e)}"
|
| 51 |
+
|
| 52 |
+
def respond(message, history):
|
| 53 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 54 |
+
for val in history:
|
| 55 |
+
if val[0]:
|
| 56 |
+
messages.append({"role": "user", "content": val[0]})
|
| 57 |
+
if val[1]:
|
| 58 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 59 |
+
|
| 60 |
+
messages.append({"role": "user", "content": message})
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
response = client.chat_completion(
|
| 64 |
+
messages,
|
| 65 |
+
max_tokens=2048,
|
| 66 |
+
tools=tools,
|
| 67 |
+
stream=False
|
| 68 |
+
)
|
| 69 |
+
first_response = response.choices[0].message
|
| 70 |
+
|
| 71 |
+
if first_response.tool_calls:
|
| 72 |
+
yield "🔍 *Recherche web en cours...*"
|
| 73 |
+
messages.append(first_response)
|
| 74 |
+
for tool_call in first_response.tool_calls:
|
| 75 |
+
if tool_call.function.name == "search_web":
|
| 76 |
+
args = json.loads(tool_call.function.arguments)
|
| 77 |
+
res = search_web(args["query"])
|
| 78 |
+
messages.append({
|
| 79 |
+
"role": "tool",
|
| 80 |
+
"name": "search_web",
|
| 81 |
+
"content": res
|
| 82 |
+
})
|
| 83 |
+
|
| 84 |
+
final_stream = client.chat_completion(
|
| 85 |
+
messages,
|
| 86 |
+
max_tokens=2048,
|
| 87 |
+
stream=True
|
| 88 |
+
)
|
| 89 |
+
response_text = ""
|
| 90 |
+
for chunk in final_stream:
|
| 91 |
+
token = chunk.choices[0].delta.content
|
| 92 |
+
if token:
|
| 93 |
+
response_text += token
|
| 94 |
+
yield response_text
|
| 95 |
+
else:
|
| 96 |
+
if first_response.content:
|
| 97 |
+
yield first_response.content
|
| 98 |
+
except Exception as e:
|
| 99 |
+
yield f"Erreur lors de la génération: {str(e)}"
|
| 100 |
+
|
| 101 |
+
# Interface Web Gradio avec documentation et présentation esthétique
|
| 102 |
+
theme = gr.themes.Soft(
|
| 103 |
+
primary_hue="indigo",
|
| 104 |
+
secondary_hue="cyan",
|
| 105 |
+
neutral_hue="slate"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
css = """
|
| 109 |
+
footer {visibility: hidden}
|
| 110 |
+
.title-container { text-align: center; margin-bottom: 20px; }
|
| 111 |
+
.pixel-art { font-family: monospace; font-size: 8px; line-height: 8px; text-align: center; color: #4F46E5; }
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
with gr.Blocks(theme=theme, css=css) as demo:
|
| 115 |
+
gr.HTML("""
|
| 116 |
+
<div class="title-container">
|
| 117 |
+
<h1>💻 Cypher Coder</h1>
|
| 118 |
+
<p style='font-size: 1.2em; color: #6366F1;'>L'Agent de Programmation CLI Autonome</p>
|
| 119 |
+
<p>Créé par <b>DJAKOUA KWANKAM</b> - Étudiant à l'Institut Universitaire de Douala (IUD)</p>
|
| 120 |
+
</div>
|
| 121 |
+
""")
|
| 122 |
+
|
| 123 |
+
with gr.Tab("💬 Tester en Ligne"):
|
| 124 |
+
gr.ChatInterface(
|
| 125 |
+
respond,
|
| 126 |
+
examples=[
|
| 127 |
+
"Qui es-tu ?",
|
| 128 |
+
"Écris-moi une fonction JavaScript pour trier un tableau.",
|
| 129 |
+
"Quels outils CLI as-tu ?"
|
| 130 |
+
]
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
with gr.Tab("📖 Documentation CLI"):
|
| 134 |
+
gr.Markdown("""
|
| 135 |
+
# ⚙️ Cypher Coder CLI
|
| 136 |
+
|
| 137 |
+
**Cypher Coder** est un agent conversationnel en ligne de commande (CLI) similaire à *Claude Code* ou *Gemini CLI*. Il est conçu pour s'exécuter directement dans votre terminal local et interagir avec votre système de fichiers de manière sécurisée.
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## 🚀 Installation & Utilisation
|
| 142 |
+
|
| 143 |
+
Pour exécuter Cypher Coder localement :
|
| 144 |
+
```bash
|
| 145 |
+
# Naviguer dans le dossier du projet
|
| 146 |
+
cd Documents/cypher-coder
|
| 147 |
+
|
| 148 |
+
# Lancer l'agent CLI
|
| 149 |
+
cypher
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
## 🛠️ Commandes Disponibles dans le CLI
|
| 153 |
+
|
| 154 |
+
- `/help` - Affiche l'aide
|
| 155 |
+
- `/clear` - Efface l'écran et réinitialise l'historique
|
| 156 |
+
- `/exit` - Ferme proprement l'application
|
| 157 |
+
- `/settings` - Configure le jeton Hugging Face ou d'autres paramètres
|
| 158 |
+
|
| 159 |
+
## 🔌 Outils du Système (Capabilities)
|
| 160 |
+
|
| 161 |
+
Lorsqu'il s'exécute localement via le terminal, **Cypher Coder** peut utiliser des outils pour vous aider :
|
| 162 |
+
- 📁 **Lecture de fichiers** : Lire du code ou du texte sur votre machine.
|
| 163 |
+
- 📝 **Écriture & Modification de fichiers** : Créer ou éditer des fichiers sources.
|
| 164 |
+
- 🖥️ **Exécution de commandes** : Lancer des tests, installer des paquets, compiler, etc. (avec votre consentement explicite).
|
| 165 |
+
- 🌐 **Recherche Web** : Rechercher sur internet en temps réel pour obtenir la documentation de dernière minute.
|
| 166 |
+
""")
|
| 167 |
+
|
| 168 |
+
if __name__ == "__main__":
|
| 169 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
huggingface_hub
|
| 3 |
+
duckduckgo-search
|