🔧 refactor(__main__.py): refactor update_settings function to accept save_api_keys parameter
✨ feat(__main__.py): add save_api_keys parameter to serve command to allow users to save API keys in their projects
The update_settings function now accepts a save_api_keys parameter, which allows the user to specify whether or not to save API keys in their projects. The serve command now has a save_api_keys parameter that defaults to True, allowing users to save API keys in their projects. This feature improves the user experience by allowing them to save API keys for future use.
This commit is contained in:
parent
dc8d2362fc
commit
e76917b53e
2 changed files with 22 additions and 7 deletions
|
|
@ -27,12 +27,19 @@ def get_number_of_workers(workers=None):
|
|||
return workers
|
||||
|
||||
|
||||
def update_settings(config: str, dev: bool = False, database_url: Optional[str] = None):
|
||||
def update_settings(
|
||||
config: str,
|
||||
dev: bool = False,
|
||||
database_url: Optional[str] = None,
|
||||
save_api_keys: bool = True,
|
||||
):
|
||||
"""Update the settings from a config file."""
|
||||
if config:
|
||||
settings.update_from_yaml(config, dev=dev)
|
||||
if database_url:
|
||||
settings.update_database_url(database_url)
|
||||
settings.update_settings(database_url=database_url)
|
||||
if save_api_keys:
|
||||
settings.update_settings(save_api_keys=save_api_keys)
|
||||
|
||||
|
||||
def serve_on_jcloud():
|
||||
|
|
@ -107,6 +114,9 @@ def serve(
|
|||
open_browser: bool = typer.Option(
|
||||
True, help="Open the browser after starting the server."
|
||||
),
|
||||
save_api_keys: bool = typer.Option(
|
||||
True, help="Save API keys in your projects for future use."
|
||||
),
|
||||
):
|
||||
"""
|
||||
Run the Langflow server.
|
||||
|
|
@ -132,7 +142,9 @@ def serve(
|
|||
load_dotenv(env_file)
|
||||
|
||||
configure(log_level=log_level, log_file=log_file)
|
||||
update_settings(config, dev=dev, database_url=database_url)
|
||||
update_settings(
|
||||
config, dev=dev, database_url=database_url, save_api_keys=save_api_keys
|
||||
)
|
||||
app = create_app()
|
||||
# get the directory of the current file
|
||||
if not path:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from typing import List, Optional
|
||||
from typing import List
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseSettings, root_validator
|
||||
|
|
@ -21,6 +21,7 @@ class Settings(BaseSettings):
|
|||
utilities: List[str] = []
|
||||
dev: bool = False
|
||||
database_url: str = "sqlite:///./langflow.db"
|
||||
save_api_keys: bool = True
|
||||
|
||||
class Config:
|
||||
validate_assignment = True
|
||||
|
|
@ -47,10 +48,12 @@ class Settings(BaseSettings):
|
|||
self.textsplitters = new_settings.textsplitters or []
|
||||
self.utilities = new_settings.utilities or []
|
||||
self.dev = dev
|
||||
self.save_api_keys = new_settings.save_api_keys
|
||||
|
||||
def update_database_url(self, database_url: Optional[str] = None):
|
||||
if database_url:
|
||||
self.database_url = database_url
|
||||
def update_settings(self, **kwargs):
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
def save_settings_to_yaml(settings: Settings, file_path: str):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue