Merge pull request #235 from langflow-ai/fix/ibm_validation

fix: added api key validation for IBM models
This commit is contained in:
Nate McCall 2025-10-09 12:14:39 +13:00 committed by GitHub
commit 6b73eecbd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -242,6 +242,35 @@ class ModelsService:
headers["Authorization"] = f"Bearer {api_key}"
if project_id:
headers["Project-ID"] = project_id
# Validate credentials with a minimal completion request
async with httpx.AsyncClient() as client:
validation_url = f"{watson_endpoint}/ml/v1/text/generation"
validation_params = {"version": "2024-09-16"}
validation_payload = {
"input": "test",
"model_id": "ibm/granite-3-2b-instruct",
"project_id": project_id,
"parameters": {
"max_new_tokens": 1,
},
}
validation_response = await client.post(
validation_url,
headers=headers,
params=validation_params,
json=validation_payload,
timeout=10.0,
)
if validation_response.status_code != 200:
raise Exception(
f"Invalid credentials or endpoint: {validation_response.status_code} - {validation_response.text}"
)
logger.info("IBM Watson credentials validated successfully")
# Fetch foundation models using the correct endpoint
models_url = f"{watson_endpoint}/ml/v1/foundation_model_specs"