# mcp/openai_utils.py import openai import os openai.api_key = os.environ.get("OPENAI_API_KEY") async def ai_summarize(text: str, prompt: str = None): """Summarize and synthesize results using OpenAI GPT-4o.""" if not prompt: prompt = "Summarize these biomedical search results, highlighting key findings and future research directions:" response = openai.ChatCompletion.create( model="gpt-4o", messages=[ {"role": "system", "content": "You are an expert biomedical research assistant."}, {"role": "user", "content": f"{prompt}\n{text}"} ], max_tokens=350 ) return response['choices'][0]['message']['content'] async def ai_qa(question: str, context: str = ""): """Answer a user question using OpenAI GPT-4o, with provided context.""" response = openai.ChatCompletion.create( model="gpt-4o", messages=[ {"role": "system", "content": "You are an advanced biomedical research agent."}, {"role": "user", "content": f"Question: {question}\nContext: {context}"} ], max_tokens=350 ) return response['choices'][0]['message']['content']