From 7b164de02142758884fc24b9071d49c04b187142 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 9 Jan 2023 01:14:49 -0300 Subject: [PATCH] Add beta API to summarize top search result using an OpenAI model This is unlike the more general chat API that combines summarization of top search result and conversing with the OpenAI model This should give faster summary results. As no intent categorization API call required --- src/routers/api_beta.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/routers/api_beta.py b/src/routers/api_beta.py index 35983805..d94974bd 100644 --- a/src/routers/api_beta.py +++ b/src/routers/api_beta.py @@ -33,6 +33,21 @@ def search_beta(q: str, n: Optional[int] = 1): return {'status': 'ok', 'result': search_results, 'type': search_type} +@api_beta.get('/summarize') +def summarize_beta(q: str): + # Initialize Variables + model = state.processor_config.conversation.model + api_key = state.processor_config.conversation.openai_api_key + + # Converse with OpenAI GPT + result_list = search(q, n=1, t=SearchType.Org, r=True) + collated_result = "\n".join([item.entry for item in result_list]) + logger.debug(f'Semantically Similar Notes:\n{collated_result}') + gpt_response = summarize(collated_result, summary_type="notes", user_query=q, model=model, api_key=api_key) + + return {'status': 'ok', 'response': gpt_response} + + @api_beta.get('/chat') def chat(q: str): # Load Conversation History