-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessUserQuery.py
62 lines (47 loc) · 2.4 KB
/
processUserQuery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import promptStorage as prompts
import openai
import json
import utilityFunctions as util
import time
import asyncio
def main():
pass
def find_and_replace_definitions(user_query):
pass
# Find relevant definition embeddings
# Prompt gpt-4 to determine which definitions are most relevant
# If there are multiple similar definitions, ask user to define which is most relevant
# Reformat user_query with applicable definitions and return
def processing_stage(user_query):
print("Starting processing stage...")
# Get similar queries by calling GPT 3.5, maybe Google BARD instead
similar_queries_list = []
print(" - Converting query to list of questions using template")
question_list = convert_query_to_question_list(user_query, used_model="gpt-3.5-turbo")
print(" - Generating similar search queries for questions")
similar_queries_list = get_similar_queries(question_list, user_query)
return similar_queries_list, question_list
def convert_query_to_question_list(user_query, used_model):
question_list = prompts.get_original_universal_answer_template(user_query)
prompt_convert_question = prompts.get_prompt_convert_question(question_list)
chat_completion = util.create_chat_completion(used_model, api_key_choice="will", prompt_messages=prompt_convert_question, temp=0)
converted_questions = chat_completion.choices[0].message.content
converted_questions = converted_questions.split("\n")
return converted_questions
def get_similar_queries(question_list, user_query):
content_list = []
lawful = prompts.get_prompt_similar_queries_lawful(user_query)
#unlawful = prompts.get_prompt_similar_queries_unlawful(user_query)
chat_completion = util.create_chat_completion(used_model="gpt-4", prompt_messages=lawful, temp=0, debug_print=True)
lawful_result = chat_completion.choices[0].message.content
#chat_completion = util.create_chat_completion(used_model="gpt-4", prompt_messages=unlawful, temp=0, debug_print=True)
#unlawful_result = chat_completion.choices[0].message.content
result_dct = json.loads(lawful_result)
lawful = " ".join(result_dct["queries"])
#result_dct = json.loads(unlawful_result)
#unlawful = " ".join(result_dct["queries"])
unlawful = None
similar_queries_list = [lawful, lawful, lawful, unlawful, unlawful]
return similar_queries_list
if __name__ == "__main__":
main()