<?php
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use OpenAI;
$openaiKey = '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';
$assistantId= 'asst_CfxsYXP15SzsBXo2SEhP84Jf';
$client = OpenAI::client($openaiKey);

require "library.php";
$_GET['message'] = '[
    {"name":"The Butcher\'s Table @SS2","phone":"03-7733 2843"},
    {"name":"IBERICO KITCHEN","phone":"012-773 7173"},
    {"name":"Savage by Foreli","phone":"016-508 0493"},
    {"name":"Me’nate Steak Hub @PJ New Town","phone":"03-7931 1919"},
    {"name":"Uncle Don\'s (SS2, Petaling Jaya)","phone":"016-945 1074"},
    {"name":"Grub by Ahong & Friends","phone":"014-607 2983"},
    {"name":"Gyuden Yakiniku","phone":"012-404 6966"},
    {"name":"Mido","phone":"03-7865 9779"},
    {"name":"Simply Ribs, Halal","phone":"017-335 6852"},
    {"name":"TTDI Meat Point - حلال","phone":"014-360 4040"},
    {"name":"The Brew House @SS2","phone":"03-7865 6815"},
    {"name":"habanna charbroil steakhouse old","phone":"018-227 7369"},
    {"name":"Me\'nate Steak Hub (The Curve Mutiara Damansara)","phone":"03-7613 6988"},
    {"name":"Luckypot SS2 Restaurant","phone":"019-576 8749"},
    {"name":"Anmour Cafe SS2 PJ","phone":"03-7865 5677"},
    {"name":"Murni Discovery SS2","phone":"012-529 9601"},
    {"name":"Old Western CowBoy Steak House","phone":"018-242 5580"},
    {"name":"Frenchie\'s Brunch & Dates","phone":"012-235 0019"},
    {"name":"Strangers at 47","phone":"012-745 4749"},
    {"name":"Carnaval Churrascaria","phone":"012-377 2252"}
]';

if(isset($_GET['message'])){
    if($_GET['message'] == ""){
        echo "No message";exit;
    }
    $message  = $_GET['message'];

    $response = $client->chat()->create([
    'model' => 'gpt-4o-mini', // or 'gpt-3.5-turbo'
    'response_format'=>[
      "type"=> "json_object"
    ],
    'messages' => [
        ['role' => 'system', 'content' => 'You are an intelligent and friendly Lifestyle Location Recommender. Your primary function is to assist users in finding suitable places based on their preferences. User will send you JSON with list of location, and his preferences. Choose 10 of the location that suitable, and tell user the location summary, pro and con,with longer sentense, in this format

{
  "message": "Here are some cheap restaurants we suggest for you",
  "places": [
    {
      "title": "Bear Furry House",
      "summary": "Highly praised for its grooming services and the care they show to pets.",
      "place_id": "ChIJMWbeGr1NzDER0SSVmuzdNEM",
      "image_ref": "places/ChIJ48UkXKVNzDERTayA_Psb7jc/photos/AVzFdbmGHxCUyvyKMtWl1QMDIamz2chqQT2oQcW9fvzipTE1AtNPMtwyqKg1ybevOp940unzJ8L5nqVX53vlOMOlxMBXf5DGfIVi-4WmnHvIlkWttPPfAy1K5irvzkKyIVuRoUU_VvD-9MI0De0xFvrr8v3lrBL3AYL12j9S",
      "phone": "036781921",
      "pro": "Something good",
      "con": "Something bad",
    }
  ]
}'],
        ['role' => 'user', 'content' => $message]
    ]
    
  ]);

  // Output the response
  echo $response['choices'][0]['message']['content'];



}

