Skip to content

Commit

Permalink
fix rpc import error (#14)
Browse files Browse the repository at this point in the history
Fixed the bug that RPC related modules throw ModuleNotFoundError under default installation conditions
  • Loading branch information
pan-x-c authored Jan 22, 2024
1 parent ce00d18 commit 4829991
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/agentscope/agents/rpc_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
from agentscope._init import _INIT_SETTINGS
from agentscope._init import init
from agentscope.agents.agent import AgentBase
from agentscope.rpc.rpc_agent_pb2 import RpcMsg # pylint: disable=E0611
from agentscope.message import MessageBase
from agentscope.message import Msg
from agentscope.message import PlaceholderMessage
from agentscope.message import deserialize
from agentscope.message import serialize
from agentscope.utils.logging_utils import logger
from agentscope.rpc.rpc_agent_client import RpcAgentClient
from agentscope.rpc.rpc_agent_pb2_grpc import (
from agentscope.rpc import (
RpcAgentClient,
RpcMsg,
RpcAgentServicer,
add_RpcAgentServicer_to_server,
)
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from loguru import logger

from .rpc.rpc_agent_client import RpcAgentClient
from .rpc import RpcAgentClient
from .utils.tools import _get_timestamp


Expand Down
26 changes: 26 additions & 0 deletions src/agentscope/rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""Import all rpc related modules in the package."""
from typing import Any
from .rpc_agent_client import RpcAgentClient

try:
from .rpc_agent_pb2 import RpcMsg # pylint: disable=E0611
except ModuleNotFoundError:
RpcMsg = Any
try:
from .rpc_agent_pb2_grpc import RpcAgentServicer
from .rpc_agent_pb2_grpc import RpcAgentStub
from .rpc_agent_pb2_grpc import add_RpcAgentServicer_to_server
except ImportError:
RpcAgentServicer = object
RpcAgentStub = Any
add_RpcAgentServicer_to_server = Any


__all__ = [
"RpcAgentClient",
"RpcMsg",
"RpcAgentServicer",
"RpcAgentStub",
"add_RpcAgentServicer_to_server",
]
10 changes: 8 additions & 2 deletions src/agentscope/rpc/rpc_agent_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# -*- coding: utf-8 -*-
""" Client of rpc agent server """

from typing import Any

try:
import grpc
except ImportError:
grpc = None

from agentscope.rpc.rpc_agent_pb2 import RpcMsg # pylint: disable=E0611
from agentscope.rpc.rpc_agent_pb2_grpc import RpcAgentStub
try:
from agentscope.rpc.rpc_agent_pb2 import RpcMsg # pylint: disable=E0611
from agentscope.rpc.rpc_agent_pb2_grpc import RpcAgentStub
except ModuleNotFoundError:
RpcMsg = Any
RpcAgentStub = Any


class RpcAgentClient:
Expand Down

0 comments on commit 4829991

Please sign in to comment.