Added curl parse to API Request component and fixed dict issues (#2013)
* Refactor code to remove console.log statements * Refactor code to remove console.log statements * ⬆️ (pyproject.toml): upgrade uncurl dependency to version 0.0.11 * 📝 (flows.py): Add docstring to the read_flows function to provide information about its purpose, arguments, and return value 📝 (parse.py): Add comments and docstrings to the parse_context function to explain its purpose and how it works 📝 (APIRequest.py): Add a new method update_build_config to handle parsing of curl commands and update build configuration based on the parsed context * refactor: Improve value change detection logic in DictComponent * refactor: Improve value change detection logic in DictAreaModal * refactor: Update APIRequest to handle parsing of curl commands and update build configuration This commit updates the APIRequest class in APIRequest.py to handle parsing of curl commands and update the build configuration based on the parsed context. It introduces a new method, update_build_config, which parses the curl command using the parse_context function and updates the build configuration with the parsed information. Additionally, it handles JSON decoding errors when parsing the data field of the curl command. This improvement enhances the functionality and flexibility of the APIRequest component. * feat: Add support for handling headers as dictionaries in APIRequest * refactor: Parse curl commands and update build configuration in APIRequest This commit refactors the APIRequest class in APIRequest.py to handle parsing of curl commands and update the build configuration based on the parsed context. It introduces a new method, update_build_config, which parses the curl command using the parse_context function and updates the build configuration with the parsed information. Additionally, it handles JSON decoding errors when parsing the data field of the curl command. This improvement enhances the functionality and flexibility of the APIRequest component. * ✨ (test_data_components.py): add new test case to parse curl command into build configuration for API requests * 🐛 (src/backend/base/langflow/components/data/APIRequest.py): fix type hinting issue for bodies variable in APIRequest class
This commit is contained in:
parent
fb018eda10
commit
e5986ec727
20 changed files with 248 additions and 63 deletions
|
|
@ -6,9 +6,8 @@ import httpx
|
|||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
from langflow.components import (
|
||||
data,
|
||||
)
|
||||
|
||||
from langflow.components import data
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -34,6 +33,27 @@ async def test_successful_get_request(api_request):
|
|||
assert result.data["result"] == mock_response
|
||||
|
||||
|
||||
def test_parse_curl(api_request):
|
||||
# Arrange
|
||||
field_value = (
|
||||
"curl -X GET https://example.com/api/test -H 'Content-Type: application/json' -d '{\"key\": \"value\"}'"
|
||||
)
|
||||
build_config = {
|
||||
"method": {"value": ""},
|
||||
"urls": {"value": []},
|
||||
"headers": {},
|
||||
"body": {},
|
||||
}
|
||||
# Act
|
||||
new_build_config = api_request.parse_curl(field_value, build_config.copy())
|
||||
|
||||
# Assert
|
||||
assert new_build_config["method"]["value"] == "GET"
|
||||
assert new_build_config["urls"]["value"] == ["https://example.com/api/test"]
|
||||
assert new_build_config["headers"]["value"] == {"Content-Type": "application/json"}
|
||||
assert new_build_config["body"]["value"] == {"key": "value"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_failed_request(api_request):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue