Skip to content

Commit af64e53

Browse files
authored
OpenAI Chat - parse JSON for responseType json_schema (#16994)
* parse json for response type json_schema * update
1 parent 9801339 commit af64e53

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

components/openai/actions/chat/chat.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ConfigurationError } from "@pipedream/platform";
66
export default {
77
...common,
88
name: "Chat",
9-
version: "0.2.8",
9+
version: "0.2.9",
1010
key: "openai-chat",
1111
description: "The Chat API, using the `gpt-3.5-turbo` or `gpt-4` model. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
1212
type: "action",
@@ -159,6 +159,16 @@ export default {
159159
},
160160
});
161161

162+
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
163+
for (const choice of response.choices) {
164+
try {
165+
choice.message.content = JSON.parse(choice.message.content);
166+
} catch {
167+
console.log(`Unable to parse JSON: ${choice.message.content}`);
168+
}
169+
}
170+
}
171+
162172
if (response) {
163173
$.export("$summary", `Successfully sent chat with id ${response.id}`);
164174
}

components/openai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/openai",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "Pipedream OpenAI Components",
55
"main": "openai.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)