-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_simple_ligands.py
More file actions
59 lines (48 loc) · 1.82 KB
/
Copy pathdebug_simple_ligands.py
File metadata and controls
59 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
sys.path.append('src')
import httpx
import asyncio
from typing import List
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pharmacology_mcp.pharmacology_api import LigandResponse, LigandQueryRequest
# Create a simple FastAPI app with just the ligands endpoint
app = FastAPI()
BASE_URL = "https://www.guidetopharmacology.org/services"
@app.post("/ligands", response_model=List[LigandResponse])
async def list_ligands_simple(request: LigandQueryRequest):
"""Simplified ligands endpoint without eliot logging"""
try:
params = {k: v for k, v in request.model_dump().items() if v is not None}
async with httpx.AsyncClient() as client:
response = await client.get(f"{BASE_URL}/ligands", params=params)
response.raise_for_status()
data = response.json()
if not isinstance(data, list):
return []
validated_ligands = []
for ligand_data in data:
try:
validated_ligands.append(LigandResponse.model_validate(ligand_data))
except Exception as e:
print(f"Validation error for ligand: {e}")
pass
return validated_ligands
except Exception as e:
print(f"Error in list_ligands_simple: {e}")
raise
# Test the simplified endpoint
client = TestClient(app)
print("Testing simplified POST /ligands...")
response = client.post("/ligands", json={})
print(f"Status Code: {response.status_code}")
print(f"Response Text: {response.text[:200]}...")
if response.status_code == 200:
data = response.json()
print(f"Success! Got {len(data)} ligands")
else:
try:
error_detail = response.json()
print(f"Error Detail: {error_detail}")
except:
print("Could not parse error as JSON")