Cleanup embeddings typing

This commit is contained in:
Nicolas Mowen 2025-06-06 08:23:25 -06:00
parent a4a91dd848
commit 1fc8d9e1b6
2 changed files with 15 additions and 4 deletions

View File

@ -1,10 +1,14 @@
"""Facilitates communication between processes.""" """Facilitates communication between processes."""
import logging
from enum import Enum from enum import Enum
from typing import Any, Callable from typing import Any, Callable
import zmq import zmq
logger = logging.getLogger(__name__)
SOCKET_REP_REQ = "ipc:///tmp/cache/embeddings" SOCKET_REP_REQ = "ipc:///tmp/cache/embeddings"
@ -41,9 +45,16 @@ class EmbeddingsResponder:
break break
try: try:
(topic, value) = self.socket.recv_json(flags=zmq.NOBLOCK) raw = self.socket.recv_json(flags=zmq.NOBLOCK)
response = process(topic, value) if isinstance(raw, list):
(topic, value) = raw
response = process(topic, value)
else:
logging.warning(
f"Received unexpected data type in ZMQ recv_json: {type(raw)}"
)
response = None
if response is not None: if response is not None:
self.socket.send_json(response) self.socket.send_json(response)
@ -65,7 +76,7 @@ class EmbeddingsRequestor:
self.socket = self.context.socket(zmq.REQ) self.socket = self.context.socket(zmq.REQ)
self.socket.connect(SOCKET_REP_REQ) self.socket.connect(SOCKET_REP_REQ)
def send_data(self, topic: str, data: Any) -> str: def send_data(self, topic: str, data: Any) -> Any:
"""Sends data and then waits for reply.""" """Sends data and then waits for reply."""
try: try:
self.socket.send_json((topic, data)) self.socket.send_json((topic, data))

View File

@ -47,7 +47,7 @@ class InterProcessCommunicator(Communicator):
response = self._dispatcher(topic, value) response = self._dispatcher(topic, value)
else: else:
logging.warning( logging.warning(
f"Received unexpected data type in ZMQ inter-process: {type(raw)}" f"Received unexpected data type in ZMQ recv_json: {type(raw)}"
) )
response = None response = None