Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Properly Send and Attach a File to client->chat()->create with Model gpt-4o-2024-05-13 #446

Open
andrey-project-launcher opened this issue Jul 9, 2024 · 0 comments

Comments

@andrey-project-launcher
Copy link

andrey-project-launcher commented Jul 9, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant