Spaces:
Sleeping
Sleeping
| """ | |
| Investigation des formats de prompt pour modèles spécialisés MCP | |
| Test de différents formats pour identifier les problèmes de compatibilité | |
| """ | |
| import os | |
| import json | |
| import re | |
| def test_prompt_formats(): | |
| """Tester différents formats de prompt pour diagnostiquer les problèmes""" | |
| print("🧪 INVESTIGATION DES FORMATS DE PROMPT MCP") | |
| print("=" * 60) | |
| # Formats de prompt à tester | |
| prompt_formats = [ | |
| { | |
| 'name': 'Format actuel (simple)', | |
| 'template': '''You are an AI assistant for an RTS game using MCP (Model Context Protocol). | |
| Available tools: | |
| - get_game_state() | |
| - move_units(unit_ids, target_x, target_y) | |
| - attack_unit(attacker_ids, target_id) | |
| - build_building(building_type, position_x, position_y) | |
| User command: "{command}" | |
| Respond with JSON only: {{"tool": "tool_name", "args": {{}}}}''' | |
| }, | |
| { | |
| 'name': 'Format MCP structuré', | |
| 'template': '''<|im_start|>system | |
| You are an MCP assistant for an RTS game. Respond with ONLY JSON. | |
| Available tools: get_game_state, move_units, attack_unit, build_building<|im_end|> | |
| <|im_start|>user | |
| {command}<|im_end|> | |
| <|im_start|>assistant | |
| ''' | |
| }, | |
| { | |
| 'name': 'Format instruct', | |
| 'template': '''[INST] You are an MCP assistant. Respond with ONLY JSON format: | |
| {{"tool": "tool_name", "args": {{}}}} | |
| Command: {command} [/INST]''' | |
| }, | |
| { | |
| 'name': 'Format code', | |
| 'template': '''// MCP assistant for RTS game | |
| // Tools: get_game_state(), move_units(), attack_unit(), build_building() | |
| // Command: {command} | |
| // Response:''' | |
| }, | |
| { | |
| 'name': 'Format minimal', | |
| 'template': '''Tools: get_game_state, move_units, attack_unit, build_building | |
| Command: {command} | |
| JSON:''' | |
| } | |
| ] | |
| test_command = "show game state" | |
| print(f"\n📝 COMMANDE DE TEST: '{test_command}'") | |
| print("-" * 40) | |
| for i, format_info in enumerate(prompt_formats, 1): | |
| prompt = format_info['template'].format(command=test_command) | |
| print(f"\n{i}. {format_info['name']}:") | |
| print(f" Prompt (début): {prompt[:80]}...") | |
| # Analyser la structure du prompt | |
| lines = prompt.count('\n') + 1 | |
| json_instructions = prompt.count('JSON') | |
| tool_mentions = prompt.count('get_game_state') + prompt.count('move_units') + \ | |
| prompt.count('attack_unit') + prompt.count('build_building') | |
| print(f" 📊 Analyse: {lines} lignes, {json_instructions} refs JSON, {tool_mentions} refs outils") | |
| # Vérifier la présence d'éléments clés | |
| has_json_example = '{"tool":' in prompt | |
| has_tool_list = 'Available tools:' in prompt or 'Tools:' in prompt | |
| has_system_prompt = '<|im_start|>system' in prompt or '[INST]' in prompt | |
| print(f" ✅ Éléments: JSON exemple={has_json_example}, Liste outils={has_tool_list}, Système={has_system_prompt}") | |
| def analyze_model_specific_requirements(): | |
| """Analyser les besoins spécifiques des modèles MCP""" | |
| print(f"\n🔍 BESOINS SPÉCIFIQUES DES MODÈLES MCP") | |
| print("=" * 60) | |
| model_requirements = { | |
| 'MCP-Instruct-v1': { | |
| 'expected_format': 'Format conversation structuré avec tokens MCP', | |
| 'common_issues': ['Besoin de tokens spécifiques', 'Format de prompt rigide'], | |
| 'recommendation': 'Utiliser <|im_start|>system/user/assistant format' | |
| }, | |
| 'MCPR L-3B-Exa': { | |
| 'expected_format': 'Format instruct avec contexte MCP', | |
| 'common_issues': ['Quantisation agressive', 'Besoin de contexte étendu'], | |
| 'recommendation': 'Augmenter n_ctx à 4096+ et utiliser Q8_0' | |
| }, | |
| 'Gemma-3n-E2B-it': { | |
| 'expected_format': 'Format technique structuré', | |
| 'common_issues': ['Quantisation extrême IQ2_XXS', 'Format incompatible'], | |
| 'recommendation': 'Utiliser version Q8_0 et format code-oriented' | |
| } | |
| } | |
| for model_name, info in model_requirements.items(): | |
| print(f"\n🧩 {model_name}:") | |
| print(f" 📋 Format attendu: {info['expected_format']}") | |
| print(f" ⚠️ Problèmes courants: {', '.join(info['common_issues'])}") | |
| print(f" 💡 Recommandation: {info['recommendation']}") | |
| def main(): | |
| """Investigation principale""" | |
| print("🔬 INVESTIGATION DES PROBLÈMES DE FORMAT MCP") | |
| print("=" * 70) | |
| test_prompt_formats() | |
| analyze_model_specific_requirements() | |
| print(f"\n🎯 CONCLUSIONS ET SOLUTIONS:") | |
| print("=" * 70) | |
| print("\n1. PROBLÈMES IDENTIFIÉS:") | |
| print(" • Format de prompt incompatible avec les modèles spécialisés") | |
| print(" • Quantisation trop agressive (Q2_K, IQ2_XXS)") | |
| print(" • Manque de tokens/spécificités MCP dans les prompts") | |
| print(" • Contexte insuffisant pour modèles plus grands") | |
| print("\n2. SOLUTIONS RECOMMANDÉES:") | |
| print(" • Télécharger versions Q8_0 des modèles problématiques") | |
| print(" • Utiliser formats structurés avec tokens MCP") | |
| print(" • Augmenter n_ctx à 4096 pour modèles 3B+") | |
| print(" • Ajouter exemples JSON complets dans les prompts") | |
| print(f"\n3. FORMATS DE PROMPT OPTIMAUX:") | |
| print(" • MCP-Instruct-v1: <|im_start|>system/user/assistant avec tokens") | |
| print(" • MCPR L-3B-Exa: Format instruct avec contexte étendu") | |
| print(" • Gemma-3n-E2B-it: Format code-oriented structuré") | |
| print(f"\n🚀 PROCHAINES ÉTAPES:") | |
| print(" 1. Télécharger mcp-instruct-v1.Q8_0.gguf") | |
| print(" 2. Télécharger mcprl-3b-exa.Q8_0.gguf") | |
| print(" 3. Télécharger google_gemma-3n-E2B-it-Q8_0.gguf") | |
| print(" 4. Tester avec formats de prompts optimisés") | |
| if __name__ == "__main__": | |
| main() |