@@ -18,9 +18,11 @@ import os
1818from pathlib import Path
1919import runpy
2020import subprocess as proc
21+ import sys
2122import threading
2223import time
2324from time import sleep
25+ from typing import Any
2426#import warnings
2527
2628# OpenAI imports
@@ -1082,44 +1084,102 @@ class ConfigManager:
10821084
10831085
10841086 # Helper to set-up/check initial configuration
1085- def config_app (self , settings : dict ) -> None :
1087+ def config_app (self , settings : dict [ str , Any ] ) -> bool :
10861088 """
1087- Sets up initial run configuration|checks exsisting configuration.
1089+ Sets up initial run configuration and checks existing configuration.
1090+ Prompts interactively for missing values.
10881091 """
1089- # Required and optional settings
1090- REQUIRED = ("MODEL" , "TEMP" , "YOUR_NAME" , "ASSISTANT_NAME" , "OPENAI_API_KEY" , "PROMPT_ID" , "VECTOR_STORE_ID" )
1091- DEFAULTS = {"MODEL" : "gpt-5.1" , "TEMP" : 0.3 }
1092-
1093- # Prompt for missing required settings
1094- updated = False
1095- for key in REQUIRED :
1096- if key not in settings or (key == "OPENAI_API_KEY" and not settings .get (key )):
1097- if key in DEFAULTS :
1098- settings [key ] = DEFAULTS [key ]
1099- print (f"No { key } found. Using default: { settings [key ]} " )
1100- else :
1101- settings [key ] = input (f"Enter { key } : " ).strip ()
1092+
1093+ REQUIRED = (
1094+ "MODEL" ,
1095+ "YOUR_NAME" ,
1096+ "ASSISTANT_NAME" ,
1097+ "OPENAI_API_KEY" ,
1098+ "PROMPT_ID" ,
1099+ "VECTOR_STORE_ID" ,
1100+ )
1101+
1102+ DEFAULTS = {
1103+ "MODEL" : "gpt-5.1" ,
1104+ "YOUR_NAME" : "User" ,
1105+ "ASSISTANT_NAME" : "Assistant" ,
1106+ }
1107+
1108+ # Nice labels for prompts
1109+ LABELS = {
1110+ "MODEL" : "model" ,
1111+ "YOUR_NAME" : "your name" ,
1112+ "ASSISTANT_NAME" : "assistant name" ,
1113+ "OPENAI_API_KEY" : "OpenAI API key" ,
1114+ "PROMPT_ID" : "Prompt ID" ,
1115+ "VECTOR_STORE_ID" : "Vector Store ID" ,
1116+ }
1117+
1118+ first_run = not self .config_path .exists ()
1119+ updated = False
1120+ incomplete = False
1121+ missing_ids : list [str ] = []
1122+
1123+ # 1. MODEL / YOUR_NAME / ASSISTANT_NAME:
1124+ # prompt with default, allow Enter to accept default.
1125+ for key in ("MODEL" , "YOUR_NAME" , "ASSISTANT_NAME" ):
1126+ current = (settings .get (key ) or "" ).strip ()
1127+ if not current :
1128+ default = DEFAULTS [key ]
1129+ label = LABELS .get (key , key )
1130+ resp = input (f"Enter { label } [{ default } ]: " ).strip ()
1131+ settings [key ] = resp or default
1132+ print (f"Using { key } = { settings [key ]!r} " )
1133+ updated = True
1134+
1135+ # 2. IDs & API key: require a value, but allow blank with warning.
1136+ for key in ("OPENAI_API_KEY" , "PROMPT_ID" , "VECTOR_STORE_ID" ):
1137+ current = (settings .get (key ) or "" ).strip ()
1138+ if not current :
1139+ label = LABELS .get (key , key )
1140+ resp = input (f"Enter { label } (leave blank to skip for now): " ).strip ()
1141+ settings [key ] = resp # may be empty string
11021142 updated = True
1143+ if not resp :
1144+ incomplete = True
1145+ missing_ids .append (key )
11031146
1104- # Write settings file if needed
1105- if updated or not self . config_dir . exists () :
1147+ # 3. Write settings file if needed
1148+ if updated or first_run :
11061149 self .config_dir .mkdir (parents = True , exist_ok = True )
11071150 with open (self .config_path , "w" , encoding = "utf-8" ) as f :
1108- f .write ("# ~/.openai-assistant/settings.py (auto-generated by openai-assistant)\n " )
1151+ f .write (
1152+ "# ~/.openai-assistant/settings.py "
1153+ "(auto-generated by openai-assistant)\n "
1154+ )
11091155 for key in REQUIRED :
1110- val = settings [ key ]
1156+ val = settings . get ( key , "" )
11111157 if isinstance (val , str ):
11121158 f .write (f"{ key } = '{ val } '\n " )
11131159 else :
11141160 f .write (f"{ key } = { val } \n " )
1115- print (f"Wrote settings to { self .config_path } " )
1161+ print (f"Wrote settings to [cyan]{ self .config_path } [/]" )
1162+
1163+ # 4. Warn about incomplete configuration if any IDs are missing
1164+ if incomplete :
1165+ missing_str = ", " .join (missing_ids )
1166+ print (
1167+ "\n [red b][WARNING][/] Configuration is incomplete.\n "
1168+ f"Missing/empty: [#f5d676]{ missing_str } [/]\n \n "
1169+ f"You can re-run the setup by running the program again,\n "
1170+ f"or edit [cyan]{ self .config_path } [/] manually.\n "
1171+ )
1172+ return False
11161173
1174+ # 5. Ensure data directories exist
11171175 if not self .chats_dir .exists ():
11181176 self .chats_dir .mkdir (parents = True , exist_ok = True )
1119-
11201177 if not self .images_dir .exists ():
11211178 self .images_dir .mkdir (parents = True , exist_ok = True )
11221179
1180+ return True
1181+ # End
1182+
11231183
11241184 def cleanup_chat_files (self , min_size_bytes = 50 ):
11251185 """
@@ -1174,7 +1234,9 @@ def main():
11741234
11751235 # Get and load settings, prompt for missing settings
11761236 settings = config_man .load_settings ()
1177- config_man .config_app (settings )
1237+ is_config = config_man .config_app (settings )
1238+ if not is_config :
1239+ sys .exit ()
11781240
11791241 # Apply resets if requested
11801242 if args .reset_prompt :
0 commit comments