"""Take a question plus relevant documents and write the final answer.""" from openai import OpenAI import config from retrieve import retrieve client = OpenAI(api_key=config.OPENAI_API_KEY) def answer(question): """Find relevant docs, then ask the model to answer using them.""" context = "\n\n".join(retrieve(question)) prompt = f"Use this context to answer.\n\nContext:\n{context}\n\nQuestion: {question}" resp = client.chat.completions.create( model=config.CHAT_MODEL, messages=[{"role": "user", "content": prompt}], ) return resp.choices[0].message.content