feat: add default user agent in api request component (#7631)
* Update api_request.py * Update api_request.py * Update api_request.py * [autofix.ci] apply automated fixes * Update src/backend/base/langflow/components/data/api_request.py Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> * Update src/backend/base/langflow/components/data/api_request.py Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> * Update api_request.py * [autofix.ci] apply automated fixes * fix format * fix format issues * [autofix.ci] apply automated fixes * Template Update --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
e3bce8b8d8
commit
d2919f228d
2 changed files with 17 additions and 7 deletions
|
|
@ -29,6 +29,9 @@ from langflow.io import (
|
|||
from langflow.schema import Data
|
||||
from langflow.schema.dataframe import DataFrame
|
||||
from langflow.schema.dotdict import dotdict
|
||||
from langflow.services.deps import get_settings_service
|
||||
|
||||
# Get settings using the service
|
||||
|
||||
|
||||
class APIRequestComponent(Component):
|
||||
|
|
@ -99,11 +102,12 @@ class APIRequestComponent(Component):
|
|||
value=[],
|
||||
input_types=["Data"],
|
||||
advanced=True,
|
||||
real_time_refresh=True,
|
||||
),
|
||||
TableInput(
|
||||
name="headers",
|
||||
display_name="Headers",
|
||||
info="The headers to send with the request as a dictionary.",
|
||||
info="The headers to send with the request",
|
||||
table_schema=[
|
||||
{
|
||||
"name": "key",
|
||||
|
|
@ -118,14 +122,15 @@ class APIRequestComponent(Component):
|
|||
"description": "Header value",
|
||||
},
|
||||
],
|
||||
value=[],
|
||||
value=[{"key": "User-Agent", "value": get_settings_service().settings.user_agent}],
|
||||
advanced=True,
|
||||
input_types=["Data"],
|
||||
real_time_refresh=True,
|
||||
),
|
||||
IntInput(
|
||||
name="timeout",
|
||||
display_name="Timeout",
|
||||
value=5,
|
||||
value=30,
|
||||
info="The timeout to use for the request.",
|
||||
advanced=True,
|
||||
),
|
||||
|
|
@ -278,7 +283,8 @@ class APIRequestComponent(Component):
|
|||
return build_config
|
||||
|
||||
def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:
|
||||
if field_name == "use_curl":
|
||||
if field_name == "use_curl" and field_value:
|
||||
# if we remove field value from validation, this gets validated every time
|
||||
build_config = self._update_curl_mode(build_config, use_curl=field_value)
|
||||
|
||||
# Fields that should not be reset
|
||||
|
|
@ -303,9 +309,13 @@ class APIRequestComponent(Component):
|
|||
reset_value = type_reset_mapping.get(type(input_field), None)
|
||||
build_config[input_field.name]["value"] = reset_value
|
||||
self.log(f"Reset field {input_field.name} to {reset_value}")
|
||||
elif field_name == "method" and not self.use_curl:
|
||||
# Don't try to parse the boolean value as a curl command
|
||||
return build_config
|
||||
if field_name == "method" and not self.use_curl:
|
||||
build_config = self._update_method_fields(build_config, field_value)
|
||||
elif field_name == "curl" and self.use_curl and field_value:
|
||||
# Not reachable, because we don't have a way to update
|
||||
# the curl field, self.use_curl is set after the build_config is created
|
||||
build_config = self.parse_curl(field_value, build_config)
|
||||
return build_config
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue