mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Configure API routes after set up search types while configuring server
Configure app routes after configuring server. Import API routers after search type is dynamically populated. Allow API to recognize the dynamically populated plugin search types as valid type query param. Enable searching for plugin type content.
This commit is contained in:
parent
d91c7e2761
commit
68bd5d9ebc
3 changed files with 20 additions and 11 deletions
|
@ -6,6 +6,7 @@ from enum import Enum
|
|||
|
||||
# External Packages
|
||||
import schedule
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
# Internal Packages
|
||||
from khoj.processor.ledger.beancount_to_jsonl import BeancountToJsonl
|
||||
|
@ -13,8 +14,8 @@ from khoj.processor.jsonl.jsonl_to_jsonl import JsonlToJsonl
|
|||
from khoj.processor.markdown.markdown_to_jsonl import MarkdownToJsonl
|
||||
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
|
||||
from khoj.search_type import image_search, text_search
|
||||
from khoj.utils import constants, state
|
||||
from khoj.utils.config import SearchType, SearchModels, ProcessorConfigModel, ConversationProcessorConfigModel
|
||||
from khoj.utils import state
|
||||
from khoj.utils.helpers import LRU, resolve_absolute_path, merge_dicts
|
||||
from khoj.utils.rawconfig import FullConfig, ProcessorConfig
|
||||
from khoj.search_filter.date_filter import DateFilter
|
||||
|
@ -48,6 +49,18 @@ def configure_server(args, required=False):
|
|||
state.search_index_lock.release()
|
||||
|
||||
|
||||
def configure_routes(app):
|
||||
# Import APIs here to setup search types before while configuring server
|
||||
from khoj.routers.api import api
|
||||
from khoj.routers.api_beta import api_beta
|
||||
from khoj.routers.web_client import web_client
|
||||
|
||||
app.mount("/static", StaticFiles(directory=constants.web_directory), name="static")
|
||||
app.include_router(api, prefix="/api")
|
||||
app.include_router(api_beta, prefix="/api/beta")
|
||||
app.include_router(web_client)
|
||||
|
||||
|
||||
@schedule.repeat(schedule.every(1).hour)
|
||||
def update_search_index():
|
||||
state.search_index_lock.acquire()
|
||||
|
|
|
@ -14,18 +14,14 @@ warnings.filterwarnings("ignore", message=r"legacy way to download files from th
|
|||
# External Packages
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtCore import QThread, QTimer
|
||||
from rich.logging import RichHandler
|
||||
import schedule
|
||||
|
||||
# Internal Packages
|
||||
from khoj.configure import configure_server
|
||||
from khoj.routers.api import api
|
||||
from khoj.routers.api_beta import api_beta
|
||||
from khoj.routers.web_client import web_client
|
||||
from khoj.utils import constants, state
|
||||
from khoj.configure import configure_routes, configure_server
|
||||
from khoj.utils import state
|
||||
from khoj.utils.cli import cli
|
||||
from khoj.interface.desktop.main_window import MainWindow
|
||||
from khoj.interface.desktop.system_tray import create_system_tray
|
||||
|
@ -33,10 +29,6 @@ from khoj.interface.desktop.system_tray import create_system_tray
|
|||
|
||||
# Initialize the Application Server
|
||||
app = FastAPI()
|
||||
app.mount("/static", StaticFiles(directory=constants.web_directory), name="static")
|
||||
app.include_router(api, prefix="/api")
|
||||
app.include_router(api_beta, prefix="/api/beta")
|
||||
app.include_router(web_client)
|
||||
|
||||
# Setup Logger
|
||||
rich_handler = RichHandler(rich_tracebacks=True)
|
||||
|
@ -78,6 +70,7 @@ def run():
|
|||
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
|
||||
|
@ -95,6 +88,7 @@ def run():
|
|||
|
||||
# Setup Server
|
||||
configure_server(args, required=False)
|
||||
configure_routes(app)
|
||||
server = ServerThread(app, args.host, args.port, args.socket)
|
||||
|
||||
# Show Main Window on First Run Experience or if on Linux
|
||||
|
|
|
@ -9,6 +9,7 @@ from fastapi.testclient import TestClient
|
|||
|
||||
# Internal Packages
|
||||
from khoj.main import app
|
||||
from khoj.configure import configure_routes
|
||||
from khoj.utils.state import model, config
|
||||
from khoj.search_type import text_search, image_search
|
||||
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
||||
|
@ -19,6 +20,7 @@ from khoj.search_filter.file_filter import FileFilter
|
|||
|
||||
# Arrange
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
configure_routes(app)
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue