Skip to content

Commit

Permalink
support openai json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
liqul committed Oct 21, 2024
1 parent 2068db4 commit d7df0cd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pandas>=2.0.0
matplotlib>=3.4
seaborn>=0.11
python-dotenv>=1.0.0
openai>=1.2.4
openai>=1.42.0
pydantic>=2.8.2
pyyaml>=6.0
scikit-learn>=1.2.2
click>=8.0.1
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "The script directory is: $scriptDirectory"

version="0.2"
version="0.3"
imageName="taskweavercontainers/taskweaver-executor"
imageFullName="$imageName:$version"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ response_json_schema: |-
"properties": {
"thought": {
"type": "string",
"maxLength": 1000,
"description": "The thoughts before generating the code."
},
"reply_type": {
Expand All @@ -49,20 +48,21 @@ response_json_schema: |-
},
"reply_content": {
"type": "string",
"minLength": 10,
"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."
}
},
"required": [
"thought",
"reply_type",
"reply_content"
]
],
"additionalProperties": false
}
},
"required": [
"response"
]
],
"additionalProperties": false
}
Expand Down
2 changes: 1 addition & 1 deletion taskweaver/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _configure(self) -> None:

self.response_format: Optional[str] = self._get_enum(
"response_format",
options=["json_object", "text"],
options=["json_object", "text", "json_schema"],
default="json_object",
)

Expand Down
8 changes: 8 additions & 0 deletions taskweaver/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ def chat_completion(
response_format = kwargs["response_format"]
elif self.config.response_format == "json_object":
response_format = {"type": "json_object"}
elif self.config.response_format == "json_schema":
response_format = {"type": "json_schema"}
assert "json_schema" in kwargs, "JSON schema is required for JSON schema response format"
response_format["json_schema"] = {
"name": "response",
"strict": True,
"schema": kwargs["json_schema"],
}
else:
response_format = None

Expand Down
9 changes: 6 additions & 3 deletions taskweaver/planner/planner_prompt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ response_json_schema: |-
"plan",
"current_plan_step",
"send_to",
"message"
]
"message",
"review"
],
"additionalProperties": false
}
},
"required": [
"response"
]
],
"additionalProperties": false
}

0 comments on commit d7df0cd

Please sign in to comment.