Merge pull request #235 from langflow-ai/fix/ibm_validation
fix: added api key validation for IBM models
This commit is contained in:
commit
6b73eecbd3
1 changed files with 29 additions and 0 deletions
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue