create a function will take object of AppState and return a dictionary of from the input…
- User
create a function will take object of AppState and return a dictionary of from the input metadata: Dict[str, str] object_definition: str import_statements: str clarifier_info: Dict[str, str] clarifier_questions: Dict[str, list[str]] test_scenarios_str: str test_scenarios_json: Dict[str, str] fmc_code: str test_code: str pytest_report_json: Dict pytest_report_str: str fca_remaining_iterations: int code_reviewer_suggestions: str global_variables_and_custom_objects: str dependency_descriptions: Dict[str, str] scenario_codes:Dict[str, str]
@dataclass class AppState:
coderepo_url: str = "" repo_path: str = "" repo_cloned: bool = False language: str = None file_path: str = None file_name: str = None packages: Dict[str, Any] = field(default_factory=dict) complete_methods: Dict[str, Any] = field(default_factory=dict) method_name: str = None method_definition: str = None objective: str = None sample_data: Any = None test_cases: List[Any] = field(default_factory=list) test_cases_full: List[Any] = field(default_factory=list) pytest_codes: str = "" pytest_results: Dict[str, Any] = field(default_factory=dict) langgraph_states: List[Any] = field(default_factory=list) selected_scenarios: List[Any] = field(default_factory=list) questions: List[Any] = field(default_factory=list) answers: List[Any] = field(default_factory=list) messages_history: List[Any] = field(default_factory=list) components: List[Any] = field(default_factory=list) metadata: Dict[str, str] object_definition: str import_statements: str clarifier_info: Dict[str, str] clarifier_questions: Dict[str, list[str]] test_scenarios_str: str test_scenarios_json: Dict[str, str] fmc_code: str test_code: str pytest_report_json: Dict pytest_report_str: str fca_remaining_iterations: int code_reviewer_suggestions: str global_variables_and_custom_objects: str dependency_descriptions: Dict[str, str] scenario_codes:Dict[str, str] - Assistant
- User
how to use this function
codedef update(self, **kwargs: Dict[str, Any]) -> None: """Update AppState attributes based on provided keyword arguments.""" for key, value in kwargs.items(): if value is not None and hasattr(self, key): setattr(self, key, value)to update the extracted dictionary
- Assistant
Great question!
If you want to use the
updatemethod you shared to update anAppStateinstance from a dictionary (like the one returned by theextract_app_state_datafunction), you can do it like this:Assume:
app_stateis an instance ofAppStatedata_dictis the dictionary you want to updateapp_statewith (like from the extract function)
Usage:
pythonapp_state.update(**data_dict)
Explanation:
- The dictionary
data_dicthas keys matching attribute names ofAppState.