From b950889f47df613d2a69d8143ebc5a55099f066b Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 29 Jun 2023 19:01:25 -0700 Subject: [PATCH 1/2] Fix org-mode web renderer to handle results containing list in block - Break out of rendering list if at end of org block in org.js - This would previous hang rendering results in web interface Should try fix this upstream in org.js as well --- src/khoj/interface/web/assets/org.min.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/khoj/interface/web/assets/org.min.js b/src/khoj/interface/web/assets/org.min.js index 0a870c9c..a919b280 100644 --- a/src/khoj/interface/web/assets/org.min.js +++ b/src/khoj/interface/web/assets/org.min.js @@ -614,8 +614,10 @@ var Org = (function () { var notBlankNextToken = this.lexer.peekNextToken(); if (blankToken && !notBlankNextToken.isListElement()) this.lexer.pushToken(blankToken); // Recover blank token only when next line is not listElement. - if (notBlankNextToken.indentation <= rootIndentation) - break; // end of the list + // End of the list if hit less indented line or end of directive + if (notBlankNextToken.indentation <= rootIndentation || + (notBlankNextToken.type === Lexer.tokens.directive && notBlankNextToken.endDirective)) + break; var element = this.parseElement(); // recursive if (element) From ef7250891401e4215fa02644e6f560f12b392c35 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Fri, 30 Jun 2023 00:23:21 -0700 Subject: [PATCH 2/2] Try/catch around github file decoding, await call to search in chat API, fix img width --- src/khoj/interface/web/index.html | 4 ++++ src/khoj/processor/github/github_to_jsonl.py | 5 ++++- src/khoj/routers/api.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/khoj/interface/web/index.html b/src/khoj/interface/web/index.html index 7a0f896c..49929b45 100644 --- a/src/khoj/interface/web/index.html +++ b/src/khoj/interface/web/index.html @@ -414,6 +414,10 @@ border: 1px solid rgb(229, 229, 229); } + img { + max-width: 90%; + } + diff --git a/src/khoj/processor/github/github_to_jsonl.py b/src/khoj/processor/github/github_to_jsonl.py index 70ea7bf2..6f21749d 100644 --- a/src/khoj/processor/github/github_to_jsonl.py +++ b/src/khoj/processor/github/github_to_jsonl.py @@ -152,7 +152,10 @@ class GithubToJsonl(TextToJsonl): content = "" for chunk in response.iter_content(chunk_size=2048): if chunk: - content += chunk.decode("utf-8") + try: + content += chunk.decode("utf-8") + except Exception as e: + logger.error(f"Unable to decode chunk from {file_url}") return content diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 6bc266aa..71fd2783 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -362,7 +362,7 @@ def update(t: Optional[SearchType] = None, force: Optional[bool] = False, client @api.get("/chat") -def chat(q: Optional[str] = None, client: Optional[str] = None): +async def chat(q: Optional[str] = None, client: Optional[str] = None): if ( state.processor_config is None or state.processor_config.conversation is None @@ -398,7 +398,7 @@ def chat(q: Optional[str] = None, client: Optional[str] = None): with timer("Searching knowledge base took", logger): result_list = [] for query in inferred_queries: - result_list.extend(search(query, n=5, r=True, score_threshold=-5.0, dedupe=False)) + result_list.extend(await search(query, n=5, r=True, score_threshold=-5.0, dedupe=False)) compiled_references = [item.additional["compiled"] for item in result_list] # Switch to general conversation type if no relevant notes found for the given query