-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AzureMLOnlineEndpoint not working, 404 error, but same url and api key works with standard http #9987
Comments
🤖 Hello, The 404 error you're experiencing when using the LangChain code with AzureMLOnlineEndpoint could be due to the way the request is being sent. In the standard Python request library, you might be sending a GET request by default, but in the LangChain code, a POST request is being sent. In the If the endpoint you're trying to reach does not support POST requests, this could be why you're receiving a 404 error. You might need to modify the In the context shared, it's also important to note that the The You can find more information about this in the following sources:
I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
@dosu-bot the test only test AzureMLChatOnlineEndpoint and not the AzureMLEndpoint. |
🤖 Hello, To effectively test the AzureMLEndpoint in LangChain, you can create a unit test that mocks the AzureMLEndpointClient's call method and the content formatter's methods. Here's an example of how you can do this using the unittest and unittest.mock libraries: import unittest
from unittest.mock import MagicMock, patch
from langchain.llms.azureml_endpoint import AzureMLEndpoint, AzureMLEndpointClient, LlamaContentFormatter
class TestAzureMLEndpoint(unittest.TestCase):
@patch.object(AzureMLEndpointClient, 'call')
@patch.object(LlamaContentFormatter, 'format_request_payload')
@patch.object(LlamaContentFormatter, 'format_response_payload')
def test_call(self, mock_format_response_payload, mock_format_request_payload, mock_call):
# Arrange
mock_format_request_payload.return_value = b'{"inputs": {"input_string": ["prompt"]}, "parameters": {}}'
mock_call.return_value = b'{"0": "generated text"}'
mock_format_response_payload.return_value = "generated text"
azure_ml_endpoint = AzureMLEndpoint(
endpoint_url="https://test-endpoint.com/score",
endpoint_api_key="test-api-key",
content_formatter=LlamaContentFormatter(),
)
# Act
result = azure_ml_endpoint._call("prompt")
# Assert
mock_format_request_payload.assert_called_once_with("prompt", {})
mock_call.assert_called_once_with(b'{"inputs": {"input_string": ["prompt"]}, "parameters": {}}')
mock_format_response_payload.assert_called_once_with(b'{"0": "generated text"}')
self.assertEqual(result, "generated text")
if __name__ == '__main__':
unittest.main() In this test, we're creating an instance of AzureMLEndpoint and calling its _call method with a prompt. We're mocking the AzureMLEndpointClient's call method and the LlamaContentFormatter's format_request_payload and format_response_payload methods to control their behavior and make assertions about how they're called. We're also asserting that the result of the _call method is as expected. This is in line with the context shared where LlamaContentFormatter is used instead of GPT2ContentFormatter. You can find more information about the AzureMLEndpoint and how it's used in the LangChain codebase in the following files:
I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
I have also experienced this same issue. However, I don't think the issue with with GET/POST request or with the content formatter. The issue seems to the with the fact that the AzureMLChatOnlineEndpoint class is not instantiated with any reference to the deployment name of the Azure ML endpoint, see
The deployment_name is an (optional) parameter for AzureMLEndpointClient, which AzureMLChatOnlineEndpoint calls. I can see here in the Langchain docs that deployment_name is "Not required" but i believe it is required when using AzureMLChatOnlineEndpoint. As @levalencia has mentioned above (and shown in his askdocuments2 example), when including the deployment name, in his case "'azureml-model-deployment': 'llama'" in his header, then the call to the hosted Azure ML model works. i.e. the deployment name is required. To fix this in the AzureMLChatOnlineEndpoint, I think adding an additional "deployment_name" parameter to the class would solve it - just like this is for AzureMLEndpointClient. The new deployment_name parameter passed to AzureMLChatOnlineEndpoint can then be passed to AzureMLEndpointClient when it is instantiated... I have tested this in debug by adding a deployment_name value just after AzureMLEndpointClient is created and it all works fine. Only with the deployment name included does it work. I'm happy to raise a PR if @dosu-bot you agree/think this is the correct solution? |
When testing with the newest versions, it works now |
System Info
0.0.276
Who can help?
@hwchase17
@agola11
Information
Related Components
Reproduction
I have deployed llama2 in Azure ML endpoint and when I test it with langchain code I got a 404 Error. However using standard request library from python it works
Below : askdocuments2 ---> no lanchain
askdocuments --->langchain
same endpoint url, same key.
Expected behavior
According to the documentation I am doing everything correctly, so not sure why its showing a 404 error in a valid url
The text was updated successfully, but these errors were encountered: