Add support for using serper.dev for online queries

- Use the knowledgeGraph, answerBox, peopleAlsoAsk and organic responses of serper.dev to provide online context for queries made with the /online command
- Add it as an additional tool for doing Google searches
- Render the results appropriately in the chat web window
- Pass appropriate reference data down to the LLM
This commit is contained in:
sabaimran
2023-11-17 16:19:11 -08:00
parent bfbe273ffd
commit 0fcf234f07
11 changed files with 250 additions and 21 deletions

View File

@@ -88,6 +88,7 @@ def extract_questions(
def converse(
references,
online_results,
user_query,
conversation_log={},
model: str = "gpt-3.5-turbo",
@@ -109,6 +110,13 @@ def converse(
if conversation_command == ConversationCommand.Notes and is_none_or_empty(compiled_references):
completion_func(chat_response=prompts.no_notes_found.format())
return iter([prompts.no_notes_found.format()])
elif conversation_command == ConversationCommand.Online and is_none_or_empty(online_results):
completion_func(chat_response=prompts.no_online_results_found.format())
return iter([prompts.no_online_results_found.format()])
elif conversation_command == ConversationCommand.Online:
conversation_primer = prompts.online_search_conversation.format(
query=user_query, online_results=str(online_results)
)
elif conversation_command == ConversationCommand.General or is_none_or_empty(compiled_references):
conversation_primer = prompts.general_conversation.format(query=user_query)
else:
@@ -130,6 +138,7 @@ def converse(
return chat_completion_with_backoff(
messages=messages,
compiled_references=references,
online_results=online_results,
model_name=model,
temperature=temperature,
openai_api_key=api_key,