mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Throw actionable exceptions when content types or chat not configured
This commit is contained in:
parent
359a2cacef
commit
924424c754
2 changed files with 23 additions and 2 deletions
|
@ -655,8 +655,14 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||
(encoded-query (url-hexify-string query))
|
||||
(query-url (format "%s/api/chat?q=%s" khoj-server-url encoded-query)))
|
||||
(with-temp-buffer
|
||||
(url-insert-file-contents query-url)
|
||||
(json-parse-buffer :object-type 'alist))))
|
||||
(condition-case ex
|
||||
(progn
|
||||
(url-insert-file-contents query-url)
|
||||
(json-parse-buffer :object-type 'alist))
|
||||
('file-error (cond ((string-match "Internal server error" (nth 2 ex))
|
||||
(message "Chat processor not configured. Configure OpenAI API key and restart it. Exception: [%s]" ex))
|
||||
(t (message "Chat exception: [%s]" ex))))))))
|
||||
|
||||
|
||||
(defun khoj--render-chat-message (message sender &optional receive-date)
|
||||
"Render chat messages as `org-mode' list item.
|
||||
|
|
|
@ -33,6 +33,12 @@ def get_default_config_data():
|
|||
@api.get("/config/types", response_model=List[str])
|
||||
def get_config_types():
|
||||
"""Get configured content types"""
|
||||
if state.config is None or state.config.content_type is None:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Content types not configured. Configure at least one content type on server and restart it.",
|
||||
)
|
||||
|
||||
configured_content_types = state.config.content_type.dict(exclude_none=True)
|
||||
return [
|
||||
search_type.value
|
||||
|
@ -190,6 +196,15 @@ def update(t: Optional[SearchType] = None, force: Optional[bool] = False):
|
|||
|
||||
@api.get("/chat")
|
||||
def chat(q: Optional[str] = None):
|
||||
if (
|
||||
state.processor_config is None
|
||||
or state.processor_config.conversation is None
|
||||
or state.processor_config.conversation.openai_api_key is None
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Chat processor not configured. Configure OpenAI API key on server and restart it."
|
||||
)
|
||||
|
||||
# Initialize Variables
|
||||
api_key = state.processor_config.conversation.openai_api_key
|
||||
model = state.processor_config.conversation.model
|
||||
|
|
Loading…
Reference in a new issue