DEVLOG #9
What I did
For this block, I fixed minor details to make the prompting more seamless. First, I fixed the deserialization so that only the response would be printed. I also used Serial.readString() so the user can send multiple prompts without having to reupload the code with a new prompt
Challenges
Getting the Deserialization and print to work
So this was a really annoying problem that I should not have had this much trouble with. When you receive the response from the AI, it comes back as JSON, with the response as well as other information like the date created, context, etc. I only wanted to print the response, so I tried using deserializeJson() from the ArduinoJson.h library. But for some reason, I kept getting null when trying to print the response element. I tried messing around with the data types, switching between string and const char*, but those didn’t work. I also tried basing my code off of an example from the ArduinoJson website, but it still would not work. Then I created an if statement that checked if there was an element in the JSON labeled response. This returned false, which meant that the data was not deserializing properly. At that point, I felt pretty lost. But then I thought of deserializing the JSON in the Python script and then sending just the response. So I looked into how to deserialize JSON strings through Python, and I came across json.loads() from the json library. There are two main versions of this method: json.loads() and json.load(). .load deserializes a file, while .loads deserializes a string. Because the response from the AI came back as a string, I was able to use the latter to separate the response from the rest of the data, which I was then able to send back and print successfully.
What is next
Now that I pretty much have the prompting working, my next course of action is likely going to be to figure out how to use the camera and send the feed to the AI. This will definitely be challenging, as I have no idea how I want this part of the project to work. Thank you.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.