Sub Process_Globals
Private http As OkHttpUtils2
Private Json As JSONParser
End Sub
Sub AppStart
http.Initialize("http")
Json.Initialize
Dim json_string As String = "{\"id\":\"chatcmpl-6t2JQdgU1ypn0ayhONAkE6bAEoGkz\",\"object\":\"chat.completion\",\"created\":1678574948,\"model\":\"gpt-3.5-turbo-0301\",\"usage\":{\"prompt_tokens\":25,\"completion_tokens\":110,\"total_tokens\":135},\"choices\":[{\"message\":{\"role\":\"assistant\",\"content\":\"Ahoy matey, ye be askin' a great question. The worst investment be ones that promise quick riches without flappin' yer sails too much, like the \\\"get rich quick\\\" schemes, ponzi schemes Or pyramid schemes. These scams be all about misuse of trust And deceivin' the inexperienced. They be luring investors with high promised returns, but in the end, they just take yer doubloons and disappear into the horizon. Stay away from such crooks and keep yer treasure safe, me hearty!\"},\"finish_reason\":\"stop\",\"index\":0}]}"
' Parse the JSON string into a Map
Dim data As Map = Json.Parse(json_string)
' Access the message content
Dim message_content As String = data.Get("choices").Get(0).Get("message").Get("content")
' Extract the message content starting with "Ahoy matey..." and ending with "...me hearty!"
Dim start As Int = message_content.IndexOf("Ahoy matey")
Dim end As Int = message_content.IndexOf("me hearty!") + Len("me hearty!")
Dim extracted_message As String = message_content.SubString2(start, end)
Log(extracted_message) ' Output: Ahoy matey, ye be askin' a great question. The worst investment be ones that promise quick riches without flappin' yer sails too much, like the "get rich quick" schemes, ponzi schemes Or pyramid schemes. These scams be all about misuse of trust And deceivin' the inexperienced. They be luring investors with high promised returns, but in the end, they just take yer doubloons and disappear into the horizon. Stay away from such crooks and keep yer treasure safe, me hearty!
End Sub