File size: 1,157 Bytes
428441b
 
 
 
 
 
 
 
 
 
93b5ba9
 
428441b
 
 
 
 
 
 
93b5ba9
428441b
 
93b5ba9
 
428441b
 
 
 
 
 
 
93b5ba9
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
# 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):
    if not prompt:
        prompt = "Summarize these biomedical search results, highlighting key findings and future research directions:"
    client = openai.AsyncOpenAI(api_key=openai.api_key)
    response = await client.chat.completions.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 = ""):
    client = openai.AsyncOpenAI(api_key=openai.api_key)
    response = await client.chat.completions.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