11"""OpenKB CLI — command-line interface for the knowledge base workflow."""
22from __future__ import annotations
33
4+ # Silence import-time warnings (e.g. pydub's missing-ffmpeg warning emitted
5+ # when markitdown pulls it in). markitdown later clobbers the filters during
6+ # its own import, so we re-apply after all imports below.
7+ import warnings
8+ warnings .filterwarnings ("ignore" )
9+
410import asyncio
511import json
612import logging
@@ -256,22 +262,23 @@ def init():
256262 return
257263
258264 # Interactive prompts
265+ click .echo ("Pick an LLM in `provider/model` LiteLLM format:" )
266+ click .echo (" OpenAI: gpt-5.4-mini, gpt-5.4" )
267+ click .echo (" Anthropic: anthropic/claude-sonnet-4-6, anthropic/claude-opus-4-6" )
268+ click .echo (" Gemini: gemini/gemini-3.1-pro-preview, gemini/gemini-3-flash-preview" )
269+ click .echo (" Others: see https://docs.litellm.ai/docs/providers" )
270+ click .echo ()
259271 model = click .prompt (
260- f"Model (e.g. gpt-5.4-mini, anthropic/claude-sonnet-4-6) [ default: { DEFAULT_CONFIG ['model' ]} ] " ,
272+ f"Model (enter for default { DEFAULT_CONFIG ['model' ]} ) " ,
261273 default = DEFAULT_CONFIG ["model" ],
262274 show_default = False ,
263275 )
264- language = click .prompt (
265- f"Language [default: { DEFAULT_CONFIG ['language' ]} ]" ,
266- default = DEFAULT_CONFIG ["language" ],
267- show_default = False ,
268- )
269- pageindex_threshold = click .prompt (
270- f"PageIndex threshold (pages) [default: { DEFAULT_CONFIG ['pageindex_threshold' ]} ]" ,
271- default = DEFAULT_CONFIG ["pageindex_threshold" ],
272- type = int ,
276+ api_key = click .prompt (
277+ "LLM API Key (saved to .env, enter to skip)" ,
278+ default = "" ,
279+ hide_input = True ,
273280 show_default = False ,
274- )
281+ ). strip ()
275282 # Create directory structure
276283 Path ("raw" ).mkdir (exist_ok = True )
277284 Path ("wiki/sources/images" ).mkdir (parents = True , exist_ok = True )
@@ -290,12 +297,22 @@ def init():
290297 openkb_dir .mkdir ()
291298 config = {
292299 "model" : model ,
293- "language" : language ,
294- "pageindex_threshold" : pageindex_threshold ,
300+ "language" : DEFAULT_CONFIG [ " language" ] ,
301+ "pageindex_threshold" : DEFAULT_CONFIG [ " pageindex_threshold" ] ,
295302 }
296303 save_config (openkb_dir / "config.yaml" , config )
297304 (openkb_dir / "hashes.json" ).write_text (json .dumps ({}), encoding = "utf-8" )
298305
306+ # Write API key to KB-local .env (0600) if the user provided one
307+ if api_key :
308+ env_path = Path (".env" )
309+ if env_path .exists ():
310+ click .echo (".env already exists, skipping write. Add LLM_API_KEY manually if needed." )
311+ else :
312+ env_path .write_text (f"LLM_API_KEY={ api_key } \n " , encoding = "utf-8" )
313+ os .chmod (env_path , 0o600 )
314+ click .echo ("Saved LLM API key to .env." )
315+
299316 # Register this KB in the global config
300317 register_kb (Path .cwd ())
301318
0 commit comments