|
|
@@ -20,29 +20,22 @@ class ChatGPT {
|
|
|
return $response->json()['choices'][0]['message']['content'] ?? false;
|
|
|
}
|
|
|
|
|
|
- public static function getClientInfo($data) {
|
|
|
- if ($client = Client::where('email', $data['email'])->first()) {
|
|
|
+ public static function getClientInfo($prompt, Client $client) {
|
|
|
+ if ($client) {
|
|
|
+// return ['images' => [1,2], 'explanation' => 'test'];
|
|
|
try {
|
|
|
$request = [
|
|
|
[
|
|
|
'role' => 'system',
|
|
|
- 'content' => $data['prompt'] . ' . Please respond with the image numbers separated by comma and explanation in two rows separated by the new line. If there won\'t be any images matching the request please put null for the "images" key'
|
|
|
+ 'content' => $prompt . ' . Please respond with the image numbers separated by comma and explanation, JSON only, without any extra formatting, such as triple backticks or quotation marks. Just the raw JSON as text. If there won\'t be any images matching the request please put null for the "images" key'
|
|
|
],
|
|
|
[
|
|
|
"role" => "user",
|
|
|
-// "content" => [
|
|
|
-// [
|
|
|
-// 'type' => 'text',
|
|
|
-// 'text' => ''
|
|
|
-// ]
|
|
|
-// ]
|
|
|
]
|
|
|
];
|
|
|
|
|
|
- $photos = [];
|
|
|
if ($client->photos) {
|
|
|
foreach ($client->photos as $photo) {
|
|
|
- $photos[] = Storage::disk('public')->get($photo->path);
|
|
|
$request[1]['content'][] = [
|
|
|
"type" => "image_url",
|
|
|
"image_url" => [
|
|
|
@@ -53,26 +46,17 @@ class ChatGPT {
|
|
|
}
|
|
|
|
|
|
$response = ChatGPT::processRequest($request);
|
|
|
- dump($response);
|
|
|
- die;
|
|
|
|
|
|
- if ($response) {
|
|
|
- $data = json_decode($response, true);
|
|
|
-
|
|
|
- dd($data);
|
|
|
-
|
|
|
-// if ($data['images']) {
|
|
|
-// }
|
|
|
-//
|
|
|
-// return ;
|
|
|
+ if (json_validate($response)) {
|
|
|
+ return json_decode($response, true);
|
|
|
}
|
|
|
|
|
|
throw new \Exception('Can\'t process your request');
|
|
|
- } catch (\Exception $e) {
|
|
|
-
|
|
|
+ } catch (\Exception $th) {
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
-}
|
|
|
+}
|