Actually, it’s the AI API (Which I use in my project) that requires the JSON in a specific format—like {"role":"user","content":"text"}—or it’ll throw an error saying the JSON is malformed.
If it has some same key name, how could i do ?
Like
{"role":"user","content":"text1","role":"system","content":"text2","role":"user","content":"text3"}........
sorry,i may get wrong last time.
The ture json is [{"role":"user","content":"text1"},{"role":"system","content":"text2"},{"role":"user","content":"text3"}]
but it will turn to be [{"content":"text1","role":"user"},{"content":"text2","role":"system"},{"content":"text3","role":"user"}]
which order from A to Z
actually, i dont know how difference between these tag....but i am using the "TinyDB"(not web) to do it.
and i want to save the history into my phone local but not online.
could you offer me another plan? or explain the difference between them?
To preserve the list order of a chat history locally, pick a tag for when the chat started, like 2025-12-21-14:40 (My local time for when this board thread started in date time sort order).
Start the value under that tag as an empty list.
As each message arrives as a three key dictionary,
retrieve the chat history for the current chat start datetime as a list into a local variable named history (empty list if not found)
add the message dictionary object to the list history
save the updated chat history list back into its TinyDB tag.