-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl register and add sub RPC (#5191)
* Refactor client id retrieval * WIP * fixes * future annotations * Fix tests * remove import
- Loading branch information
1 parent
db2410c
commit 55e929d
Showing
3 changed files
with
151 additions
and
120 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from autogen_core._subscription import Subscription | ||
from autogen_core._type_prefix_subscription import TypePrefixSubscription | ||
from autogen_core._type_subscription import TypeSubscription | ||
|
||
from .protos import agent_worker_pb2 | ||
|
||
|
||
def subscription_to_proto(subscription: Subscription) -> agent_worker_pb2.Subscription: | ||
match subscription: | ||
case TypeSubscription(topic_type=topic_type, agent_type=agent_type, id=id): | ||
return agent_worker_pb2.Subscription( | ||
id=id, | ||
typeSubscription=agent_worker_pb2.TypeSubscription(topic_type=topic_type, agent_type=agent_type), | ||
) | ||
case TypePrefixSubscription(topic_type_prefix=topic_type_prefix, agent_type=agent_type, id=id): | ||
return agent_worker_pb2.Subscription( | ||
id=id, | ||
typePrefixSubscription=agent_worker_pb2.TypePrefixSubscription( | ||
topic_type_prefix=topic_type_prefix, agent_type=agent_type | ||
), | ||
) | ||
case _: | ||
raise ValueError("Unsupported subscription type.") | ||
|
||
|
||
def subscription_from_proto(subscription: agent_worker_pb2.Subscription) -> Subscription: | ||
oneofcase = subscription.WhichOneof("subscription") | ||
match oneofcase: | ||
case "typeSubscription": | ||
type_subscription_msg: agent_worker_pb2.TypeSubscription = subscription.typeSubscription | ||
return TypeSubscription( | ||
topic_type=type_subscription_msg.topic_type, | ||
agent_type=type_subscription_msg.agent_type, | ||
id=subscription.id, | ||
) | ||
|
||
case "typePrefixSubscription": | ||
type_prefix_subscription_msg: agent_worker_pb2.TypePrefixSubscription = subscription.typePrefixSubscription | ||
return TypePrefixSubscription( | ||
topic_type_prefix=type_prefix_subscription_msg.topic_type_prefix, | ||
agent_type=type_prefix_subscription_msg.agent_type, | ||
id=subscription.id, | ||
) | ||
case None: | ||
raise ValueError("Invalid subscription message.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.