Skip to content

Commit 2b8d924

Browse files
author
Will Kukkamalla
committed
updated models to have consistent json shcema file checks
1 parent 93dbd4b commit 2b8d924

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

ai_feedback/models/CodeLlamaModel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def generate_response(
4949
or None if no valid response is returned.
5050
"""
5151
if json_schema:
52-
with open(json_schema, "r", encoding="utf-8") as f:
52+
schema_path = Path(json_schema)
53+
if not schema_path.exists():
54+
raise FileNotFoundError(f"JSON schema file not found: {schema_path}")
55+
with open(schema_path, "r", encoding="utf-8") as f:
5356
schema = json.load(f)
5457
else:
5558
schema = None

ai_feedback/models/DeepSeekModel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def generate_response(
4646
or None if the response was invalid.
4747
"""
4848
if json_schema:
49-
with open(json_schema, "r", encoding="utf-8") as f:
49+
schema_path = Path(json_schema)
50+
if not schema_path.exists():
51+
raise FileNotFoundError(f"JSON schema file not found: {schema_path}")
52+
with open(schema_path, "r", encoding="utf-8") as f:
5053
schema = json.load(f)
5154
else:
5255
schema = None

ai_feedback/models/DeepSeekV3Model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ def generate_response(
5252
Optional[Tuple[str, str]]: A tuple containing the prompt and the model's response,
5353
or None if the response was invalid.
5454
"""
55-
schema = None
5655
if json_schema:
57-
with open(json_schema) as f:
56+
schema_path = Path(json_schema)
57+
if not schema_path.exists():
58+
raise FileNotFoundError(f"JSON schema file not found: {schema_path}")
59+
with open(schema_path, "r", encoding="utf-8") as f:
5860
schema = json.load(f)
61+
else:
62+
schema = None
5963

6064
prompt = f"{system_instructions}\n{prompt}"
6165
if llama_mode == 'server':

ai_feedback/models/OpenAIModelVector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ def generate_response(
6767
if not self.model:
6868
raise RuntimeError("Model was not created successfully.")
6969

70-
schema = None
7170
if json_schema:
72-
with open(json_schema, "r") as f:
71+
schema_path = Path(json_schema)
72+
if not schema_path.exists():
73+
raise FileNotFoundError(f"JSON schema file not found: {schema_path}")
74+
with open(schema_path, "r", encoding="utf-8") as f:
7375
schema = json.load(f)
76+
else:
77+
schema = None
7478

7579
request = "Uploaded Files: "
7680
file_ids: List[str] = []

0 commit comments

Comments
 (0)