Created
September 12, 2025 18:49
-
-
Save carsongee/00df6179a652d2d1d8e0cee64914b9df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Demo script for LLM Gateway Catalog SDK functionality. | |
| This demonstrates how to use the new LLMGatewayCatalog classes to replace | |
| manual API calls with proper SDK methods. | |
| """ | |
| from __future__ import annotations | |
| from datarobot.models.genai.llm_gateway_catalog import LLMGatewayCatalog | |
| def demo_basic_usage(): | |
| """Demonstrate basic catalog usage.""" | |
| print("=== LLM Gateway Catalog Demo ===") | |
| # Get all available models (active, non-deprecated by default) | |
| print("\n1. Getting available models:") | |
| try: | |
| available_models = LLMGatewayCatalog.get_available_models() | |
| print(f"Found {len(available_models)} available models:") | |
| for model in available_models[:5]: # Show first 5 | |
| print(f" - {model}") | |
| if len(available_models) > 5: | |
| print(f" ... and {len(available_models) - 5} more") | |
| except Exception as e: | |
| print(f"Error getting available models: {e}") | |
| # Get full catalog entries with details | |
| print("\n2. Getting catalog entries with details:") | |
| try: | |
| catalog_entries = LLMGatewayCatalog.list(limit=3) | |
| print(f"Retrieved {len(catalog_entries)} catalog entries:") | |
| for entry in catalog_entries: | |
| print(f" - {entry.name} ({entry.model})") | |
| print(f" Provider: {entry.provider}") | |
| print(f" Context Size: {entry.context_size:,} tokens") | |
| print(f" Active: {entry.is_active}, Deprecated: {entry.is_deprecated}") | |
| print() | |
| except Exception as e: | |
| print(f"Error getting catalog entries: {e}") | |
| # Verify a specific model is available | |
| print("\n3. Verifying model availability:") | |
| test_models = [ | |
| "azure/gpt-4o-2024-11-20", # Example from real API | |
| "azure-openai-gpt-4-o", # Using llmId | |
| "non-existent-model" # This should fail | |
| ] | |
| for model_id in test_models: | |
| try: | |
| model_entry = LLMGatewayCatalog.verify_model_availability(model_id) | |
| print(f" ✓ {model_id} is available: {model_entry.name}") | |
| except ValueError as e: | |
| print(f" ✗ {model_id} is not available: {e}") | |
| def demo_advanced_filtering(): | |
| """Demonstrate advanced filtering capabilities.""" | |
| print("\n=== Advanced Filtering Demo ===") | |
| # Get all models including deprecated ones | |
| print("\n1. Including deprecated models:") | |
| try: | |
| all_entries = LLMGatewayCatalog.list( | |
| only_active=False, | |
| only_non_deprecated=False, | |
| limit=10 | |
| ) | |
| active_count = sum(1 for entry in all_entries if entry.is_active) | |
| deprecated_count = sum(1 for entry in all_entries if entry.is_deprecated) | |
| print(f"Found {len(all_entries)} total entries:") | |
| print(f" - Active: {active_count}") | |
| print(f" - Deprecated: {deprecated_count}") | |
| # Show deprecated models with replacement info | |
| deprecated_models = [e for e in all_entries if e.is_deprecated] | |
| if deprecated_models: | |
| print("\nDeprecated models with replacements:") | |
| for entry in deprecated_models[:3]: | |
| print(f" - {entry.model}") | |
| if entry.retirement_date: | |
| print(f" Retirement Date: {entry.retirement_date}") | |
| if entry.suggested_replacement: | |
| print(f" Suggested Replacement: {entry.suggested_replacement}") | |
| print() | |
| except Exception as e: | |
| print(f"Error getting all entries: {e}") | |
| def demo_replacement_pattern(): | |
| """Demonstrate how this replaces the original manual API pattern.""" | |
| print("\n=== Replacement Pattern Demo ===") | |
| print("OLD WAY (manual API call):") | |
| print(" response = dr_client.get('genai/llmgw/catalog/')") | |
| print(" models = [item['model'] for item in response.json()['data']]") | |
| print(" # Manual filtering and validation...") | |
| print("\nNEW WAY (using SDK):") | |
| print(" from datarobot.models.genai.llm_gateway_catalog import LLMGatewayCatalog") | |
| print(" models = LLMGatewayCatalog.get_available_models()") | |
| print(" entry = LLMGatewayCatalog.verify_model_availability('model-id')") | |
| print("\nBenefits:") | |
| print(" ✓ Proper error handling") | |
| print(" ✓ Built-in filtering (active, non-deprecated)") | |
| print(" ✓ Rich object model with typed fields") | |
| print(" ✓ Convenience methods for common patterns") | |
| print(" ✓ Consistent with other DataRobot SDK patterns") | |
| if __name__ == "__main__": | |
| print("LLM Gateway Catalog SDK Demo") | |
| print("Note: This requires valid DataRobot credentials and API access") | |
| print() | |
| try: | |
| demo_basic_usage() | |
| demo_advanced_filtering() | |
| demo_replacement_pattern() | |
| print("\n=== Demo Complete ===") | |
| print("The LLM Gateway Catalog SDK is ready for use!") | |
| except Exception as e: | |
| print(f"\nDemo failed with error: {e}") | |
| print("Make sure you have valid DataRobot credentials configured.") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: