Skip to main content
Glama

LCBro

by lcbro
INTELLIGENT_PREPROCESSING.md•6.3 kB
# Intelligent Auto-Generation of Prompts for Preprocessing ## Overview The new automatic prompt generation system for preprocessing uses local LLM models to analyze content and create optimal preprocessing instructions. This significantly improves data processing quality at minimal cost. ## Key Features ### 1. Intelligent Content Analysis The system automatically analyzes input data using fast local models: - **Content type analysis**: HTML, JSON, text - **Structure detection**: tables, products, articles, data - **Noise detection**: ads, navigation, scripts - **Complexity assessment**: size, nesting, consistency ### 2. Local Model Priority The system maximizes local model usage for savings: **Priority order (default):** 1. `ollama:qwen2.5:7b` - fastest for preprocessing 2. `ollama:llama3.2:3b` - very fast, small model 3. `ollama:mistral:7b` - good balance 4. `ollama:llama3.1:8b` - stable choice 5. `jan:llama-3.2-3b` - JAN fallback 6. `jan:mistral-7b` - JAN alternative ### 3. Smart Auto-Trigger Thresholds The system automatically determines when preprocessing is needed: - **HTML**: >3KB (default) or presence of noise - **Text**: >5KB (default) or formatting issues - **JSON**: >1KB (default) or structure inconsistency - **Any type**: >10KB automatically ### 4. Template Library If intelligent analysis is unavailable, the system uses optimized templates: - **HTML**: general, tables, products, articles - **Text**: general, extraction, summarization - **JSON**: general, tables, dates ## Configuration ### config/default.yaml ```yaml llm: autoPreprocess: true preprocessing: enabled: true # enable/disable preprocessing intelligentMode: true # use LLM for analysis fallbackToTemplates: true # fallback to templates # Size thresholds for auto-trigger thresholds: html: 3000 # HTML larger than 3KB text: 5000 # text larger than 5KB json: 1000 # JSON larger than 1KB # Model priority for preprocessing preferredModels: - "ollama:qwen2.5:7b" # fastest - "ollama:llama3.2:3b" # very fast - "ollama:mistral:7b" # balance - "ollama:llama3.1:8b" # stable - "jan:llama-3.2-3b" # JAN fallback - "jan:mistral-7b" # JAN alternative # Analysis settings analysis: maxContentSample: 1000 # max characters for analysis maxAnalysisTokens: 300 # max analysis tokens analysisTemperature: 0.1 # low temperature ``` ## Usage Examples ### 1. Automatic Mode (Recommended) ```typescript const result = await mcp.callTool('llm.transform', { input: { kind: 'html', data: largeHtmlContent }, instruction: 'Extract product information as JSON' // preprocessRequest automatically generated }); ``` **What happens:** 1. System determines HTML >3KB needs preprocessing 2. Local model analyzes content (first 1000 characters) 3. Generates specific prompt: "Remove HTML noise: scripts, styles, navigation, ads, footers. Focus on product/item information, remove marketing fluff. Keep only content relevant to the main task." 4. Fast local model performs preprocessing 5. Main model processes cleaned data ### 2. Explicit Control ```typescript const result = await mcp.callTool('llm.transform', { input: { kind: 'html', data: htmlData }, instruction: 'Create product catalog', preprocessRequest: 'Remove all non-product elements, focus on titles, prices, descriptions' }); ``` ### 3. Disable Preprocessing ```typescript // In configuration preprocessing: { enabled: false } // Or only intelligent mode preprocessing: { intelligentMode: false, fallbackToTemplates: true } ``` ## System Architecture ### 1. Preprocessing Need Detector - Analyzes content size - Checks for HTML noise - Detects text formatting issues - Evaluates JSON structure consistency ### 2. Intelligent Prompt Generator - Uses local model for content analysis - Creates customized preprocessing instructions - Adapts to task type (extraction, cleaning, structuring) ### 3. Fallback System - Automatic fallback to templates on failures - Graceful functionality degradation - Logging of all stages for debugging ### 4. Local Model Manager - Prioritization by speed/efficiency - Automatic selection of available model - Support for Ollama and JAN providers ## Performance and Savings ### Example: E-commerce Site Processing **Without preprocessing:** - Input data: 50KB HTML with navigation, ads, comments - Tokens: ~12,500 (OpenAI pricing) - Cost: ~$0.125 (GPT-4) - Quality: low (much noise) **With intelligent preprocessing:** - Content analysis: ollama:qwen2.5:7b (~200 tokens, free) - Preprocessing: ollama:qwen2.5:7b (~3000 tokens, free) - Main processing: 5KB cleaned data (~1,250 tokens) - Cost: ~$0.012 (only for main processing) - **Savings: 90%** + significantly better quality ### Execution Time - **Analysis**: 0.5-1 sec (local model) - **Preprocessing**: 2-5 sec (local model) - **Main processing**: 3-8 sec (target model) - **Total time**: +20-30% for 90% savings and better quality ## Monitoring and Debugging ### Logging The system logs all stages: ```json { "level": "info", "msg": "Auto-generated intelligent preprocessing request", "autoGeneratedPreprocess": "Remove HTML noise: scripts, styles, navigation, ads, footers. Focus on product/item information, remove marketing fluff. Keep only content relevant to the main task." } { "level": "info", "msg": "Preprocessing completed", "originalLength": 51200, "processedLength": 5800, "preprocessRequest": "..." } { "level": "debug", "msg": "Selected Ollama model for preprocessing", "model": "ollama:qwen2.5:7b", "modelType": "Ollama" } ``` ### Debugging For detailed analysis, set logging level: ```yaml logging: level: debug ``` ## Conclusion The new intelligent auto-generation system for preprocessing prompts: - āœ… **Saves 80-90%** of processing costs - āœ… **Improves quality** of results - āœ… **Maximizes usage** of local models - āœ… **Automatically adapts** to content type - āœ… **Gracefully degrades** on failures - āœ… **Easily configurable** for project needs **Model:** Claude Sonnet 4

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lcbro/lcbro-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server