Views
No views yet
You are a router. Analyze this user request and choose the best model:
- "TEXT" for text summarization, Q&A, or text processing
- "CAPTION" for describing images
- "TEXT2IMG" for generating images from text
- "MULTIMODAL" for complex tasks requiring multiple models
Respond only with one keyword: TEXT, CAPTION, TEXT2IMG, or MULTIMODAL.
User request: <USER_PROMPT>
Response:┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Request │───▶│ Parent LLM │───▶│ Child Models │
│ │ │ (distilgpt2) │ │ │
└─────────────────┘ │ • Analyzes │ │ • TEXT │
│ • Routes │ │ • CAPTION │
│ • Confidences │ │ • TEXT2IMG │
└──────────────────┘ └─────────────────┘pip install git+https://huggingface.co/kunaliitkgp09/multi-model-orchestrator1import asyncio
2from advanced_orchestrator import AdvancedMultiModelOrchestrator
3
4async def main():
5 # Initialize the orchestrator
6 orchestrator = AdvancedMultiModelOrchestrator(parent_model_name="distilgpt2")
7
8 # Process a request
9 result = await orchestrator.process_request("Generate an image of a peaceful forest")
10
11 print(f"Task Type: {result.task_type.value}")
12 print(f"Confidence: {result.confidence:.2f}")
13 print(f"Output: {result.output}")
14 print(f"Processing Time: {result.processing_time:.2f}s")
15
16asyncio.run(main())1# Text processing request
2result = await orchestrator.process_request("What is machine learning?")
3# Parent LLM routes to TEXT model
4
5# Image captioning request
6result = await orchestrator.process_request("Describe this image of a sunset")
7# Parent LLM routes to CAPTION model
8
9# Text-to-image request
10result = await orchestrator.process_request("Generate an image of a futuristic city")
11# Parent LLM routes to TEXT2IMG model1# Process complex multimodal requests
2results = await orchestrator.process_multimodal_request(
3 image_path="sample_image.jpg",
4 text_prompt="A serene landscape with mountains"
5)
6
7# Results contain both caption and generated image
8caption_result = results["caption"]
9generated_image_result = results["generated_image"]1# Get performance statistics
2stats = orchestrator.get_performance_stats()
3print(f"Total Tasks: {stats['total_tasks']}")
4print(f"Success Rate: {stats['success_rate']:.1%}")
5print(f"Average Processing Time: {stats['average_processing_time']:.2f}s")
6
7# Get task history
8history = orchestrator.get_task_history()
9for task in history:
10 print(f"{task.task_type.value}: {task.input_data[:50]}...")1from advanced_orchestrator import ModelConfig, TaskType
2
3# Custom model configuration
4config = ModelConfig(
5 name="your-custom-model",
6 model_type=TaskType.TEXT,
7 device="cuda",
8 max_length=512,
9 temperature=0.7
10)1# Use different parent LLM
2orchestrator = AdvancedMultiModelOrchestrator(
3 parent_model_name="gpt2" # or any other model
4)Request: "Summarize this article about AI"
Decision: TEXT (Confidence: 0.43) ✅
Request: "Describe this image of a sunset"
Decision: CAPTION (Confidence: 0.43) ✅
Request: "Generate an image of a forest"
Decision: TEXT (Confidence: 0.29) ❌
Expected: TEXT2IMG1class CustomParentRouter(ParentLLMRouter):
2 def analyze_request(self, user_request: str):
3 # Custom routing logic
4 # Override the default behavior
5 pass1# Models are automatically cached after first load
2# Subsequent requests use cached models for faster processing1# Automatic fallback to heuristic routing
2# Comprehensive error logging and reporting1import logging
2logging.basicConfig(level=logging.DEBUG)
3
4# Detailed logging for troubleshooting