HTTPS 400 Error Bad Request when trying to connect Azure ML #24794
Replies: 1 comment
-
You are encountering an HTTPS 400 Error (Bad Request) because the Ensure your @validator("endpoint_url")
def validate_endpoint_url(cls, field_value: Any) -> str:
"""Validate that endpoint url is complete."""
if field_value.endswith("/"):
field_value = field_value[:-1]
if field_value.endswith("inference.ml.azure.com"):
raise ValueError(
"`endpoint_url` should contain the full invocation URL including "
"`/score` for `endpoint_api_type='dedicated'` or `/v1/completions` "
"or `/v1/chat/completions` for `endpoint_api_type='serverless'`"
)
return field_value Additionally, ensure that your request payload is correctly formatted. An invalid request format can also lead to a 400 Error. For example, if you are using a custom content formatter, make sure the request payload structure matches the expected format by the endpoint. Here is an example of a test case for an invalid request format: def test_invalid_request_format() -> None:
"""Test invalid request format."""
class CustomContentFormatter(ContentFormatterBase):
content_type = "application/json"
accepts = "application/json"
def format_request_payload(self, prompt: str, model_kwargs: Dict) -> bytes: # type: ignore[override]
input_str = json.dumps(
{
"incorrect_input": {"input_string": [prompt]},
"parameters": model_kwargs,
}
)
return str.encode(input_str)
def format_response_payload(self, output: bytes) -> str: # type: ignore[override]
response_json = json.loads(output)
return response_json[0]["0"]
with pytest.raises(HTTPError):
llm = AzureMLOnlineEndpoint(
endpoint_api_key=os.getenv("OSS_ENDPOINT_API_KEY"), # type: ignore[arg-type]
endpoint_url=os.getenv("OSS_ENDPOINT_URL"), # type: ignore[arg-type]
deployment_name=os.getenv("OSS_DEPLOYMENT_NAME"), # type: ignore[arg-type]
content_formatter=CustomContentFormatter(),
)
llm.invoke("Foo") Make sure your |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to invoke an llm thats deployed on azure ai. It gives a bad request error.
System Info
python 3
Beta Was this translation helpful? Give feedback.
All reactions