@@ -56,6 +56,7 @@ def generate_prompt(
5656 move_type (str): The type of move to generate.
5757 hint (Optional[str]): An optional hint to guide the prompt generation.
5858 previous_prompt (List[Dict[str, str]]): A list of previous prompt entries, each containing a "content" key.
59+ turn (Optional[int]): Current turn.
5960
6061 Returns:
6162 str: The generated prompt.
@@ -77,6 +78,22 @@ def generate_prompt(
7778 return self .prompt_helper ._check_prompt (previous_prompt = previous_prompt , steps = steps )
7879
7980 def _get_documentation_steps (self , move_type : str , previous_prompt , doc_steps : Any ) -> List [str ]:
81+ """
82+ Generates documentation steps based on the current API specification, previous prompts,
83+ and the intended move type.
84+
85+ Args:
86+ move_type (str): Determines the strategy to apply. Accepted values:
87+ - "explore": Generates initial documentation steps for exploration.
88+ - Any other value: Triggers identification of endpoints needing more help.
89+ previous_prompt (Any): A history of previously generated prompts used to determine
90+ which endpoints have already been addressed.
91+ doc_steps (Any): Existing documentation steps that are modified or expanded based on
92+ the selected move_type.
93+
94+ Returns:
95+ List[str]: A list of documentation prompts tailored to the move_type and current context.
96+ """
8097 # Extract properties and example response
8198 if "endpoints" in self .open_api_spec :
8299 properties = self .extract_properties ()
@@ -118,11 +135,23 @@ def _get_documentation_steps(self, move_type: str, previous_prompt, doc_steps: A
118135 return self .prompt_helper .get_endpoints_needing_help (
119136 info = f"Based on this information :\n { icl_prompt } \n Do the following: " )
120137
121- # Function to extract properties from the schema
122-
123138
124- # Function to extract example response from paths
125139 def extract_example_response (self , api_paths , endpoint , method = "get" ):
140+ """
141+ Extracts a representative example response for a specified API endpoint and method
142+ from an OpenAPI specification.
143+ Args:
144+ api_paths (dict): A dictionary representing the paths section of the OpenAPI spec,
145+ typically `self.open_api_spec["endpoints"]`.
146+ endpoint (str): The specific API endpoint to extract the example from (e.g., "/users").
147+ method (str, optional): The HTTP method to consider (e.g., "get", "post").
148+ Defaults to "get".
149+
150+ Returns:
151+ dict: A dictionary with the HTTP method as the key and the extracted example
152+ response as the value. If no suitable example is found, returns an empty dict.
153+ Format: { "get": { "exampleName": exampleData } }
154+ """
126155 example_method = {}
127156 example_response = {}
128157 # Ensure that the provided endpoint and method exist in the schema
@@ -159,8 +188,23 @@ def extract_example_response(self, api_paths, endpoint, method="get"):
159188
160189 # Function to generate the prompt for In-Context Learning
161190 def generate_icl_prompt (self , properties , example_response , endpoint ):
191+ """
192+ Generates an in-context learning (ICL) prompt to guide a language model in understanding
193+ and documenting a REST API endpoint.
194+
195+ Args:
196+ properties (dict): A dictionary of property names to their types and example values.
197+ Format: { "property_name": {"type": "string", "example": "value"} }
198+ example_response (dict): A dictionary containing example API responses, typically extracted
199+ using `extract_example_response`. Format: { "get": { ...example... } }
200+ endpoint (str): The API endpoint path (e.g., "/users").
201+
202+ Returns:
203+ str: A formatted prompt string containing API metadata, property descriptions,
204+ and a JSON-formatted example response.
205+ """
162206 # Core information about API
163- if example_response .keys () != {} :
207+ if len ( example_response .keys ()) > 0 :
164208 prompt = f"# REST API: { list (example_response .keys ())[0 ].upper ()} { endpoint } \n \n "
165209 else :
166210 prompt = f"# REST API: { endpoint } \n \n "
@@ -186,6 +230,22 @@ def generate_icl_prompt(self, properties, example_response, endpoint):
186230 return prompt
187231
188232 def extract_properties_with_examples (self , data ):
233+ """
234+ Extracts and flattens properties from a nested dictionary or list of dictionaries,
235+ producing a dictionary of property names along with their inferred types and example values.
236+
237+ Args:
238+ data (dict or list): The input data, usually an example API response. This can be:
239+ - A single dictionary (representing a single API object).
240+ - A list of dictionaries (representing a collection of API objects).
241+ - A special-case dict with a single `None` key, which is unwrapped.
242+
243+ Returns:
244+ dict: A dictionary mapping property names to a dictionary with keys:
245+ - "type": The inferred data type (e.g., "string", "integer").
246+ - "example": A sample value for the property.
247+ Format: { "property_name": {"type": "string", "example": "value"} }
248+ """
189249
190250 # Handle nested dictionaries, return flattened properties
191251
@@ -327,7 +387,16 @@ def transform_test_case_to_string(self, test_case, character):
327387
328388 return '' .join (result )
329389
330- def get_props (self , data , result ):
390+ def get_props (self , data :dict , result :dict ):
391+ """
392+ Recursively extracts properties from a dictionary, including nested dictionaries and lists,
393+ and appends them to the result dictionary with their inferred data types and example values.
394+
395+ Returns:
396+ dict: The updated result dictionary containing all extracted properties, including those
397+ found in nested dictionaries or lists.
398+ """
399+
331400 for key , value in data .items ():
332401
333402 if isinstance (value , dict ):
0 commit comments