Download mcp/openai_utils.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/9d807172186a31bc7469058a1700e55debd77d9b/mcp/openai_utils.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@9d807172186a31bc7469058a1700e55debd77d9b/mcp/openai_utils.py
-
curl -L -o openai_utils.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/9d807172186a31bc7469058a1700e55debd77d9b/mcp/openai_utils.py
1.19 kB
| # 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'] | |