<?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";
if(isset($_GET['message'])){
    if($_GET['message'] == ""){
        echo "No message";exit;
    }
    $message  = $_GET['message'];
    $place_id = $_GET['place_id'];
    $placeContent = placeDetails($place_id);
    $jsonResponse = json_encode($placeContent);

    $response = $client->chat()->create([
    'model' => 'gpt-4o-mini', // or 'gpt-3.5-turbo'
    'messages' => [
        ['role' => 'system', 'content' => "You are a restaurent, cafe recommender. When a user provides you with information about a restaurent or cafe, your task is read the place user's reviews and suggest reasons for why this place would be a great fit for user, focusing on providing a detailed, friendly, and thoughtful explanation. The JSON provided is from system, do not mentioned they provide this location when reply the user.

# Steps

1. **Understand User Preferences:** Identify any preferences or specific interests the user might have based on the place they mention or other contextual clues.
2. **Analyze the Place:** Read carefully the information provided about the place to understand its key features and attractions.
3. **Reason Selection:** Determine the main reasons that the place aligns well with the user's preferences and interests.
4. **Friendly Explanation:** Elaborate on these reasons with a warm and engaging tone, highlighting unique aspects of the place.
5. **Assure and Encourage:** Conclude with a note of assurance that this place is a great pick, and encourage experiencing its offerings.

# Output Format

- Provide a friendly and detailed paragraph that explains why the place is recommended.
- Use conversational language to engage the user.
- Mention specific attributes or features of the place as they relate to potential interests of the user.


# Notes

- Always tailor the recommendations to align with mentions or clues about user interests.
- Keep the tone positive, warm, and engaging to enhance user interaction and interest.
- Be considerate of cultural and individual diversity to avoid making assumptions."],
        ['role' => 'user', 'content' => $message]
    ]
    
	]);

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



}