How can I extract information from my JsonObject?

Hi, everyone.

I created a project using VB to try out the ChatGPT API. I’m using the steps outlined here, except that I’d like to figure out how to do this with VB instead of C#.

I’m at the stage where I’m trying to get information out of a JsonObject. I keep getting object reference errors like the one below, so I know I’m not getting the answer that I want. I can see the answer in the JsonObject, though. (It’s the word “Springfield” because I asked ChatGPT what the capital of Illinois is.)

I have a feeling it may be because the Invoke Code activity I am using is written in C#, but then I wouldn’t expect to get a response from the API. I’m getting a response, as you can see, I’m just not getting the information I want out of it.

Can anyone help me figure out where I’m going wrong after deserializing the JSON?

Here is my code thus far:
ChatGPT (12.8 KB)

Yeah, pretty sure I’m messing this all up because I’m mixing some C# with VB, but I’m not sure at what point that is causing the trouble. Like I said, I’m getting the response below, so it seems like my POST request is working, but I’m not getting the “text” value of “Springfield” from the response.

{“id”:“cmpl-6aAjsqGcPb4qppeevR0GhWMKIsNMj”,“object”:“text_completion”,“created”:1674079108,“model”:“davinci”,“choices”:[{“text”:" Springfield.",“index”:0,“logprobs”:null,“finish_reason”:“stop”}],“usage”:{“prompt_tokens”:12,“completion_tokens”:2,“total_tokens”:14}}

JSON String was deserilized JSON to a JObject: myJobject


Thanks for the help, @ppr. I’m still doing something wrong. It’s giving me what I sent instead of what I received when I type in jsonOutput.ToString in the Immediate panel.

EDIT: OHHHHHHHHHH… I was putting strJsonBody where strResponse needed to go, lol. Thanks so much for the help!!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.