Skip to content

Commit 5cbee2a

Browse files
committed
Configurable verbose logging
1 parent 78569cd commit 5cbee2a

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

selfie-ui/src/app/components/Settings/Settings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ const Settings = () => {
2525
enumNames: ['Local (llama.cpp)', 'Other (litellm)'],
2626
default: "llama.cpp"
2727
},
28+
verbose_logging: { type: "boolean", title: "Verbose logging", default: false },
2829
// name: { type: "string", title: "Name" },
2930
// description: { type: "string", title: "Description" },
3031
// apiKey: { type: "string", title: "API Key" },
3132
// host: { type: "string", title: "Host", default: "http://localhost" },
3233
// port: { type: "integer", title: "Port", default: 8000 },
3334
// share: { type: "boolean", title: "Share", default: false },
34-
// verbose: { type: "boolean", title: "Verbose", default: false },
3535
},
3636
allOf: [
3737
{
@@ -128,7 +128,7 @@ const Settings = () => {
128128
console.log(models)
129129

130130
const uiSchema = {
131-
'ui:order': ['gpu', 'ngrok_enabled', 'ngrok_authtoken', 'ngrok_domain', '*'],
131+
'ui:order': ['gpu', 'ngrok_enabled', 'ngrok_authtoken', 'ngrok_domain', '*', 'verbose_logging'],
132132

133133
method: {
134134
"ui:widget": "radio",

selfie/__main__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def deserialize_args_from_env():
3232
'api_port': ('SELFIE_API_PORT', int),
3333
'gpu': ('SELFIE_GPU', to_bool),
3434
'reload': ('SELFIE_RELOAD', to_bool),
35-
'verbose': ('SELFIE_VERBOSE', to_bool),
35+
'verbose_logging': ('SELFIE_VERBOSE_LOGGING', to_bool),
3636
'headless': ('SELFIE_HEADLESS', to_bool),
3737
'model': ('SELFIE_MODEL', str),
3838
}
@@ -61,7 +61,7 @@ def parse_args():
6161
parser.add_argument("--api_port", type=int, default=None, help="Specify the port to run on")
6262
parser.add_argument("--gpu", default=None, action="store_true", help="Enable GPU support")
6363
parser.add_argument("--reload", action="store_true", default=None, help="Enable hot-reloading")
64-
parser.add_argument("--verbose", action="store_true", default=None, help="Enable verbose logging")
64+
parser.add_argument("--verbose_logging", action="store_true", default=None, help="Enable verbose logging")
6565
parser.add_argument("--headless", action="store_true", default=None, help="Run in headless mode (no GUI)")
6666
parser.add_argument("--model", type=str, default=None, help="Specify the model to use")
6767
args = parser.parse_args()
@@ -74,12 +74,15 @@ def get_configured_app(shareable=False):
7474

7575
logger.info(f"Running with args: {args}")
7676

77-
if 'verbose' in args and args.verbose:
77+
if 'verbose_logging' in args and args.verbose_logging:
7878
logging.getLogger("selfie").setLevel(level=logging.DEBUG)
7979

8080
logger.info("Creating app configuration")
8181
app_config = create_app_config(**vars(args))
8282

83+
if app_config.verbose_logging:
84+
logging.getLogger("selfie").setLevel(level=logging.DEBUG)
85+
8386
if shareable and app_config.ngrok_enabled:
8487
if app_config.ngrok_authtoken is None:
8588
raise ValueError("ngrok_authtoken is required to share the API.")

selfie/config.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
default_hosted_model = 'openai/gpt-3.5-turbo'
1818
default_local_gpu_model = 'TheBloke/Mistral-7B-OpenOrca-GPTQ'
1919

20-
ensure_set_in_db = ['gpu', 'method', 'model']
20+
ensure_set_in_db = ['gpu', 'method', 'model', 'verbose_logging']
2121

2222

2323
# TODO: This is not accurate, e.g. if the user starts the app with --gpu
@@ -36,7 +36,7 @@ class AppConfig(BaseModel):
3636
api_port: Optional[int] = Field(default=default_port, description="Specify the port to run on")
3737
share: bool = Field(default=False, description="Enable sharing via ngrok")
3838
gpu: bool = Field(default=get_default_gpu_mode(), description="Enable GPU support")
39-
verbose: bool = Field(default=False, description="Enable verbose logging")
39+
verbose_logging: bool = Field(default=False, description="Enable verbose logging")
4040
db_name: str = Field(default='selfie.db', description="Database name")
4141
method: str = Field(default=default_method, description="LLM provider method, llama.cpp or litellm")
4242
model: str = Field(default=default_local_model, description="Local model")
@@ -125,16 +125,13 @@ def create_app_config(**kwargs):
125125
config_dict[key] = value
126126
runtime_overrides[key] = value
127127

128-
db_update_required = False
129-
updates = {}
130128
for field in ensure_set_in_db:
129+
updates = {}
131130
if field not in db_config or db_config[field] is None:
132-
db_update_required = True
133-
logger.info(f"No saved setting for {field}, saving {config_dict[field]}") # Corrected access method
131+
logger.info(f"No saved setting for {field}, saving {config_dict[field]}")
134132
updates[field] = config_dict[field]
135-
136-
if db_update_required:
137-
update_config_in_database(updates)
133+
if updates:
134+
update_config_in_database(updates)
138135

139136
global _singleton_instance
140137
logger.info(f"Creating AppConfig with: {config_dict}")
@@ -150,9 +147,9 @@ def load_config_from_database():
150147
return DataManager().get_settings()
151148

152149

153-
def update_config_in_database(settings):
150+
def update_config_in_database(settings, delete_others=False):
154151
from selfie.database import DataManager
155-
DataManager().save_settings(settings, delete_others=True)
152+
DataManager().save_settings(settings, delete_others=delete_others)
156153

157154

158155
def get_app_config():

selfie/embeddings/importance_scorer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def calculate_raw_score(self, document: EmbeddingDocumentModel):
4545

4646
llm = LLM(
4747
config.local_functionary_model,
48-
verbose=config.verbose,
48+
verbose=config.verbose_logging,
4949
n_gpu_layers=-1 if config.gpu else 0,
5050
method="llama.cpp",
5151
chat_format="functionary",

selfie/logging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def setup_logging():
1919
logger.setLevel(level)
2020

2121
file_handler = RotatingFileHandler(log_path, maxBytes=1024*1024, backupCount=5)
22-
file_handler.setLevel(level)
22+
file_handler.setLevel(logging.DEBUG)
2323
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
2424
file_handler.setFormatter(formatter)
2525

2626
logger.addHandler(file_handler)
2727

28-
2928
setup_logging()

selfie/text_generation/generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def completion(request: CompletionRequest | ChatCompletionRequest) -> Self
5656
if method == "llama.cpp":
5757
model = request.model or config.model
5858
logger.info(f"Using llama.cpp model {model}")
59-
llm = get_llama_cpp_llm(model, config.verbose, config.gpu)
59+
llm = get_llama_cpp_llm(model, config.verbose_logging, config.gpu)
6060

6161
completion_fn = (llm.create_chat_completion if chat_mode else llm.create_completion)
6262

0 commit comments

Comments
 (0)