Skip to content

Commit 7f48bb7

Browse files
authoredOct 21, 2024··
Support json_schema for openai endpoint (#432)
1 parent a2d6de3 commit 7f48bb7

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed
 

‎requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ pandas>=2.0.0
33
matplotlib>=3.4
44
seaborn>=0.11
55
python-dotenv>=1.0.0
6-
openai>=1.2.4
6+
openai>=1.42.0
7+
pydantic>=2.8.2
78
pyyaml>=6.0
89
scikit-learn>=1.2.2
910
click>=8.0.1

‎scripts/build_executor.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55
echo "The script directory is: $scriptDirectory"
66

7-
version="0.2"
7+
version="0.3"
88
imageName="taskweavercontainers/taskweaver-executor"
99
imageFullName="$imageName:$version"
1010

‎taskweaver/code_interpreter/code_interpreter/code_generator_prompt.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ response_json_schema: |-
3636
"properties": {
3737
"thought": {
3838
"type": "string",
39-
"maxLength": 1000,
4039
"description": "The thoughts before generating the code."
4140
},
4241
"reply_type": {
@@ -49,20 +48,21 @@ response_json_schema: |-
4948
},
5049
"reply_content": {
5150
"type": "string",
52-
"minLength": 10,
5351
"description": "The actual content of the response. If the reply_type is 'python', the content should be a valid python code snippet. Make sure escaping the special characters (e.g., '\\', '/', and '\"') in the strings for JSON format."
5452
}
5553
},
5654
"required": [
5755
"thought",
5856
"reply_type",
5957
"reply_content"
60-
]
58+
],
59+
"additionalProperties": false
6160
}
6261
},
6362
"required": [
6463
"response"
65-
]
64+
],
65+
"additionalProperties": false
6666
}
6767
6868

‎taskweaver/llm/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _configure(self) -> None:
5555

5656
self.response_format: Optional[str] = self._get_enum(
5757
"response_format",
58-
options=["json_object", "text"],
58+
options=["json_object", "text", "json_schema"],
5959
default="json_object",
6060
)
6161

‎taskweaver/llm/openai.py

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ def chat_completion(
180180
response_format = kwargs["response_format"]
181181
elif self.config.response_format == "json_object":
182182
response_format = {"type": "json_object"}
183+
elif self.config.response_format == "json_schema":
184+
response_format = {"type": "json_schema"}
185+
assert "json_schema" in kwargs, "JSON schema is required for JSON schema response format"
186+
response_format["json_schema"] = {
187+
"name": "response",
188+
"strict": True,
189+
"schema": kwargs["json_schema"],
190+
}
183191
else:
184192
response_format = None
185193

‎taskweaver/planner/planner_prompt.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ response_json_schema: |-
150150
"plan",
151151
"current_plan_step",
152152
"send_to",
153-
"message"
154-
]
153+
"message",
154+
"review"
155+
],
156+
"additionalProperties": false
155157
}
156158
},
157159
"required": [
158160
"response"
159-
]
161+
],
162+
"additionalProperties": false
160163
}

0 commit comments

Comments
 (0)
Please sign in to comment.