user-simulator 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- user_sim/__init__.py +0 -0
- user_sim/cli/__init__.py +0 -0
- user_sim/cli/gen_user_profile.py +34 -0
- user_sim/cli/init_project.py +65 -0
- user_sim/cli/sensei_chat.py +481 -0
- user_sim/cli/sensei_check.py +103 -0
- user_sim/cli/validation_check.py +143 -0
- user_sim/core/__init__.py +0 -0
- user_sim/core/ask_about.py +665 -0
- user_sim/core/data_extraction.py +260 -0
- user_sim/core/data_gathering.py +134 -0
- user_sim/core/interaction_styles.py +147 -0
- user_sim/core/role_structure.py +608 -0
- user_sim/core/user_simulator.py +302 -0
- user_sim/handlers/__init__.py +0 -0
- user_sim/handlers/asr_module.py +128 -0
- user_sim/handlers/html_parser_module.py +202 -0
- user_sim/handlers/image_recognition_module.py +139 -0
- user_sim/handlers/pdf_parser_module.py +123 -0
- user_sim/utils/__init__.py +0 -0
- user_sim/utils/config.py +47 -0
- user_sim/utils/cost_tracker.py +153 -0
- user_sim/utils/cost_tracker_v2.py +193 -0
- user_sim/utils/errors.py +15 -0
- user_sim/utils/exceptions.py +47 -0
- user_sim/utils/languages.py +78 -0
- user_sim/utils/register_management.py +62 -0
- user_sim/utils/show_logs.py +63 -0
- user_sim/utils/token_cost_calculator.py +338 -0
- user_sim/utils/url_management.py +60 -0
- user_sim/utils/utilities.py +568 -0
- user_simulator-0.1.0.dist-info/METADATA +733 -0
- user_simulator-0.1.0.dist-info/RECORD +37 -0
- user_simulator-0.1.0.dist-info/WHEEL +5 -0
- user_simulator-0.1.0.dist-info/entry_points.txt +6 -0
- user_simulator-0.1.0.dist-info/licenses/LICENSE.txt +21 -0
- user_simulator-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
import os
|
2
|
+
import csv
|
3
|
+
import json
|
4
|
+
import time
|
5
|
+
import pandas as pd
|
6
|
+
import yaml
|
7
|
+
from user_sim.utils.show_logs import *
|
8
|
+
import logging
|
9
|
+
from argparse import ArgumentParser
|
10
|
+
from dataclasses import dataclass
|
11
|
+
from user_sim.core.role_structure import RoleData
|
12
|
+
from user_sim.utils.utilities import read_yaml
|
13
|
+
|
14
|
+
|
15
|
+
logger = logging.getLogger('Info Logger')
|
16
|
+
|
17
|
+
|
18
|
+
@dataclass
|
19
|
+
class ValidationIssue:
|
20
|
+
field: str
|
21
|
+
error: str
|
22
|
+
error_type: str
|
23
|
+
location: str
|
24
|
+
|
25
|
+
class ProfileValidation:
|
26
|
+
|
27
|
+
def __init__(self, profile, export_path):
|
28
|
+
self.profile = profile
|
29
|
+
self.timestamp = int(time.time())
|
30
|
+
self.export_path = export_path + f"/run_{self.timestamp}"
|
31
|
+
self.profile_errors = []
|
32
|
+
self.error_number = 0
|
33
|
+
self.conversation_number = 0
|
34
|
+
self.combinations_dict = {}
|
35
|
+
|
36
|
+
def export_matrix_to_csv(self, matrix_combination=False):
|
37
|
+
df = pd.DataFrame()
|
38
|
+
combinations = 0
|
39
|
+
|
40
|
+
for combinations_dict in self.combinations_dict:
|
41
|
+
name = "_".join(combinations_dict.get('name', []))
|
42
|
+
matrix = combinations_dict.get('matrix', [])
|
43
|
+
func_type = combinations_dict.get("type", '')
|
44
|
+
combinations = combinations_dict.get('combinations', 0)
|
45
|
+
|
46
|
+
if matrix_combination:
|
47
|
+
if df.empty:
|
48
|
+
df = pd.DataFrame(matrix, columns=combinations_dict.get('name'))
|
49
|
+
else:
|
50
|
+
df_new = pd.DataFrame(matrix, columns=combinations_dict.get('name'))
|
51
|
+
df = pd.concat([df, df_new], axis=1)
|
52
|
+
combinations = len(df)
|
53
|
+
|
54
|
+
else:
|
55
|
+
filename = f"{name}_{func_type}_{combinations}_{self.timestamp}.csv"
|
56
|
+
path = f"{self.export_path}/combination_matrices"
|
57
|
+
filepath = f"{path}/{filename}"
|
58
|
+
if not os.path.exists(path):
|
59
|
+
os.makedirs(path)
|
60
|
+
try:
|
61
|
+
df = pd.DataFrame(matrix, columns=combinations_dict.get('name'))
|
62
|
+
df.to_csv(filepath, index=False)
|
63
|
+
except Exception as e:
|
64
|
+
logger.error(f"Couldn't export matrix dataframe: {e}")
|
65
|
+
logger.info(f"Combinations file saved as: {filepath}")
|
66
|
+
|
67
|
+
if matrix_combination:
|
68
|
+
filename = f"full_matrix_{combinations}_{self.timestamp}.csv"
|
69
|
+
path = f"{self.export_path}/combination_matrices"
|
70
|
+
filepath = f"{path}/{filename}"
|
71
|
+
if not os.path.exists(path):
|
72
|
+
os.makedirs(path)
|
73
|
+
try:
|
74
|
+
df.to_csv(filepath, index=False)
|
75
|
+
except Exception as e:
|
76
|
+
logger.error(f"Couldn't export matrix dataframe: {e}")
|
77
|
+
logger.info(f"Combinations file saved as: {filepath}")
|
78
|
+
|
79
|
+
def collect_errors(self, e, prefix="", message=None):
|
80
|
+
e_msg = f"{message}: {str(e)}" if message else str(e)
|
81
|
+
self.profile_errors.append(
|
82
|
+
{"field": 'unknown',
|
83
|
+
"error": e_msg,
|
84
|
+
"type": type(e).__name__,
|
85
|
+
"location": prefix}
|
86
|
+
# ValidationIssue(
|
87
|
+
# field='unknown',
|
88
|
+
# error=e_msg,
|
89
|
+
# error_type=type(e).__name__,
|
90
|
+
# location=prefix
|
91
|
+
# )
|
92
|
+
)
|
93
|
+
|
94
|
+
def validate(self):
|
95
|
+
try:
|
96
|
+
profile = read_yaml(self.profile)
|
97
|
+
user_profile = RoleData(profile, validation=True)
|
98
|
+
self.profile_errors, self.error_number = user_profile.get_errors()
|
99
|
+
self.conversation_number = user_profile.conversation_number
|
100
|
+
self.combinations_dict = user_profile.combinations_dict
|
101
|
+
except Exception as e:
|
102
|
+
self.collect_errors(e, "YAML_file", message="Invalid YAML syntax")
|
103
|
+
|
104
|
+
def show_report(self, matrix_combination=False):
|
105
|
+
if not os.path.exists(self.export_path):
|
106
|
+
os.makedirs(self.export_path)
|
107
|
+
logger.info(f"Validation report directory created at {self.export_path}")
|
108
|
+
|
109
|
+
error_result = {
|
110
|
+
"errors": self.profile_errors,
|
111
|
+
"total_errors": self.error_number
|
112
|
+
}
|
113
|
+
|
114
|
+
json_result = json.dumps(error_result, indent=4, ensure_ascii=False)
|
115
|
+
filepath = f"{self.export_path}/errors_{self.timestamp}.json"
|
116
|
+
|
117
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
118
|
+
f.write(json_result)
|
119
|
+
|
120
|
+
for c_dict in self.combinations_dict:
|
121
|
+
self.export_matrix_to_csv(matrix_combination)
|
122
|
+
|
123
|
+
|
124
|
+
def main():
|
125
|
+
parser = ArgumentParser(description='Conversation generator for a chatbot')
|
126
|
+
parser.add_argument('--profile', default='.',
|
127
|
+
help='Directory where the profile is located.')
|
128
|
+
parser.add_argument("--export", default='.',
|
129
|
+
help="Directory where the report will be exported")
|
130
|
+
parser.add_argument('--verbose', action='store_true', help='Shows debug prints')
|
131
|
+
parser.add_argument('--combined_matrix', action='store_true', help='Shows debug prints')
|
132
|
+
args = parser.parse_args()
|
133
|
+
|
134
|
+
logger = create_logger(args.verbose, 'Info Logger')
|
135
|
+
logger.info('Logs enabled!')
|
136
|
+
|
137
|
+
validation = ProfileValidation(args.profile, args.export)
|
138
|
+
validation.validate()
|
139
|
+
validation.show_report(args.combined_matrix)
|
140
|
+
|
141
|
+
|
142
|
+
if __name__ == "__main__":
|
143
|
+
main()
|
File without changes
|