You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: headless-cms/smart-seo-open-ai/5.41.x/extensions/smartSeoOpenAi/admin/src/DecorateContentEntryFormBind.tsx
constprompt=`You will be provided with one or more paragraphs of HTML, and you need to extract a SEO optimized page title, a page summary, and up to 5 keywords. Response should be returned as a plain JSON object, with "title" field for the page title, "description" field for page summary, and "keywords" field as an array of keywords.`;
* A button component to trigger OpenAI's GPT model to generate SEO fields.
58
-
* Extracts rich-text content, sends it to GPT, and updates the form fields with the AI's suggestions.
59
-
*/
60
23
constGetSeoData=()=>{
24
+
constclient=useApolloClient();
25
+
constform=useForm();
61
26
const{ showSnackbar }=useSnackbar();
62
27
const[loading,setLoading]=useState(false);
63
28
const{ fields }=useFieldTracker();
64
29
65
30
constaskChatGpt=async()=>{
66
-
letresponse;
67
31
setLoading(true);
68
32
try{
69
-
response=awaitopenai.chat.completions.create({
70
-
model: "gpt-3.5-turbo",
71
-
messages: [
72
-
{
73
-
role: "system",
74
-
content: prompt
75
-
},
76
-
{
77
-
role: "user",
33
+
const{ data }=awaitclient.query({
34
+
query: GENERATE_SEO_QUERY,
35
+
variables: {
36
+
input: {
78
37
content: extractRichTextHtml(fields).join("\n")
79
38
}
80
-
],
81
-
temperature: 0.5,
82
-
max_tokens: 128,
83
-
top_p: 1
39
+
}
84
40
});
85
-
}catch(e){
86
-
console.log(e);
87
-
}
88
-
setLoading(false);
89
41
90
-
console.log("ChatGPT response",response);
91
-
try{
92
-
// const seo = {
93
-
// title: "Node.js, Yarn, and AWS Setup Guide for Webiny",
94
-
// description:
95
-
// "Learn how to set up Node.js, yarn, and AWS account and user credentials for deploying Webiny. Make sure you have the required versions installed.",
0 commit comments