From f0f6390366ba2f6d1060e01fd19be85417633a3c Mon Sep 17 00:00:00 2001 From: sabaimran Date: Sat, 1 Jul 2023 19:07:59 -0700 Subject: [PATCH] Make --no-gui the default behavior of Khoj and update corresponding documentation --- README.md | 25 ++++++++++++++----------- docker-compose.yml | 2 +- src/interface/emacs/khoj.el | 2 +- src/interface/obsidian/README.md | 21 ++++++++++++--------- src/khoj/main.py | 19 +++++++++++-------- src/khoj/utils/cli.py | 4 +--- tests/test_cli.py | 6 +++--- 7 files changed, 43 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 39c2965c..5868f0a6 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,17 @@ https://github.com/khoj-ai/khoj/assets/6413477/3e33d8ea-25bb-46c8-a3bf-c92f78d0f
Description -- Install Khoj via `pip` and start Khoj backend in non-gui mode -- Install Khoj plugin via Community Plugins settings pane on Obsidian app -- Check the new Khoj plugin settings -- Let Khoj backend index the markdown, pdf, Github markdown files in the current Vault -- Open Khoj plugin on Obsidian via Search button on Left Pane -- Search \"*Announce plugin to folks*\" in the [Obsidian Plugin docs](https://marcus.se.net/obsidian-plugin-docs/) -- Jump to the [search result](https://marcus.se.net/obsidian-plugin-docs/publishing/submit-your-plugin) +1. Install Khoj via `pip` and start Khoj backend in a terminal (Run `khoj`) + ``` + python -m pip install khoj-assistant + khoj + ``` +2. Install Khoj plugin via Community Plugins settings pane on Obsidian app + - Check the new Khoj plugin settings + - Let Khoj backend index the markdown, pdf, Github markdown files in the current Vault + - Open Khoj plugin on Obsidian via Search button on Left Pane + - Search \"*Announce plugin to folks*\" in the [Obsidian Plugin docs](https://marcus.se.net/obsidian-plugin-docs/) + - Jump to the [search result](https://marcus.se.net/obsidian-plugin-docs/publishing/submit-your-plugin)
### Khoj in Emacs, Browser @@ -160,7 +164,7 @@ The optional steps below allow using Khoj from within an existing application li - **Khoj via Emacs** - Run `M-x khoj ` - **Khoj via Web** - - Open via desktop interface or directly + - Open directly - **Khoj via API** - See the Khoj FastAPI [Swagger Docs](http://localhost:8000/docs), [ReDocs](http://localhost:8000/redocs) @@ -308,8 +312,7 @@ pip install --upgrade --pre khoj-assistant ### Set your OpenAI API key in Khoj If you want, Khoj can be configured to use OpenAI for search and chat.
Add your OpenAI API to Khoj by using either of the two options below: - - Open the Khoj desktop GUI, add your [OpenAI API key](https://beta.openai.com/account/api-keys) and click *Configure* - Ensure khoj is started **without** the `--no-gui` flag. Check your system tray to see if Khoj is minimized there. + - Open your [Khoj settings](http://localhost:8000/config/processor/conversation), add your OpenAI API key, and click *Save*. Then go to your [Khoj settings](http://localhost:8000/config) and click `Configure`. This will refresh Khoj with your OpenAI API key. - Set `openai-api-key` field under `processor.conversation` section in your `khoj.yml`[^1] to your [OpenAI API key](https://beta.openai.com/account/api-keys) and restart khoj: ```diff processor: @@ -388,7 +391,7 @@ pip install -e .[dev] khoj -vv ``` 2. Configure Khoj - - **Via GUI**: Add files, directories to index in the GUI window that pops up on starting Khoj, then Click Configure + - **Via the Settings UI**: Add files, directories to index the [Khoj settings](http://localhost:8000/config) UI once Khoj has started up. Once you've saved all your settings, click `Configure`. - **Manually**: - Copy the `config/khoj_sample.yml` to `~/.khoj/khoj.yml` - Set `input-files` or `input-filter` in each relevant `content-type` section of `~/.khoj/khoj.yml` diff --git a/docker-compose.yml b/docker-compose.yml index 03b74444..84f8d3f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,4 +27,4 @@ services: - ./tests/data/embeddings/:/data/embeddings/ - ./tests/data/models/:/data/models/ # Use 0.0.0.0 to explicitly set the host ip for the service on the container. https://pythonspeed.com/articles/docker-connection-refused/ - command: --no-gui --host="0.0.0.0" --port=8000 -c=config/khoj_docker.yml -vv + command: --host="0.0.0.0" --port=8000 -c=config/khoj_docker.yml -vv diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 41ac0aaf..6f08ab9c 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -197,7 +197,7 @@ Use `which-key` if available, else display simple message in echo area" :type 'string :group 'khoj) -(defcustom khoj-server-args '("--no-gui") +(defcustom khoj-server-args '() "Arguments to pass to Khoj server on startup." :type '(repeat string) :group 'khoj) diff --git a/src/interface/obsidian/README.md b/src/interface/obsidian/README.md index 1cb72006..f2d664d3 100644 --- a/src/interface/obsidian/README.md +++ b/src/interface/obsidian/README.md @@ -40,13 +40,16 @@ https://github.com/khoj-ai/khoj/assets/6413477/3e33d8ea-25bb-46c8-a3bf-c92f78d0f
Description -1. Install Khoj via `pip` and start Khoj backend in non-gui mode +1. Install Khoj via `pip` and start Khoj backend + ```shell + python -m pip install khoj-assistant && khoj + ``` 2. Install Khoj plugin via Community Plugins settings pane on Obsidian app -3. Check the new Khoj plugin settings -4. Wait for Khoj backend to index markdown, PDF files in the current Vault -5. Open Khoj plugin on Obsidian via Search button on Left Pane -6. Search \"*Announce plugin to folks*\" in the [Obsidian Plugin docs](https://marcus.se.net/obsidian-plugin-docs/) -7. Jump to the [search result](https://marcus.se.net/obsidian-plugin-docs/publishing/submit-your-plugin) + - Check the new Khoj plugin settings + - Wait for Khoj backend to index markdown, PDF files in the current Vault + - Open Khoj plugin on Obsidian via Search button on Left Pane + - Search \"*Announce plugin to folks*\" in the [Obsidian Plugin docs](https://marcus.se.net/obsidian-plugin-docs/) + - Jump to the [search result](https://marcus.se.net/obsidian-plugin-docs/publishing/submit-your-plugin)
@@ -65,12 +68,12 @@ https://github.com/khoj-ai/khoj/assets/6413477/3e33d8ea-25bb-46c8-a3bf-c92f78d0f Open terminal/cmd and run below command to install and start the khoj backend - On Linux/MacOS ```shell - python -m pip install khoj-assistant && khoj --no-gui + python -m pip install khoj-assistant && khoj ``` - On Windows ```shell - py -m pip install khoj-assistant && khoj --no-gui + py -m pip install khoj-assistant && khoj ``` ### 2. Setup Plugin @@ -96,7 +99,7 @@ See [Khoj Chat](https://github.com/khoj-ai/khoj/tree/master/#Khoj-Chat) for more ### Search Click the *Khoj search* icon 🔎 on the [Ribbon](https://help.obsidian.md/User+interface/Workspace/Ribbon) or run *Khoj: Search* from the [Command Palette](https://help.obsidian.md/Plugins/Command+palette) -*Note: Ensure the khoj server is running in the background before searching. Execute `khoj --no-gui` in your terminal if it is not already running* +*Note: Ensure the khoj server is running in the background before searching. Execute `khoj` in your terminal if it is not already running* https://user-images.githubusercontent.com/6413477/218801155-cd67e8b4-a770-404a-8179-d6b61caa0f93.mp4 diff --git a/src/khoj/main.py b/src/khoj/main.py index 5c2c71c0..b989c2d6 100644 --- a/src/khoj/main.py +++ b/src/khoj/main.py @@ -63,14 +63,8 @@ def run(): logger.info("🌘 Starting Khoj") - if args.no_gui: - # Setup task scheduler - poll_task_scheduler() - # Start Server - configure_server(args, required=False) - configure_routes(app) - start_server(app, host=args.host, port=args.port, socket=args.socket) - else: + if args.gui: + logger.warning("🚧 GUI is being deprecated and may not work as expected. Starting...") # Setup GUI gui = QtWidgets.QApplication([]) main_window = MainWindow(args.config_file) @@ -118,6 +112,15 @@ def run(): gui.exec() + if not state.demo: + # Setup task scheduler + poll_task_scheduler() + + # Start Server + configure_server(args, required=False) + configure_routes(app) + start_server(app, host=args.host, port=args.port, socket=args.socket) + def sigint_handler(*args): QtWidgets.QApplication.quit() diff --git a/src/khoj/utils/cli.py b/src/khoj/utils/cli.py index ba0ef971..535e664b 100644 --- a/src/khoj/utils/cli.py +++ b/src/khoj/utils/cli.py @@ -16,9 +16,7 @@ def cli(args=None): parser.add_argument( "--config-file", "-c", default="~/.khoj/khoj.yml", type=pathlib.Path, help="YAML file to configure Khoj" ) - parser.add_argument( - "--no-gui", action="store_true", default=False, help="Do not show native desktop GUI. Default: false" - ) + parser.add_argument("--gui", action="store_true", default=False, help="Show native desktop GUI. Default: false") parser.add_argument( "--regenerate", action="store_true", diff --git a/tests/test_cli.py b/tests/test_cli.py index 98b2353c..c96e57bd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,7 +16,7 @@ def test_cli_minimal_default(): # Assert assert actual_args.config_file == resolve_absolute_path(Path("~/.khoj/khoj.yml")) assert actual_args.regenerate == False - assert actual_args.no_gui == False + assert actual_args.gui == False assert actual_args.verbose == 0 @@ -36,11 +36,11 @@ def test_cli_invalid_config_file_path(): # ---------------------------------------------------------------------------------------------------- def test_cli_config_from_file(): # Act - actual_args = cli(["-c=tests/data/config.yml", "--regenerate", "--no-gui", "-vvv"]) + actual_args = cli(["-c=tests/data/config.yml", "--regenerate", "-vvv"]) # Assert assert actual_args.config_file == resolve_absolute_path(Path("tests/data/config.yml")) - assert actual_args.no_gui == True + assert actual_args.gui == False assert actual_args.regenerate == True assert actual_args.config is not None assert actual_args.verbose == 3