-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_all.py
More file actions
58 lines (48 loc) · 2.2 KB
/
patch_all.py
File metadata and controls
58 lines (48 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
path_schemas = "D:/Projects/Research2Text-main/src/schemas.py"
with open(path_schemas, "r", encoding="utf-8") as f:
code = f.read()
target_schemas = """ # Phase 3: Confidence scores for each extracted field
confidence: Dict[str, ConfidenceScore] = Field(
default_factory=dict,
description="Per-field confidence scores from conformal prediction"
)"""
replacement_schemas = """ @model_validator(mode="before")
@classmethod
def coerce_none_to_defaults(cls, data: Any) -> Any:
# LLMs often return null for list/dict fields — coerce to empty list/dict.
if isinstance(data, dict):
list_fields = ["equations", "datasets", "references"]
dict_fields = ["inputs", "outputs"]
for field in list_fields:
if data.get(field) is None:
data[field] = []
for field in dict_fields:
if data.get(field) is None:
data[field] = {}
return data
# Phase 3: Confidence scores for each extracted field
confidence: Dict[str, ConfidenceScore] = Field(
default_factory=dict,
description="Per-field confidence scores from conformal prediction"
)"""
if target_schemas in code:
code = code.replace(target_schemas, replacement_schemas)
with open(path_schemas, "w", encoding="utf-8") as f:
f.write(code)
print("Successfully patched schemas.py")
else:
print("Failed to patch schemas.py")
path_codegen = "D:/Projects/Research2Text-main/src/code_generator.py"
with open(path_codegen, "r", encoding="utf-8") as f:
code = f.read()
target_codegen_1 = """9. Do NOT leave TODO placeholders or incomplete code."""
replacement_codegen_1 = """9. Do NOT leave TODO placeholders or incomplete code.
10. Use ONLY ASCII characters in code and print statements (e.g., use '->' instead of '→') to prevent UnicodeEncodeError in Windows."""
if target_codegen_1 in code:
code = code.replace(target_codegen_1, replacement_codegen_1)
with open(path_codegen, "w", encoding="utf-8") as f:
f.write(code)
print("Successfully patched system prompt in code_generator.py")
else:
print("Failed to patch code_generator.py prompt")