Skip to content
Snippets Groups Projects
Commit 6ec48b84 authored by Swetha Lakshmana Murthy's avatar Swetha Lakshmana Murthy
Browse files

Restructure: agentic workflow code

parent aa3b6f12
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ enum AgentType {
WEATHER = 1;
PLACES = 2;
FOOD = 3;
MAP = 4;
}
message AgentResponse {
......
grpcio==1.38.0
grpcio-tools==1.38.0
grpcio
grpcio-tools
grpc-interceptor
protobuf==3.16.0
protobuf
multithreading
openai
requests
......
import grpc
from concurrent import futures
import planner_pb2
import planner_pb2_grpc
from transformers import pipeline
import logging
import time
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
# Zero-shot classifier
classifier = pipeline("zero-shot-classification")
def match_agent(text):
candidate_labels = ["weather", "places", "food", "map"]
result = classifier(text, candidate_labels)
label = result["labels"][0]
if label == "weather":
return planner_pb2.WEATHER
elif label == "places":
return planner_pb2.PLACES
elif label == "food":
return planner_pb2.FOOD
elif label == "map":
return planner_pb2.MAP
else:
return planner_pb2.UNKNOWN
class PlannerService(planner_pb2_grpc.PlannerServicer):
def __init__(self):
logger.info("PlannerService initialized.")
def evaluateUserQueriesFromChatbot(self, request_iterator, context):
print("evaluateUserQueriesFromChatbot..............................")
for user_query in request_iterator:
logger.info(f"Received user query: {user_query.text}")
agent_type = match_agent(user_query.text)
logger.info(f"Matched agent type: {agent_type}")
agent_response = planner_pb2.AgentRequest()
agent_response.text = user_query.text
agent_response.agent_type = agent_type
if agent_type == planner_pb2.AgentType.WEATHER:
logger.info("Handling WEATHER agent.")
elif agent_type == planner_pb2.AgentType.PLACES:
logger.info("Handling PLACES agent.")
elif agent_type == planner_pb2.AgentType.FOOD:
logger.info("Handling FOOD agent.")
elif agent_type == planner_pb2.AgentType.MAP:
logger.info("Handling MAP agent.")
else:
agent_response.text = "Sorry, I couldn't understand the query."
yield agent_response
def processAgentResponsesFromAgent(self, request_iterator, context):
logger.info("Receiving AgentResponses from agent...")
for response in request_iterator:
logger.info(f"Received AgentResponse: {response.text}")
res = planner_pb2.AgentResponse()
res.text = response.text
print(res)
yield res
logger.info("Finished processing AgentResponses.")
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
planner_pb2_grpc.add_PlannerServicer_to_server(PlannerService(), server)
server.add_insecure_port("[::]:8061")
server.start()
logger.info("Planner Service running on port 8061")
server.wait_for_termination()
if __name__ == "__main__":
serve()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment