Skip to content

Commit

Permalink
Add productType to product update mutation and refactor product cate…
Browse files Browse the repository at this point in the history
…gorization response handling
  • Loading branch information
jamalsoueidan committed Jul 1, 2024
1 parent 1fc9019 commit 148a0f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const PRODUCT_FRAGMENT = `#graphql
handle
tags
title
productType
variants(first: 1) {
nodes {
id
Expand Down Expand Up @@ -241,10 +242,6 @@ const PRODUCT_FRAGMENT = `#graphql
id
value
}
parentId: metafield(key: "parentId", namespace: "booking") {
id
value
}
scheduleId: metafield(key: "scheduleId", namespace: "booking") {
id
value
Expand Down Expand Up @@ -282,8 +279,8 @@ const PRODUCT_FRAGMENT = `#graphql

export const PRODUCT_UPDATE = `#graphql
${PRODUCT_FRAGMENT}
mutation ProductUpdate($id: ID, $metafields: [MetafieldInput!], $tags: [String!], $title: String, $descriptionHtml: String) {
productUpdate(input: {id: $id, metafields: $metafields, tags: $tags, title: $title, descriptionHtml: $descriptionHtml, status: ACTIVE}) {
mutation ProductUpdate($id: ID, $metafields: [MetafieldInput!], $tags: [String!], $title: String, $productType: String, $descriptionHtml: String) {
productUpdate(input: {id: $id, metafields: $metafields, tags: $tags, title: $title, productType: $productType, descriptionHtml: $descriptionHtml, status: ACTIVE}) {
product {
...UpdateProductFragment
}
Expand Down
20 changes: 10 additions & 10 deletions src/functions/openai/services/product-categorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ Respond with this JSON structure:
"collections": [
{
id: "gid://shopify/Collection/1111",
title: "example",
ruleSet: {
rules: [{
column
condition
}],
},
},
],
}`;
Expand All @@ -57,14 +50,21 @@ Respond with this JSON structure:
content,
},
],
max_tokens: 20000,
max_tokens: 4096,
response_format: {
type: "json_object",
},
});

return JSON.parse(response.choices[0].message.content as any)
.collections as CollectionsQuery["collections"]["nodes"];
const collections = JSON.parse(
response.choices[0].message.content as any
).collections;

const newResponse: CollectionsQuery["collections"]["nodes"] =
collections.map(({ id }: { id: string }) => {
return data?.collections.nodes.find((c) => c.id === id);
});
return newResponse;
} catch (error) {
console.error("Error:", error);
}
Expand Down

0 comments on commit 148a0f5

Please sign in to comment.