Add (ai gen)

This commit is contained in:
2023-10-01 04:17:49 +08:00
parent 5fcfa75d97
commit 5b4a02778e
7 changed files with 191 additions and 84 deletions

View File

@@ -10,9 +10,11 @@ class OpenAI
{
public static function writeProductArticle($excerpt, $photos)
{
$excerpt = substr($excerpt, 0, 900);
$system_prompt = '
You are tasked with writing a comprehensive product introduction article using the provided excerpt. The emphasis should be on the performance, features, and notable aspects of the product. The review should avoid the use of personal pronouns and must not delve into marketplace-related information. Return the output in the following json format:\n\n
{"title": "(Article Title)","excerpt": "(One sentence summary, 150-160 characters of an article, do not use start sentence with verb.)","cliffhanger": "(One sentence 70-80 characters of article, cliff-hanging sentence to attract readers)","body": "(Markdown format, 500-700 word count)"}\n\n
{"title": "(Article Title)","excerpt": "(One sentence summary, 150-160 characters of an article, do not use start sentence with verb.)","cliffhanger": "(One sentence 70-80 characters of article, cliff-hanging sentence to attract readers)","body": "(Markdown format, 700-900 word count)"}\n\n
Mandatory Requirements:\n
- Write in US grade 8-9 English\n
- Use the following sections whenever applicable:\n
@@ -24,16 +26,23 @@ public static function writeProductArticle($excerpt, $photos)
- do not make up facts, use facts provided by excerpt only\n
- No article titles inside markdown\n
- All article sections use ###
- Add at least 3 markdown images with article title as caption in every section except for Introduction
';
$user_prompt = "Excerpt: {$excerpt}\nPhotos:\n";
$user_prompt = "EXCERPT\n------------\n{$excerpt}\n";
foreach ($photos as $photo) {
$user_prompt .= "{$photo}\n";
if (count($photos) > 0) {
$system_prompt .= '- Add at least 3 markdown images with article title as caption in every section except for Introduction';
$user_prompt .= "\n\nPHOTOS\n------------\n";
foreach ($photos as $photo) {
$user_prompt .= "{$photo}\n";
}
}
$output = (self::chatCompletion($system_prompt, $user_prompt, 'gpt-3.5-turbo', 2000));
$output = (self::chatCompletion($system_prompt, $user_prompt, 'gpt-3.5-turbo', 2500));
// dump($user_prompt);
// dd($output);
if (! is_null($output)) {
try {