mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 13:20:17 +00:00
Update the new /config APIs to configure Khoj for first time users
- Setup state.config and sub-components from unset state - Setup search types with default settings
This commit is contained in:
@@ -16,7 +16,10 @@ from khoj.processor.conversation.utils import message_to_log, message_to_prompt
|
||||
from khoj.search_type import image_search, text_search
|
||||
from khoj.utils.helpers import log_telemetry, timer
|
||||
from khoj.utils.rawconfig import (
|
||||
ContentConfig,
|
||||
FullConfig,
|
||||
ProcessorConfig,
|
||||
SearchConfig,
|
||||
SearchResponse,
|
||||
TextContentConfig,
|
||||
ConversationProcessorConfig,
|
||||
@@ -74,7 +77,10 @@ async def set_config_data(updated_config: FullConfig):
|
||||
|
||||
@api.post("/config/data/content_type/github", status_code=200)
|
||||
async def set_content_config_github_data(updated_config: GithubContentConfig):
|
||||
state.config.content_type.github = updated_config
|
||||
if not state.config:
|
||||
state.config = FullConfig()
|
||||
state.config.search_type = SearchConfig.parse_obj(constants.default_config["search-type"])
|
||||
state.config.content_type = ContentConfig(github=updated_config)
|
||||
try:
|
||||
save_config_to_file_updated_state()
|
||||
return {"status": "ok"}
|
||||
@@ -84,7 +90,10 @@ async def set_content_config_github_data(updated_config: GithubContentConfig):
|
||||
|
||||
@api.post("/config/data/content_type/{content_type}", status_code=200)
|
||||
async def set_content_config_data(content_type: str, updated_config: TextContentConfig):
|
||||
state.config.content_type[content_type] = updated_config
|
||||
if not state.config:
|
||||
state.config = FullConfig()
|
||||
state.config.search_type = SearchConfig.parse_obj(constants.default_config["search-type"])
|
||||
state.config.content_type = ContentConfig(**{content_type: updated_config})
|
||||
try:
|
||||
save_config_to_file_updated_state()
|
||||
return {"status": "ok"}
|
||||
@@ -94,7 +103,10 @@ async def set_content_config_data(content_type: str, updated_config: TextContent
|
||||
|
||||
@api.post("/config/data/processor/conversation", status_code=200)
|
||||
async def set_processor_conversation_config_data(updated_config: ConversationProcessorConfig):
|
||||
state.config.processor.conversation = updated_config
|
||||
if not state.config:
|
||||
state.config = FullConfig()
|
||||
state.config.search_type = SearchConfig.parse_obj(constants.default_config["search-type"])
|
||||
state.config.processor = ProcessorConfig(conversation=updated_config)
|
||||
try:
|
||||
save_config_to_file_updated_state()
|
||||
return {"status": "ok"}
|
||||
|
||||
@@ -41,7 +41,7 @@ def github_config_page(request: Request):
|
||||
)
|
||||
|
||||
current_config = (
|
||||
state.config.content_type.github if state.config.content_type.github is not None else default_config
|
||||
state.config.content_type.github if state.config and state.config.content_type.github else default_config
|
||||
)
|
||||
|
||||
current_config = json.loads(current_config.json())
|
||||
@@ -65,7 +65,7 @@ def content_config_page(request: Request, content_type: str):
|
||||
)
|
||||
current_config = (
|
||||
state.config.content_type[content_type]
|
||||
if state.config.content_type[content_type] is not None
|
||||
if state.config and content_type in state.config.content_type
|
||||
else default_config
|
||||
)
|
||||
current_config = json.loads(current_config.json())
|
||||
@@ -93,7 +93,7 @@ def conversation_processor_config_page(request: Request):
|
||||
|
||||
current_processor_conversation_config = (
|
||||
state.config.processor.conversation
|
||||
if state.config.processor.conversation is not None
|
||||
if state.config and state.config.processor.conversation
|
||||
else default_processor_config
|
||||
)
|
||||
current_processor_conversation_config = json.loads(current_processor_conversation_config.json())
|
||||
|
||||
Reference in New Issue
Block a user