Update mcp/openai_utils.py
Browse files- mcp/openai_utils.py +6 -6
mcp/openai_utils.py
CHANGED
@@ -6,10 +6,10 @@ import os
|
|
6 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
7 |
|
8 |
async def ai_summarize(text: str, prompt: str = None):
|
9 |
-
"""Summarize and synthesize results using OpenAI GPT-4o."""
|
10 |
if not prompt:
|
11 |
prompt = "Summarize these biomedical search results, highlighting key findings and future research directions:"
|
12 |
-
|
|
|
13 |
model="gpt-4o",
|
14 |
messages=[
|
15 |
{"role": "system", "content": "You are an expert biomedical research assistant."},
|
@@ -17,11 +17,11 @@ async def ai_summarize(text: str, prompt: str = None):
|
|
17 |
],
|
18 |
max_tokens=350
|
19 |
)
|
20 |
-
return response
|
21 |
|
22 |
async def ai_qa(question: str, context: str = ""):
|
23 |
-
|
24 |
-
response =
|
25 |
model="gpt-4o",
|
26 |
messages=[
|
27 |
{"role": "system", "content": "You are an advanced biomedical research agent."},
|
@@ -29,4 +29,4 @@ async def ai_qa(question: str, context: str = ""):
|
|
29 |
],
|
30 |
max_tokens=350
|
31 |
)
|
32 |
-
return response
|
|
|
6 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
7 |
|
8 |
async def ai_summarize(text: str, prompt: str = None):
|
|
|
9 |
if not prompt:
|
10 |
prompt = "Summarize these biomedical search results, highlighting key findings and future research directions:"
|
11 |
+
client = openai.AsyncOpenAI(api_key=openai.api_key)
|
12 |
+
response = await client.chat.completions.create(
|
13 |
model="gpt-4o",
|
14 |
messages=[
|
15 |
{"role": "system", "content": "You are an expert biomedical research assistant."},
|
|
|
17 |
],
|
18 |
max_tokens=350
|
19 |
)
|
20 |
+
return response.choices[0].message.content
|
21 |
|
22 |
async def ai_qa(question: str, context: str = ""):
|
23 |
+
client = openai.AsyncOpenAI(api_key=openai.api_key)
|
24 |
+
response = await client.chat.completions.create(
|
25 |
model="gpt-4o",
|
26 |
messages=[
|
27 |
{"role": "system", "content": "You are an advanced biomedical research agent."},
|
|
|
29 |
],
|
30 |
max_tokens=350
|
31 |
)
|
32 |
+
return response.choices[0].message.content
|