refactor: Set user agent for API calls in base settings
The code changes in `base.py` add a `user_agent` attribute to the `Settings` class and a corresponding class method `set_user_agent` to set the user agent for API calls. If the `user_agent` is not provided, it defaults to "langflow". The method also updates the `USER_AGENT` environment variable and logs the new value. This refactor improves the flexibility and maintainability of the code. The commit message follows the established convention of using a prefix to indicate the type of change.
This commit is contained in:
parent
22e3c86df7
commit
669237cbd9
1 changed files with 15 additions and 0 deletions
|
|
@ -119,8 +119,22 @@ class Settings(BaseSettings):
|
|||
"""Timeout for the API calls in seconds."""
|
||||
frontend_timeout: int = 0
|
||||
"""Timeout for the frontend API calls in seconds."""
|
||||
user_agent: str = "langflow"
|
||||
"""User agent for the API calls."""
|
||||
|
||||
@field_validator("user_agent", mode="after")
|
||||
@classmethod
|
||||
def set_user_agent(cls, value):
|
||||
if not value:
|
||||
value = "langflow"
|
||||
import os
|
||||
|
||||
os.environ["USER_AGENT"] = value
|
||||
logger.debug(f"Setting user agent to {value}")
|
||||
return value
|
||||
|
||||
@field_validator("config_dir", mode="before")
|
||||
@classmethod
|
||||
def set_langflow_dir(cls, value):
|
||||
if not value:
|
||||
from platformdirs import user_cache_dir
|
||||
|
|
@ -144,6 +158,7 @@ class Settings(BaseSettings):
|
|||
return str(value)
|
||||
|
||||
@field_validator("database_url", mode="before")
|
||||
@classmethod
|
||||
def set_database_url(cls, value, info):
|
||||
if not value:
|
||||
logger.debug("No database_url provided, trying LANGFLOW_DATABASE_URL env variable")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue