Update /beta/chat API to return chat history if no query param passed

This commit is contained in:
Debanjum Singh Solanky 2023-01-13 21:24:30 -03:00
parent d8ee0f0e9a
commit cc2456e411

View file

@ -62,7 +62,7 @@ def summarize_beta(q: str):
@api_beta.get('/chat')
def chat(q: str):
def chat(q: Optional[str]=None):
# Initialize Variables
model = state.processor_config.conversation.model
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
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
metadata = understand(q, model=model, api_key=api_key, verbose=state.verbose)
logger.debug(f'Understood: {get_from_dict(metadata, "intent")}')