from llmops.config import prompt_path from llmops.base import ( Step, AbstractOperation, Judgement4GPT, ExecutionResult ) from llmops.utils.llm_client import LlmClient, LlmConfig from llmops.business.business_expert import BusinessExpert from typing import Dict, Any class TargetMatcher: """Check if the last step matches the target operation""" def __init__(self, business_expert: BusinessExpert, model: str): self.system_prompt_template = prompt_path / "is_target_ready.md" # self.business_expert = business_expert self.llm_client = LlmClient(self.system_prompt_template, llm_config=LlmConfig(model=model)) self.trajectory = [] def matches(self, last_step: Step, response: ExecutionResult, target: AbstractOperation) -> Judgement4GPT: user_prompt = { "last_request": { "operation_id": last_step.operation_id, "request": last_step.request.model_dump(), }, "last_response": response.model_dump(), "expect": last_step.expect, "target_operation": target.model_dump(), } result = self.llm_client.generate(user_prompt, Judgement4GPT) self.trajectory.append( { "input": { "last_step": last_step.model_dump(), "target_operation": target.model_dump(), }, "output": result.model_dump(), } ) return result def get_trajectory(self) -> Dict[str, Any]: """Get the trajectory of target matching process""" return self.trajectory