Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions charge/servers/molecular_generation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## SPDX-License-Identifier: Apache-2.0
################################################################################

from concurrent.futures import ThreadPoolExecutor
from loguru import logger

try:
Expand All @@ -30,7 +31,7 @@
import charge.utils.helper_funcs as hf
import argparse
from typing import Optional

import asyncio

mcp = FastMCP(
"SMILES Diagnosis and retrieval MCP Server",
Expand Down Expand Up @@ -85,8 +86,20 @@ def diagnose_smiles(smiles: str) -> str:

diagnose_agent = AGENT_POOL.create_agent(task=task)

async def _run_async_agent():
return await diagnose_agent.run()

try:
response = asyncio.run(diagnose_agent.run())
# Check if asyncio event loop is already running
if asyncio.get_event_loop().is_running():

# What should we do here?
with ThreadPoolExecutor() as pool:
future = pool.submit(asyncio.run, _run_async_agent())
response = future.result()

else:
response = asyncio.run(_run_async_agent())
assert response is not None
assert len(response.messages) > 0 # type: ignore
assert response.messages[-1] is not None # type: ignore
Expand Down