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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
16 changes: 12 additions & 4 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 @@
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 @@
"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 @@
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,11 @@
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}")
build_config = self.parse_curl(field_value, build_config)
elif 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

Check failure on line 316 in src/backend/base/langflow/components/data/api_request.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.13)

Ruff (E501)

src/backend/base/langflow/components/data/api_request.py:316:121: E501 Line too long (137 > 120)
build_config = self.parse_curl(field_value, build_config)
return build_config

Expand Down
Loading