Skip to content

Commit 938ea37

Browse files
authored
Merge pull request #62 from cloudera/dev
freeform job synthesis parameters update for freeformflag
2 parents a377312 + 986e9b2 commit 938ea37

File tree

4 files changed

+20
-48
lines changed

4 files changed

+20
-48
lines changed

app/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ async def generate_freeform_data(request: SynthesisRequest):
466466
else:
467467
# Pass additional parameter to indicate this is a freeform request
468468
request_dict = request.model_dump()
469-
request_dict['generation_type'] = 'freeform'
469+
freeform = True
470470
# Convert back to SynthesisRequest object
471471
freeform_request = SynthesisRequest(**request_dict)
472-
return synthesis_job.generate_job(freeform_request, core, mem, request_id=request_id)
472+
return synthesis_job.generate_job(freeform_request, core, mem, request_id=request_id, freeform = freeform)
473473

474474
@app.post("/synthesis/evaluate",
475475
include_in_schema=True,
@@ -519,10 +519,10 @@ async def evaluate_freeform(request: EvaluationRequest):
519519
return evaluator_service.evaluate_row_data(request, request_id=request_id)
520520
else:
521521
request_dict = request.model_dump()
522-
request_dict['generation_type'] = 'freeform'
522+
freeform = True
523523
# Convert back to SynthesisRequest object
524524
freeform_request = EvaluationRequest(**request_dict)
525-
return synthesis_job.evaluate_job(freeform_request, request_id=request_id)
525+
return synthesis_job.evaluate_job(freeform_request, request_id=request_id,freeform = freeform)
526526

527527

528528
@app.post("/model/alignment",

app/run_eval_job.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,7 @@
99

1010
os.chdir("/home/cdsw/synthetic-data-studio")
1111

12-
# def check_and_install_requirements():
13-
# """Check and install requirements from requirements.txt"""
14-
# # Get the current working directory instead of using __file__
15-
# current_dir = os.getcwd()
16-
# requirements_path = os.path.join(current_dir, 'requirements.txt')
17-
18-
# if os.path.exists(requirements_path):
19-
# try:
20-
# print(f"Installing requirements from: {requirements_path}")
21-
# subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', requirements_path])
22-
# except subprocess.CalledProcessError as e:
23-
# print(f"Error installing requirements: {e}")
24-
# sys.exit(1)
25-
# else:
26-
# print("No requirements.txt found, continuing with existing packages")
27-
28-
# # Run installation check at start
29-
# check_and_install_requirements()
30-
# Get the current notebook's directory
12+
3113
notebook_dir = os.getcwd()
3214

3315
# Detect the Python version dynamically
@@ -69,7 +51,7 @@ async def run_freeform_eval(request, job_name, request_id):
6951
"""Run freeform data synthesis job"""
7052
try:
7153
job = EvaluatorService()
72-
result = await job.evaluate_row_data(request, job_name, is_demo=False, request_id=request_id)
54+
result = job.evaluate_row_data(request, job_name, is_demo=False, request_id=request_id)
7355
return result
7456
except Exception as e:
7557
print(f"Error in freeform synthesis: {e}")

app/run_job.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,9 @@
88
if os.getenv("IS_COMPOSABLE"):
99
os.chdir("/home/cdsw/synthetic-data-studio")
1010

11-
# def check_and_install_requirements():
12-
# """Check and install requirements from requirements.txt"""
13-
# # Get the current working directory instead of using __file__
14-
# current_dir = os.getcwd()
15-
# requirements_path = os.path.join(current_dir, 'requirements.txt')
16-
17-
# if os.path.exists(requirements_path):
18-
# try:
19-
# print(f"Installing requirements from: {requirements_path}")
20-
# subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', requirements_path])
21-
# except subprocess.CalledProcessError as e:
22-
# print(f"Error installing requirements: {e}")
23-
# sys.exit(1)
24-
# else:
25-
# print("No requirements.txt found, continuing with existing packages")
26-
27-
28-
# # Run installation check at start
29-
# check_and_install_requirements()
11+
12+
13+
3014

3115
# Get the current notebook's directory
3216
notebook_dir = os.getcwd()

app/services/synthesis_job.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def _create_and_run_job(
5252
params: Dict[str, Any],
5353
cpu: int,
5454
memory: int,
55-
request_id = None
55+
request_id = None,
56+
freeform = None
5657
) -> tuple:
5758
"""Common job creation and execution logic"""
5859
script_path = self.path_manager.get_str_path(f"app/{script_name}")
@@ -62,6 +63,8 @@ def _create_and_run_job(
6263
job_name = f"{display_name}_{random_id}" if display_name else f"{job_prefix}_{random_id}"
6364
params['job_name'] = job_name
6465
params['request_id'] = request_id
66+
if freeform:
67+
params['generation_type'] = 'freeform'
6568
file_name = f"{job_prefix}_args_{random_id}.json"
6669

6770
# Write parameters to file
@@ -103,7 +106,7 @@ def _get_job_creator_name(self, job_run_id: str) -> str:
103106
).job_runs[0].creator.name
104107

105108
#@track_job("generate")
106-
def generate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id = None) -> Dict[str, str]:
109+
def generate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id = None, freeform = False) -> Dict[str, str]:
107110
"""Create and run a synthesis generation job"""
108111
json_str = request.model_dump_json()
109112
params = json.loads(json_str)
@@ -114,7 +117,9 @@ def generate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id =
114117
params,
115118
cpu=cpu,
116119
memory=memory,
117-
request_id=request_id
120+
request_id=request_id,
121+
freeform = freeform
122+
118123
)
119124

120125
# Calculate total count
@@ -159,7 +164,7 @@ def generate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id =
159164
return {"job_name": job_name, "job_id": job_run.job_id}
160165

161166
#@track_job("evaluate")
162-
def evaluate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id = None) -> Dict[str, str]:
167+
def evaluate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id = None, freeform = None) -> Dict[str, str]:
163168
"""Create and run an evaluation job"""
164169
json_str = request.model_dump_json()
165170
params = json.loads(json_str)
@@ -170,7 +175,8 @@ def evaluate_job(self, request: Any, cpu: int = 2, memory: int = 4, request_id =
170175
params,
171176
cpu=cpu,
172177
memory=memory,
173-
request_id=request_id
178+
request_id=request_id,
179+
freeform = freeform
174180
)
175181

176182
custom_prompt_str = PromptHandler.get_default_custom_eval_prompt(

0 commit comments

Comments
 (0)