MCPcopy Create free account
hub / github.com/AutoPackAI/autopack / parse_selection_response

Function parse_selection_response

autopack/selection.py:106–130  ·  view source on GitHub ↗

Parse the response from the LLM and extract pack IDs. The response is split by commas and newlines, and any arguments provided in the response are removed. Args: response (str): The response from the LLM. Returns: list[str]: A list of parsed pack IDs.

(response: str)

Source from the content-addressed store, hash-verified

104
105
106def parse_selection_response(response: str) -> list[type[Pack]]:
107 """
108 Parse the response from the LLM and extract pack IDs.
109
110 The response is split by commas and newlines, and any arguments provided in the response are removed.
111
112 Args:
113 response (str): The response from the LLM.
114
115 Returns:
116 list[str]: A list of parsed pack IDs.
117 """
118 pack_names = [r.split("(")[0].strip() for r in re.split(r"(?<=\w),|\n", response)]
119
120 installed_packs = get_all_installed_packs()
121 selected_packs = []
122 for pack_name in pack_names:
123 try:
124 selected_pack = next(pack for pack in installed_packs if pack.name == pack_name)
125 selected_packs.append(selected_pack)
126 except StopIteration:
127 # This means that the pack selected is not installed. This error should've been caught elsewhere
128 continue
129
130 return selected_packs

Callers 1

select_packsFunction · 0.85

Calls 1

get_all_installed_packsFunction · 0.90

Tested by

no test coverage detected