Add (ai gen)
This commit is contained in:
@@ -34,6 +34,8 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
$shopee_task->shopee_seller_scrape = $shopee_seller_scrape;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// dd($shopee_task);
|
||||
|
||||
// dd($shopee_task->product_task->response);
|
||||
@@ -42,6 +44,8 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
|
||||
$excerpt = self::stripHtml($raw_html);
|
||||
|
||||
$excerpt .= self::getProductPricingExcerpt($shopee_task->product_task->response->jsonld);
|
||||
|
||||
$photos = ShopeeSellerScrapedImage::where('shopee_seller_scrape_id', $shopee_seller_scrape->id)->where('featured', false)->orderByRaw('RAND()')->take(3)->get()->pluck('image')->toArray();
|
||||
|
||||
$ai_writeup = AiWriteup::where('source', 'shopee')->where('source_url', $shopee_task->product_task->response->url)->first();
|
||||
@@ -120,12 +124,38 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
return $post;
|
||||
}
|
||||
|
||||
private static function getProductPricingExcerpt(array $jsonLdData)
|
||||
{
|
||||
foreach ($jsonLdData as $data) {
|
||||
// Ensure the type is "Product" before proceeding
|
||||
if (isset($data->{'@type'}) && $data->{'@type'} === 'Product') {
|
||||
|
||||
// Extract necessary data
|
||||
$lowPrice = $data->offers->lowPrice ?? null;
|
||||
$highPrice = $data->offers->highPrice ?? null;
|
||||
$price = $data->offers->price ?? null;
|
||||
$currency = $data->offers->priceCurrency ?? null;
|
||||
$sellerName = $data->offers->seller->name ?? "online store"; // default to "online store" if name is not set
|
||||
|
||||
// Determine and format pricing sentence
|
||||
if ($lowPrice && $highPrice) {
|
||||
return "Price Range from {$currency} {$lowPrice} to {$highPrice} in {$sellerName}";
|
||||
} elseif ($price) {
|
||||
return "Priced at {$currency} {$price} in {$sellerName}";
|
||||
} else {
|
||||
return "Price not stated, refer to {$sellerName}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function getTotalServiceCost($shopee_task)
|
||||
{
|
||||
|
||||
$cost = 0.00;
|
||||
|
||||
$cost += 0.06; // chatgpt-3.5-turbo $0.03 for 1k, writing for 2k tokens
|
||||
$cost += 0.09; // chatgpt-3.5-turbo $0.03 for 1k, writing for 2k tokens
|
||||
|
||||
// Shopee Seller Scraping
|
||||
if (isset($shopee_task?->seller_shop_task?->response?->total_cost)) {
|
||||
|
||||
Reference in New Issue
Block a user