Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support json_schema for openai endpoint #432

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
liqul marked this conversation as resolved.
Show resolved Hide resolved
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"
liqul marked this conversation as resolved.
Show resolved Hide resolved
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
}