mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Update /beta/chat API to return chat history if no query param passed
This commit is contained in:
@@ -62,7 +62,7 @@ def summarize_beta(q: str):
|
|||||||
|
|
||||||
|
|
||||||
@api_beta.get('/chat')
|
@api_beta.get('/chat')
|
||||||
def chat(q: str):
|
def chat(q: Optional[str]=None):
|
||||||
# Initialize Variables
|
# Initialize Variables
|
||||||
model = state.processor_config.conversation.model
|
model = state.processor_config.conversation.model
|
||||||
api_key = state.processor_config.conversation.openai_api_key
|
api_key = state.processor_config.conversation.openai_api_key
|
||||||
@@ -71,6 +71,10 @@ def chat(q: str):
|
|||||||
chat_session = state.processor_config.conversation.chat_session
|
chat_session = state.processor_config.conversation.chat_session
|
||||||
meta_log = state.processor_config.conversation.meta_log
|
meta_log = state.processor_config.conversation.meta_log
|
||||||
|
|
||||||
|
# If user query is empty, return chat history
|
||||||
|
if not q:
|
||||||
|
return {'status': 'ok', 'response': meta_log["chat"]}
|
||||||
|
|
||||||
# Converse with OpenAI GPT
|
# Converse with OpenAI GPT
|
||||||
metadata = understand(q, model=model, api_key=api_key, verbose=state.verbose)
|
metadata = understand(q, model=model, api_key=api_key, verbose=state.verbose)
|
||||||
logger.debug(f'Understood: {get_from_dict(metadata, "intent")}')
|
logger.debug(f'Understood: {get_from_dict(metadata, "intent")}')
|
||||||
|
|||||||
Reference in New Issue
Block a user