You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to send a message along with an attached file using the client->chat()->create method with the model gpt-4o-2024-05-13. Below is the code snippet I am currently using:
However, this results in a 500 Internal Server Error.
I would like to know the correct way to send a file and attach it to a message using the client->chat()->create method. What am I doing wrong, and how can I fix it?
Thank you in advance for your help!
The text was updated successfully, but these errors were encountered:
I am trying to send a message along with an attached file using the client->chat()->create method with the model gpt-4o-2024-05-13. Below is the code snippet I am currently using:
public function sendMessage(Request $request)
{
$request->validate([
"message" => "required|string",
"file" => "required|file",
]);
$message = $request->input("message");
$file = $request->file("file");
$filePath = $file->getPathname();
$fileName = $file->getClientOriginalName();
// Upload the file
$fileContent = file_get_contents($filePath);
$response = $this->client->files()->upload([
"file" => $fileContent,
"filename" => $fileName,
]);
// Send the message
$response = $this->client->chat()->create([
"model" => "gpt-4o-2024-05-13",
"messages" => [
["role" => "user", "content" => $message]
],
"attachments" => [
["id" => $response["id"]]
],
]);
return response()->json($response);
}
However, this results in a 500 Internal Server Error.
I would like to know the correct way to send a file and attach it to a message using the client->chat()->create method. What am I doing wrong, and how can I fix it?
Thank you in advance for your help!
The text was updated successfully, but these errors were encountered: