|
|
@ -42,32 +42,34 @@ def get_answer_from_files(question, session_id, pinecone_index):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
files_string += file_string
|
|
|
|
files_string += file_string
|
|
|
|
|
|
|
|
|
|
|
|
prompt = f"Given a question, try to answer it using the content of the file extracts below, and if you cannot answer, or find " \
|
|
|
|
messages = [
|
|
|
|
f"a relevant file, just output \"I couldn't find the answer to that question in your files.\".\n\n" \
|
|
|
|
{
|
|
|
|
f"If the answer is not contained in the files or if there are no file extracts, respond with \"I couldn't find the answer " \
|
|
|
|
"role": "system",
|
|
|
|
f"to that question in your files.\" If the question is not actually a question, respond with \"That's not a valid question.\"\n\n" \
|
|
|
|
"content": f"Given a question, try to answer it using the content of the file extracts below, and if you cannot answer, or find " \
|
|
|
|
f"In the cases where you can find the answer, first give the answer. Then explain how you found the answer from the source or sources, " \
|
|
|
|
f"a relevant file, just output \"I couldn't find the answer to that question in your files.\".\n\n" \
|
|
|
|
f"and use the exact filenames of the source files you mention. Do not make up the names of any other files other than those mentioned "\
|
|
|
|
f"If the answer is not contained in the files or if there are no file extracts, respond with \"I couldn't find the answer " \
|
|
|
|
f"in the files context. Give the answer in markdown format." \
|
|
|
|
f"to that question in your files.\" If the question is not actually a question, respond with \"That's not a valid question.\"\n\n" \
|
|
|
|
f"Use the following format:\n\nQuestion: <question>\n\nFiles:\n<###\n\"filename 1\"\nfile text>\n<###\n\"filename 2\"\nfile text>...\n\n"\
|
|
|
|
f"In the cases where you can find the answer, first give the answer. Then explain how you found the answer from the source or sources, " \
|
|
|
|
f"Answer: <answer or \"I couldn't find the answer to that question in your files\" or \"That's not a valid question.\">\n\n" \
|
|
|
|
f"and use the exact filenames of the source files you mention. Do not make up the names of any other files other than those mentioned "\
|
|
|
|
f"Question: {question}\n\n" \
|
|
|
|
f"in the files context. Give the answer in markdown format." \
|
|
|
|
f"Files:\n{files_string}\n" \
|
|
|
|
f"Use the following format:\n\nQuestion: <question>\n\nFiles:\n<###\n\"filename 1\"\nfile text>\n<###\n\"filename 2\"\nfile text>...\n\n"\
|
|
|
|
f"Answer:"
|
|
|
|
f"Answer: <answer or \"I couldn't find the answer to that question in your files\" or \"That's not a valid question.\">\n\n" \
|
|
|
|
|
|
|
|
f"Question: {question}\n\n" \
|
|
|
|
|
|
|
|
f"Files:\n{files_string}\n" \
|
|
|
|
|
|
|
|
f"Answer:"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"[get_answer_from_files] prompt: {prompt}")
|
|
|
|
response = openai.ChatCompletion.create(
|
|
|
|
|
|
|
|
messages=messages,
|
|
|
|
response = openai.Completion.create(
|
|
|
|
model=GENERATIVE_MODEL,
|
|
|
|
prompt=prompt,
|
|
|
|
|
|
|
|
temperature=0,
|
|
|
|
|
|
|
|
max_tokens=1000,
|
|
|
|
max_tokens=1000,
|
|
|
|
top_p=1,
|
|
|
|
temperature=0,
|
|
|
|
frequency_penalty=0,
|
|
|
|
|
|
|
|
presence_penalty=0,
|
|
|
|
|
|
|
|
engine=GENERATIVE_MODEL,
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
answer = response.choices[0].text.strip()
|
|
|
|
choices = response["choices"] # type: ignore
|
|
|
|
|
|
|
|
answer = choices[0].message.content.strip()
|
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"[get_answer_from_files] answer: {answer}")
|
|
|
|
logging.info(f"[get_answer_from_files] answer: {answer}")
|
|
|
|
|
|
|
|
|
|
|
|
return jsonify({"answer": answer})
|
|
|
|
return jsonify({"answer": answer})
|
|
|
|