MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / check_llm_api

Function check_llm_api

AskAgent/python/testing/check_connectivity.py:45–68  ·  view source on GitHub ↗
(llm_name)

Source from the content-addressed store, hash-verified

43
44# Function to check LLM API connectivity
45async def check_llm_api(llm_name) -> bool:
46 print(f"Checking LLM API connectivity for {llm_name}...")
47 if llm_name not in CONFIG.llm_endpoints:
48 await log_unknown_provider("LLM", llm_name)
49 return False
50
51 try:
52 schema = {"capital": "string"}
53 test_prompt = "What is the capital of France?"
54 # Using a larger timeout than the default because we don't want to fail on slow responses
55 output = await ask_llm(test_prompt, schema=schema, provider=llm_name, timeout=20)
56 #print(f"Output from {llm_name}: {output}")
57 if not output:
58 print(f"❌ LLM API connectivity check failed for {llm_name}: No valid output received.")
59 return False
60 elif str(output).__contains__("Paris") or str(output).__contains__("paris"):
61 print(f"✅ LLM API connectivity check successful for {llm_name}. Output contains expected answer.")
62 return True
63 else:
64 print(f"❌ LLM API connectivity check failed for {llm_name}: Output does not contain expected answer 'Paris'. Please verify manually: {output!s}")
65 return False
66 except Exception as e:
67 print(f"❌ LLM API connectivity check failed for {llm_name}: {type(e).__name__}: {e!s}")
68 return False
69
70
71# Function to check embedding API connectivity

Callers 1

mainFunction · 0.70

Calls 2

ask_llmFunction · 0.90
log_unknown_providerFunction · 0.70

Tested by

no test coverage detected