Log usage of /search, /chat, /update API endpoints to telemetry server

This commit is contained in:
Debanjum Singh Solanky 2023-05-15 20:58:51 +08:00
parent f2e89f6f46
commit 3ede919c66

View file

@ -14,7 +14,7 @@ from khoj.configure import configure_processor, configure_search
from khoj.processor.conversation.gpt import converse, extract_questions
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 timer
from khoj.utils.helpers import log_telemetry, timer
from khoj.utils.rawconfig import FullConfig, SearchResponse
from khoj.utils.state import SearchType
from khoj.utils import state, constants
@ -168,6 +168,8 @@ def search(
# Cache results
state.query_cache[query_cache_key] = results
log_telemetry(telemetry_type="api", api="search", app_config=state.config.app)
return results
@ -191,6 +193,8 @@ def update(t: Optional[SearchType] = None, force: Optional[bool] = False):
else:
logger.info("📬 Processor reconfigured via API")
log_telemetry(telemetry_type="api", api="update", app_config=state.config.app)
return {"status": "ok", "message": "khoj reloaded"}
@ -251,4 +255,6 @@ def chat(q: Optional[str] = None):
conversation_log=meta_log.get("chat", []),
)
log_telemetry(telemetry_type="api", api="chat", app_config=state.config.app)
return {"status": status, "response": gpt_response, "context": compiled_references}