-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
esp32 picture to base64 to chatGPT_Client.vision_question #9
Comments
@robomaniac Memory consumption reaches its peak when doing HTTP Posts, including Base64 encoded strings. |
I did try to make smaller images but the issue is how I assemble/construct the base64 URL, how you attach data:image/jpeg;base64, to image taken, merge the 2/ Strycopy does not cut it. This is json section in python that works. I need to reproduce this json format in C.
|
It worked like this. const char *base64Prefix = "data:image/jpeg;base64,";
auto inputLength = fb->len; // Get the length of the framebuffer data
size_t prefixLength = strlen(base64Prefix);
// Calculate the total length for the buffer
size_t totalLength = prefixLength + base64::encodeLength(inputLength);
// Allocate buffer to hold the concatenated string
char *output = new char[totalLength + 1]; // +1 for null terminator
// Copy the prefix into the output buffer
strcpy(output, base64Prefix);
// Encode the framebuffer data into the output buffer after the prefix
base64::encode((const uint8_t *)fb->buf, inputLength, output + prefixLength);
// Ensure the output buffer is null-terminated
output[totalLength] = '\0';
Serial.println(prompt);
if (chatGPT_Client.vision_question("gpt-4o", "user", "text", prompt, "image_url", output, "auto", 200, true, chatGPTresult)) {
Serial.print("[ChatGPT] Response: ");
Serial.println(chatGPTresult);
} else {
Serial.print("[ChatGPT] Error: ");
Serial.println(chatGPTresult);
}
delete[] output; |
I want to take picture with esp32 convert to base64 and send it to chatgpt
I have issue to convert the picture to base64, can you share your function
I came up with this function
then pass
base64Image
to the functionif I paste this string into online tool, it does show my picture but there is error which could explain why chatgpt api does not take it, returns error.
This is the function that take picture and convert to base64
next step for me is to try other base64 library until that online website does not detect any error
The text was updated successfully, but these errors were encountered: