MCPcopy Create free account
hub / github.com/IBM/mcp-cli / test_client_creation

Function test_client_creation

diagnostics/debug_models.py:95–156  ·  view source on GitHub ↗

Test creating clients directly.

()

Source from the content-addressed store, hash-verified

93
94
95def test_client_creation():
96 """Test creating clients directly."""
97 print("\n🔧 Client Creation Test:")
98
99 try:
100 # Try chuk-llm 0.6 approach
101 from chuk_llm.llm.client import get_client, list_available_providers
102
103 print(" 📋 Testing list_available_providers()...")
104 providers = list_available_providers()
105
106 for name, info in providers.items():
107 if "error" in info:
108 print(f" ❌ {name}: {info['error']}")
109 else:
110 # FIXED: Use "models" key instead of "available_models" for chuk-llm 0.7
111 model_count = len(info.get("models", info.get("available_models", [])))
112 has_key = info.get("has_api_key", False)
113
114 # Special handling for Ollama - check if it's running
115 if name == "ollama":
116 import httpx
117
118 try:
119 response = httpx.get(
120 "http://localhost:11434/api/tags", timeout=2.0
121 )
122 if response.status_code == 200:
123 has_key = True # Ollama running = no API key needed
124 ollama_models = response.json().get("models", [])
125 model_count = len(ollama_models)
126 except Exception:
127 pass
128
129 status = (
130 "✅" if has_key or (name == "ollama" and model_count > 0) else "❌"
131 )
132 print(f" {status} {name}: {model_count} models, API key: {has_key}")
133
134 # Try creating a client
135 print("\n 🔧 Testing client creation...")
136 if "openai" in providers and providers["openai"].get("has_api_key"):
137 try:
138 get_client(provider="openai", model="gpt-4o-mini")
139 print(" ✅ OpenAI client created successfully")
140 except Exception as e:
141 print(f" ❌ OpenAI client creation failed: {e}")
142 else:
143 print(" ⚠️ Skipping OpenAI client test (no API key)")
144
145 except ImportError:
146 print(" ❌ chuk-llm 0.6 client functions not available")
147
148 # Try legacy approach
149 try:
150 print(" 🔄 Trying legacy client creation...")
151
152 # This would need your existing ModelManager for config

Callers 1

mainFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected