Add logs for chat bot in verbose mode

This commit is contained in:
Debanjum Singh Solanky 2022-01-12 09:06:32 -05:00
parent 6dc2a99d35
commit 5a686b7be9
2 changed files with 9 additions and 2 deletions

View file

@ -103,11 +103,16 @@ def chat(q: str):
meta_log = processor_config.conversation.meta_log meta_log = processor_config.conversation.meta_log
# Converse with OpenAI GPT # Converse with OpenAI GPT
metadata = understand(q, api_key=processor_config.conversation.openai_api_key) metadata = understand(q, api_key=processor_config.conversation.openai_api_key, verbose=verbose)
if verbose > 1:
print(f'Understood: {get_from_dict(metadata, "intent")}')
if get_from_dict(metadata, "intent", "memory-type") == "notes": if get_from_dict(metadata, "intent", "memory-type") == "notes":
query = get_from_dict(metadata, "intent", "query") query = get_from_dict(metadata, "intent", "query")
result_list = search(query, n=1, t=SearchType.Notes) result_list = search(query, n=1, t=SearchType.Notes)
collated_result = "\n".join([item["Entry"] for item in result_list]) collated_result = "\n".join([item["Entry"] for item in result_list])
if verbose > 1:
print(f'Semantically Similar Notes:\n{collated_result}')
gpt_response = summarize(collated_result, summary_type="notes", user_query=q, api_key=processor_config.conversation.openai_api_key) gpt_response = summarize(collated_result, summary_type="notes", user_query=q, api_key=processor_config.conversation.openai_api_key)
else: else:
gpt_response = converse(q, chat_session, api_key=processor_config.conversation.openai_api_key) gpt_response = converse(q, chat_session, api_key=processor_config.conversation.openai_api_key)

View file

@ -36,7 +36,7 @@ def summarize(text, summary_type, user_query=None, api_key=None, temperature=0.5
return str(story).replace("\n\n", "") return str(story).replace("\n\n", "")
def understand(text, api_key=None, temperature=0.5, max_tokens=100): def understand(text, api_key=None, temperature=0.5, max_tokens=100, verbose=0):
""" """
Understand user input using OpenAI's GPT Understand user input using OpenAI's GPT
""" """
@ -46,6 +46,8 @@ def understand(text, api_key=None, temperature=0.5, max_tokens=100):
# Setup Prompt with Understand Primer # Setup Prompt with Understand Primer
prompt = message_to_prompt(text, understand_primer, start_sequence="\nA:", restart_sequence="\nQ:") prompt = message_to_prompt(text, understand_primer, start_sequence="\nA:", restart_sequence="\nQ:")
if verbose > 1:
print(f"Message -> Prompt: {text} -> {prompt}")
# Get Response from GPT # Get Response from GPT
response = openai.Completion.create( response = openai.Completion.create(