QuotationChatbot_v5 / extract_input_mappings.py
jess
modify config and input_mappings
b344bb8
from itertools import chain
from prompt_configs import PROMPTS
# For each configuration, combine the "inputs" and "outputs" lists.
# 1. For each configuration in PROMPTS, get the list of inputs and outputs.
all_vars_lists = []
for prompt in PROMPTS.values():
# Access the inputs and outputs from the prompt configuration.
vars_list = prompt.inputs + prompt.outputs
all_vars_lists.append(vars_list)
# 2. Flatten the list of lists into a single sequence.
flattened_vars = list(chain(*all_vars_lists))
# 3. Process each item: if it contains commas, split and strip whitespace.
processed_vars = []
for var in flattened_vars:
# Split if comma exists, otherwise use the original string.
parts = [item.strip() for item in var.split(",")]
processed_vars.extend(parts)
# 4. Remove duplicates while preserving the order.
unique_vars = list(dict.fromkeys(processed_vars))
lines = ["INPUT_MAPPINGS = {\n\t'project_detail': lambda self: self.get_project_detail(),"]
for var in unique_vars:
lines.append(f" '{var}': lambda self: self.{var},")
lines.append("}")
output_text = "\n".join(lines)
# Write the mapping to a file.
with open("input_mappings.py", "w") as file:
file.write(output_text)
print("Mappings have been written to input_mappings.py")