Add (ai gen): auto-select categories
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
use App\Models\AiWriteup;
|
||||
use App\Models\Post;
|
||||
use App\Models\PostCategory;
|
||||
use App\Models\Category;
|
||||
use App\Models\ShopeeSellerCategory;
|
||||
use App\Models\ShopeeSellerScrape;
|
||||
use App\Models\ShopeeSellerScrapedImage;
|
||||
@@ -54,7 +55,15 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
$ai_writeup = AiWriteup::where('source', 'shopee')->where('source_url', $shopee_task->product_task->response->url)->first();
|
||||
|
||||
if (is_null($ai_writeup)) {
|
||||
$ai_output = OpenAI::writeProductArticle($excerpt, $photos);
|
||||
|
||||
$categories = [
|
||||
'Beauty',
|
||||
'Technology',
|
||||
'Home & Living',
|
||||
'Health & Fitness'
|
||||
];
|
||||
|
||||
$ai_output = OpenAI::writeProductArticle($excerpt, $photos, $categories);
|
||||
|
||||
//dd($ai_output);
|
||||
|
||||
@@ -65,11 +74,19 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
inspector()->reportException($e);
|
||||
throw ($e);
|
||||
} else {
|
||||
|
||||
$picked_category = Category::where('name', $ai_output->category)->where('country_locale_id', $shopee_seller_scrape->category->country_locale_id)->first();
|
||||
|
||||
if (is_null($picked_category))
|
||||
{
|
||||
$picked_category = $shopee_seller_scrape->category;
|
||||
}
|
||||
|
||||
// save
|
||||
$ai_writeup = new AiWriteup;
|
||||
$ai_writeup->source = 'shopee';
|
||||
$ai_writeup->source_url = $shopee_task->product_task->response->url;
|
||||
$ai_writeup->category_id = $shopee_seller_scrape->category->id;
|
||||
$ai_writeup->category_id = $picked_category->category->id;
|
||||
$ai_writeup->title = $ai_output->title;
|
||||
$ai_writeup->excerpt = $ai_output->excerpt;
|
||||
$ai_writeup->featured_image = '';
|
||||
@@ -120,7 +137,7 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
|
||||
PostCategory::create([
|
||||
'post_id' => $post->id,
|
||||
'category_id' => $shopee_seller_scrape->category->id,
|
||||
'category_id' => $picked_category->id,
|
||||
]);
|
||||
|
||||
if (app()->environment() == 'production') {
|
||||
|
||||
Reference in New Issue
Block a user