Make --no-gui the default behavior of Khoj and update corresponding documentation

This commit is contained in:
sabaimran 2023-07-01 19:07:59 -07:00
parent 2fbc609233
commit f0f6390366
7 changed files with 43 additions and 36 deletions

View file

@ -73,8 +73,12 @@ https://github.com/khoj-ai/khoj/assets/6413477/3e33d8ea-25bb-46c8-a3bf-c92f78d0f
<details><summary>Description</summary> <details><summary>Description</summary>
- Install Khoj via `pip` and start Khoj backend in non-gui mode 1. Install Khoj via `pip` and start Khoj backend in a terminal (Run `khoj`)
- Install Khoj plugin via Community Plugins settings pane on Obsidian app ```
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 - Check the new Khoj plugin settings
- Let Khoj backend index the markdown, pdf, Github markdown files in the current Vault - 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 - Open Khoj plugin on Obsidian via Search button on Left Pane
@ -160,7 +164,7 @@ The optional steps below allow using Khoj from within an existing application li
- **Khoj via Emacs** - **Khoj via Emacs**
- Run `M-x khoj <user-query>` - Run `M-x khoj <user-query>`
- **Khoj via Web** - **Khoj via Web**
- Open <http://localhost:8000/> via desktop interface or directly - Open <http://localhost:8000/> directly
- **Khoj via API** - **Khoj via API**
- See the Khoj FastAPI [Swagger Docs](http://localhost:8000/docs), [ReDocs](http://localhost:8000/redocs) - 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 ### Set your OpenAI API key in Khoj
If you want, Khoj can be configured to use OpenAI for search and chat.<br /> If you want, Khoj can be configured to use OpenAI for search and chat.<br />
Add your OpenAI API to Khoj by using either of the two options below: 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* - 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.
Ensure khoj is started **without** the `--no-gui` flag. Check your system tray to see if Khoj is minimized there.
- 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: - 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 ```diff
processor: processor:
@ -388,7 +391,7 @@ pip install -e .[dev]
khoj -vv khoj -vv
``` ```
2. Configure Khoj 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**: - **Manually**:
- Copy the `config/khoj_sample.yml` to `~/.khoj/khoj.yml` - 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` - Set `input-files` or `input-filter` in each relevant `content-type` section of `~/.khoj/khoj.yml`

View file

@ -27,4 +27,4 @@ services:
- ./tests/data/embeddings/:/data/embeddings/ - ./tests/data/embeddings/:/data/embeddings/
- ./tests/data/models/:/data/models/ - ./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/ # 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

View file

@ -197,7 +197,7 @@ Use `which-key` if available, else display simple message in echo area"
:type 'string :type 'string
:group 'khoj) :group 'khoj)
(defcustom khoj-server-args '("--no-gui") (defcustom khoj-server-args '()
"Arguments to pass to Khoj server on startup." "Arguments to pass to Khoj server on startup."
:type '(repeat string) :type '(repeat string)
:group 'khoj) :group 'khoj)

View file

@ -40,13 +40,16 @@ https://github.com/khoj-ai/khoj/assets/6413477/3e33d8ea-25bb-46c8-a3bf-c92f78d0f
<details><summary>Description</summary> <details><summary>Description</summary>
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 2. Install Khoj plugin via Community Plugins settings pane on Obsidian app
3. Check the new Khoj plugin settings - Check the new Khoj plugin settings
4. Wait for Khoj backend to index markdown, PDF files in the current Vault - 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 - 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/) - 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) - Jump to the [search result](https://marcus.se.net/obsidian-plugin-docs/publishing/submit-your-plugin)
</details> </details>
@ -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 Open terminal/cmd and run below command to install and start the khoj backend
- On Linux/MacOS - On Linux/MacOS
```shell ```shell
python -m pip install khoj-assistant && khoj --no-gui python -m pip install khoj-assistant && khoj
``` ```
- On Windows - On Windows
```shell ```shell
py -m pip install khoj-assistant && khoj --no-gui py -m pip install khoj-assistant && khoj
``` ```
### 2. Setup Plugin ### 2. Setup Plugin
@ -96,7 +99,7 @@ See [Khoj Chat](https://github.com/khoj-ai/khoj/tree/master/#Khoj-Chat) for more
### Search ### 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) 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 https://user-images.githubusercontent.com/6413477/218801155-cd67e8b4-a770-404a-8179-d6b61caa0f93.mp4

View file

@ -63,14 +63,8 @@ def run():
logger.info("🌘 Starting Khoj") logger.info("🌘 Starting Khoj")
if args.no_gui: if args.gui:
# Setup task scheduler logger.warning("🚧 GUI is being deprecated and may not work as expected. Starting...")
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:
# Setup GUI # Setup GUI
gui = QtWidgets.QApplication([]) gui = QtWidgets.QApplication([])
main_window = MainWindow(args.config_file) main_window = MainWindow(args.config_file)
@ -118,6 +112,15 @@ def run():
gui.exec() 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): def sigint_handler(*args):
QtWidgets.QApplication.quit() QtWidgets.QApplication.quit()

View file

@ -16,9 +16,7 @@ def cli(args=None):
parser.add_argument( parser.add_argument(
"--config-file", "-c", default="~/.khoj/khoj.yml", type=pathlib.Path, help="YAML file to configure Khoj" "--config-file", "-c", default="~/.khoj/khoj.yml", type=pathlib.Path, help="YAML file to configure Khoj"
) )
parser.add_argument( parser.add_argument("--gui", action="store_true", default=False, help="Show native desktop GUI. Default: false")
"--no-gui", action="store_true", default=False, help="Do not show native desktop GUI. Default: false"
)
parser.add_argument( parser.add_argument(
"--regenerate", "--regenerate",
action="store_true", action="store_true",

View file

@ -16,7 +16,7 @@ def test_cli_minimal_default():
# Assert # Assert
assert actual_args.config_file == resolve_absolute_path(Path("~/.khoj/khoj.yml")) assert actual_args.config_file == resolve_absolute_path(Path("~/.khoj/khoj.yml"))
assert actual_args.regenerate == False assert actual_args.regenerate == False
assert actual_args.no_gui == False assert actual_args.gui == False
assert actual_args.verbose == 0 assert actual_args.verbose == 0
@ -36,11 +36,11 @@ def test_cli_invalid_config_file_path():
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
def test_cli_config_from_file(): def test_cli_config_from_file():
# Act # 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
assert actual_args.config_file == resolve_absolute_path(Path("tests/data/config.yml")) 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.regenerate == True
assert actual_args.config is not None assert actual_args.config is not None
assert actual_args.verbose == 3 assert actual_args.verbose == 3