Skip to content

Commit 4dc6c02

Browse files
committed
emphasize strict JSON response format
1 parent dfd4fd6 commit 4dc6c02

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/openai/constants/prompts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
'Target reading grade level: {target_reading_grade_level}'
33
)
44

5-
OPENAI_PROMPT_INSTRUCTION__JSON_RESPONSE = 'The response content MUST ONLY contain strictly valid JSON, and MUST be able to be parsed directly using standard Python `json.loads(response_content)`.' # noqa: E501
6-
7-
85
OPENAI_PROMPT_INSTRUCTION__EXPECTED_RESPONSE_FORMAT = (
96
'Expected response format:'
107
)
8+
9+
OPENAI_PROMPT_INSTRUCTION__JSON_RESPONSE = 'The response content MUST ONLY contain strictly valid JSON, no wrapping text or delimiters, and MUST be able to be parsed directly using standard Python: `json.loads(response_content)`.' # noqa: E501

lib/openai/models/system_prompt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ def response_parameters_instructions(self) -> list[str]:
8989
target_reading_grade_level=self.target_reading_grade_level
9090
)
9191
)
92-
if self.as_json:
93-
content_lines.append(OPENAI_PROMPT_INSTRUCTION__JSON_RESPONSE)
9492

9593
if self.expected_response_format:
9694
content_lines.append(
@@ -101,6 +99,10 @@ def response_parameters_instructions(self) -> list[str]:
10199
+ self.expected_response_format
102100
+ '```'
103101
)
102+
103+
if self.as_json:
104+
content_lines.append(OPENAI_PROMPT_INSTRUCTION__JSON_RESPONSE)
105+
104106
return content_lines
105107

106108
@property

0 commit comments

Comments
 (0)