from typing import List, Optional from llmops.base import AbstractOperation from llmops.business.business_expert import BusinessExpert from llmops.config import prompt_path from llmops.utils.llm_client import LlmClient, LlmConfig class Preprocessor: """user requirements in natural language to abstract operations""" def __init__(self, business_expert: BusinessExpert, model: str): self.client = LlmClient(prompt_path / "preprocessor.md", llm_config=LlmConfig(model=model)) self.business_expert = business_expert self.all_operations = self.business_expert.operation_ids if business_expert.biz_system_prompt_preprocessor != "": self.client.update_system_prompt( self.client.system_prompt + "\nBusiness Logic:\n" + business_expert.biz_system_prompt_preprocessor ) def process( self, scenario_steps: Optional[List[str]] = None ) -> List[AbstractOperation]: """process Swagger specification to generate abstract state sequence Args: scenario_steps: Optional scenario steps list, if provided, generate state sequence based on steps Returns: Abstract state sequence """ # generate state sequence based on steps states = [] for step in scenario_steps: # state = self.extract_state(step) # states.append(state) states.append(AbstractOperation(original_description=step)) return states # def extract_state(self, step_description: str) -> AbstractOperation: # """extract abstract operation from step description""" # user_prompt = { # "step_description": step_description, # "swagger_spec": self.business_expert.extract_ids_and_descriptions, # } # AllOperationID = Enum("AllOperationID", {op: op for op in self.all_operations}) # class AbstractOperation4GPT(BaseModel): # operation_id: AllOperationID # attributes: str # llm_response = self.client.generate( # user_prompt, AbstractOperation4GPT # ) # mainly to get operation_id # operation_id = llm_response.operation_id.value # spec = self.business_expert.extract_operation(operation_id) # user_prompt["swagger_spec"] = spec # llm_response = self.client.generate( # user_prompt, AbstractOperation4GPT # ) # mainly to get attributes # llm_response.attributes = format_json_string_by_ai(llm_response.attributes) # return AbstractOperation( # operation_id=llm_response.operation_id, # attributes=llm_response.attributes, # original_description=step_description, # )