{"id":4444,"date":"2024-01-24T10:31:09","date_gmt":"2024-01-24T09:31:09","guid":{"rendered":"https:\/\/rent-a-pilot.nl\/?p=4444"},"modified":"2024-01-24T12:01:05","modified_gmt":"2024-01-24T11:01:05","slug":"formidableforms-send-form-data-to-chatgpt-via-api","status":"publish","type":"post","link":"https:\/\/rent-a-pilot.nl\/nl\/formidableforms-send-form-data-to-chatgpt-via-api\/","title":{"rendered":"Formidableforms: Send form data to ChatGPT via API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have some texts that I want to send to ChatGPT for editing and translation. This is a way to do that. This post is a way for me to document what I did and maybe you find it useful if you happen to find it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The texts that I want to input are written in a mix of Dutch and English so I want to be able to tell ChatGPT to fix that and then translate it into English.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can obtain more advanced functionality with a custom GPT but the disadvantage there is that you need a pro license for each person using that. With this solution you can share the functionality on a private server or to authorised users and decide how you want to pay for the API usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Requirements<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WordPress (duh)<\/li>\n\n\n\n<li>Formidableforms plugin<\/li>\n\n\n\n<li>Formidable API addon<\/li>\n\n\n\n<li>A ChatGPT API key<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Create a form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a form that has at least three fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Input (Invoer)<\/li>\n\n\n\n<li>Answer (Antwoord)<\/li>\n\n\n\n<li>Instructions (Instructions)<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"740\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1024x740.png\" alt=\"\" class=\"wp-image-4445\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1024x740.png 1024w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-300x217.png 300w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-768x555.png 768w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-18x12.png 18w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image.png 1085w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Input:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can set the Input field to type &#8220;rich text&#8221; (if you have the pro version of Formidableforms). This looks nice later on but with the disadvantage that the rich text field does not have the &#8220;auto grow&#8221; option that the normal text field does have. Your choice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Answer:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I will use this field later to save the API reply from chatgpt.<br>It is a standard text field with the auto grow option enabled.<br>This requires the use of a code snippet that I will cover later.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Instructions:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the part where you tell chatgpt what to do.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use a standard text field with the &#8220;Auto Grow&#8221; option enabled.<\/li>\n\n\n\n<li>Put the default instruction that you want to pass to chatgpt in the &#8220;Default Value&#8221; and let the user edit this if they want. <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"435\" height=\"901\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1.png\" alt=\"\" class=\"wp-image-4448\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1.png 435w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1-145x300.png 145w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-1-6x12.png 6w\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The actual instructions are a lot longer than that.<br>Figure out a good prompt, it is the sauce that makes this thing awesome.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Form options &#8211; sending the input to chatgpt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is where you need the API addon. Go to the form settings and add an API action. I called mine &#8220;Zend data naar ChatGPT&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"614\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2-1024x614.png\" alt=\"\" class=\"wp-image-4451\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2-1024x614.png 1024w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2-300x180.png 300w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2-768x460.png 768w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2-18x12.png 18w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-2.png 1121w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Configure the API action<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"826\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3-1024x826.png\" alt=\"\" class=\"wp-image-4452\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3-1024x826.png 1024w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3-300x242.png 300w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3-768x620.png 768w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3-15x12.png 15w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-3.png 1150w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Action name:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Whatever you want. I choose &#8220;Zend data naar ChatGPT&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Trigger:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Set this to &#8220;Entry is created&#8221; and &#8220;Entry is updated&#8221;.<br>This will allow you to publish the result on a view later and offer to option to edit the entry and allow the user to fine tune the input and the instructions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The howto I will post later along with the code snippet for the API answer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Notification URL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/api.openai.com\/v1\/chat\/completions<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Auth:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ok here comes one of the interesting bits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the API docs it states that you should use something called &#8220;bearer authorization&#8221; but you cannot put that in here.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"790\" height=\"232\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4.png\" alt=\"\" class=\"wp-image-4455\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4.png 790w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4-300x88.png 300w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4-768x226.png 768w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-4-18x5.png 18w\" sizes=\"auto, (max-width: 790px) 100vw, 790px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you dig a little deeper you will find that you can do it like this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Basic Auth, leave the username empty and just write a colon followed by your API key. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"257\" src=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-5.png\" alt=\"\" class=\"wp-image-4456\" srcset=\"https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-5.png 547w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-5-300x141.png 300w, https:\/\/rent-a-pilot.nl\/wp-content\/uploads\/2024\/01\/image-5-18x8.png 18w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Even if you insert the actual API key here the test connection fails but THE API WILL WORK.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Data Format:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>raw<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Method:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>POST (= default)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Character Set:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use blog charset (= default)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Raw Data:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You now need some JSON code. Put this in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br>    \"model\": \"gpt-4-1106-preview\",<br>    \"messages\": &#91;<br>        {<br>            \"role\": \"system\",<br>            \"content\": \"&#91;2929]\"<br>        },<br>        {<br>            \"role\": \"user\",<br>            \"content\": \"&#91;2928]\"<br>        }<br>    ]<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I used the latest preview model of today but that can change. Look for the model names <a href=\"https:\/\/platform.openai.com\/docs\/models\/continuous-model-upgrades\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Replace<\/strong> [2929] in<br>&#8220;role&#8221;: &#8220;system&#8221;,<br>&#8220;content&#8221;: &#8220;[2929]&#8221;<br>with the field number of field that contains the <strong>instructions<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Replace<\/strong> [2928] in<br>&#8220;role&#8221;: &#8220;user&#8221;,<br> &#8220;content&#8221;: &#8220;[2928]&#8221;<br>with the field number of field that contains the <strong>input<\/strong>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the options, you&#8217;re done.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Chatgpt API reference<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Look <a href=\"https:\/\/platform.openai.com\/docs\/api-reference\/making-requests\" target=\"_blank\" rel=\"noreferrer noopener\">here for the docs<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have some texts that I want to send to ChatGPT for editing and translation. This is a way to do that. This post is a way for me to document what I did and maybe you find it useful if you happen to find it. The texts that I want to input are written [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[126,125],"tags":[121,128],"class_list":["post-4444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gutenberg","category-wordpress","tag-chatgpt","tag-formidableforms"],"_links":{"self":[{"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/posts\/4444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/comments?post=4444"}],"version-history":[{"count":11,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/posts\/4444\/revisions"}],"predecessor-version":[{"id":4470,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/posts\/4444\/revisions\/4470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/media\/4465"}],"wp:attachment":[{"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/media?parent=4444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/categories?post=4444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rent-a-pilot.nl\/nl\/wp-json\/wp\/v2\/tags?post=4444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}