verify model credentials and build display credentials :param model_schema_id: the model schema id :param provider_model_id: the provider model id :param properties: the properties :param model_type: the model type :param credentials: the credentials :param encrypted_cre
(
model_schema_id: str,
provider_model_id: str,
properties: Dict,
model_type: str,
credentials: Dict,
encrypted_credentials: Dict = None,
)
| 42 | |
| 43 | |
| 44 | async def verify_model_credentials( |
| 45 | model_schema_id: str, |
| 46 | provider_model_id: str, |
| 47 | properties: Dict, |
| 48 | model_type: str, |
| 49 | credentials: Dict, |
| 50 | encrypted_credentials: Dict = None, |
| 51 | ) -> Tuple[str, str, str, str, Dict, Dict, Dict]: |
| 52 | """ |
| 53 | verify model credentials and build display credentials |
| 54 | :param model_schema_id: the model schema id |
| 55 | :param provider_model_id: the provider model id |
| 56 | :param properties: the properties |
| 57 | :param model_type: the model type |
| 58 | :param credentials: the credentials |
| 59 | :param encrypted_credentials: the encrypted credentials |
| 60 | :return: a tuple of (the model schema id, provider id, provider model id, model type, |
| 61 | encrypted credentials, display credentials, properties) |
| 62 | |
| 63 | """ |
| 64 | from app.services.model import get_model_schema, get_provider |
| 65 | from app.services.inference import verify_credentials |
| 66 | |
| 67 | # verify model schema exists |
| 68 | model_schema: ModelSchema = get_model_schema(model_schema_id) |
| 69 | if not model_schema: |
| 70 | raise_http_error( |
| 71 | error_code=ErrorCode.OBJECT_NOT_FOUND, |
| 72 | message=f"Model schema {model_schema_id} not found.", |
| 73 | ) |
| 74 | |
| 75 | # get provider |
| 76 | provider: Provider = get_provider(model_schema.provider_id) |
| 77 | |
| 78 | provider_model_id = provider_model_id or model_schema.provider_model_id |
| 79 | |
| 80 | properties = properties or model_schema.properties |
| 81 | provider_model_id = provider_model_id or model_schema.provider_model_id |
| 82 | |
| 83 | if model_schema.type == ModelType.WILDCARD: |
| 84 | if not model_type: |
| 85 | raise_request_validation_error("Model type is required for wildcard models.") |
| 86 | elif model_type == ModelType.WILDCARD: |
| 87 | raise_request_validation_error("Model type cannot be wildcard.") |
| 88 | else: |
| 89 | model_type = model_schema.type |
| 90 | |
| 91 | # verify model credentials |
| 92 | response = await verify_credentials( |
| 93 | model_schema_id=model_schema.model_schema_id, |
| 94 | provider_model_id=provider_model_id, |
| 95 | model_type=model_type, |
| 96 | credentials=credentials, |
| 97 | encrypted_credentials=encrypted_credentials, |
| 98 | properties=properties, |
| 99 | ) |
| 100 | check_http_error(response) |
| 101 | response_data = response.json()["data"] |
no test coverage detected