I am trying to get messages from a thread using the chat_gpt_sdk flutter package. I am failing at a seemingly very simple step. I must be missing something fundamental and it's driving me nuts.
Here is a piece of my code:
final runRequest = CreateRun(assistantId: assistantID);
runResult = await globals.chatAI.threads.runs
.createRun(threadId: threadID, request: runRequest);
var runID = runResult.id.toString();
print('runID: $runID');
// this is giving me the output 'runID: run_abc123'.
final mRunSteps = await globals.chatAI.threads.runs.listRunSteps(
threadId: threadID,
runId: runID, //this is where I get an error!
);
print('runID after: ${runResult.id}');
If I run the code above, I get a runtime error saying
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String'
#0 new ListRun.fromJson (package:chat_gpt_sdk/src/model/run/response/list_run.dart:19:22)
#1 OpenAIClient.get (package:chat_gpt_sdk/src/client/openai_client.dart:59:25)
<asynchronous suspension>
#2 ChatBotBrain.getChatAnswer (package:germaniac01/controlers/chatbot_brain.dart:84:23)
<asynchronous suspension>
#3 _ChatBotScreenState.build.<anonymous closure>.<anonymous closure> (package:germaniac01/screens/chatbot_screen.dart:52:35)
<asynchronous suspension>
The error is pointing to the position before the await globals.chatAI.threads..... I assume it's related to the runID, because if I exchange the definition of runID with runID = 'run_abc123' instead, it works just fine. In that case the print below gives me the same output as the one above, so it seems that runID is a String all the time.
If I wrap it with if(runID is String) it says that's unnecessary bc always true.
Why does it say it is null then? What am I missing?
I think the error is not on your side. maybe we can debug it together. OpenAI api says the response of that endpoint looks like this:
The error in your app says its in this files:
The #1 is of the client trying to make the request, and #0 is the model trying to convert the json to the object:
can you check/debug with the flutter debug tool in the network view what is the response (it should be 200 with a json and then compare it with the one here, the endpoint has to be something like /$threadId/$kRuns/run_abc123/steps)
This is an example of the network view. It says first_id shoudn't be null but it looks like openAI is responding with null.
Is this your fist question in the openAI chat? do you actually have a run instance at that moment?