MCPcopy
hub / github.com/bhaskatripathi/pdfGPT / generate_answer

Function generate_answer

api.py:130–150  ·  view source on GitHub ↗
(question, openAI_key)

Source from the content-addressed store, hash-verified

128
129
130def generate_answer(question, openAI_key):
131 topn_chunks = recommender(question)
132 prompt = ""
133 prompt += 'search results:\n\n'
134 for c in topn_chunks:
135 prompt += c + '\n\n'
136
137 prompt += (
138 "Instructions: Compose a comprehensive reply to the query using the search results given. "
139 "Cite each reference using [ Page Number] notation (every result has this number at the beginning). "
140 "Citation should be done at the end of each sentence. If the search results mention multiple subjects "
141 "with the same name, create separate answers for each. Only include information found in the results and "
142 "don't add any additional information. Make sure the answer is correct and don't output false content. "
143 "If the text does not relate to the query, simply state 'Text Not Found in PDF'. Ignore outlier "
144 "search results which has nothing to do with the question. Only answer what is asked. The "
145 "answer should be short and concise. Answer step-by-step. \n\nQuery: {question}\nAnswer: "
146 )
147
148 prompt += f"Query: {question}\nAnswer:"
149 answer = generate_text(openAI_key, prompt, "text-davinci-003")
150 return answer
151
152
153def load_openai_key() -> str:

Callers 2

ask_urlFunction · 0.85
ask_fileFunction · 0.85

Calls 1

generate_textFunction · 0.85

Tested by

no test coverage detected