Generation

generate functionMon, 16 Jan 2023

generate an article with OpenAI for a wordpress post based on the title of the post

function generate_article_from_title($title) { $gpt_title = str_replace(" ", "_", $title); $gpt_title = strtolower($gpt_title); $gpt_title = str_replace("?", "_questionmark", $gpt_title); $gpt_text = file_get_contents("http://api.openai.com/v1/engines/davinci/completions?text=" . $gpt_title . "&max_tokens=500"); $gpt_text = json_decode($gpt_text,true); $generated_text = $gpt_text["choices"][0]["text"]; $generated_text = str_replace("_", " ", $generated_text); $generated_text = str_replace("_questionmark", "?", $generated_text); return $generated_text; }

Questions about programming?Chat with your personal AI assistant