Skip to content

feat: add default user agent in api request component #7631

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

Merged
merged 18 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/backend/base/langflow/components/data/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
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):
Expand Down Expand Up @@ -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",
Expand All @@ -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,
),
Expand Down Expand Up @@ -278,7 +283,8 @@ def parse_curl(self, curl: str, build_config: dotdict) -> dotdict:
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
Expand All @@ -303,9 +309,13 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
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

Expand Down
Loading
Loading