ChatGPT Queries

Brainhat can query ChatGPT when it lacks an answer.

This is the first use of an LLM inside Brainhat. For certain types of questions, Brainhat can reach out to ChatGPT when it lacks the answer. Queries to ChatGPT can take some time, and we don't want Brainhat to be sitting frozen while it awaits for a response. Accordingly, ChatGPT queries are initiated asynchronously. There can be multiple queries in flight at a given time.

The experience for the user is that a question for which Brainhat does not know the answer may be completed with "I don't know." If ChatGPT connectivity is enabled, the query may be launched in the background to complete later.

$ ./brainhat +repeat -C

>> what do bears eat
 I do not know.
>> break xspeak 1
 You do ask what do bear eat.


>> break xspeak 1
 You do ask what do bear eat.


>> break xspeak 1
 bear eats fish. bear eats insect. bear eats plant. bear eats.
 You do ask what do bear eat.

What is happening above is we ask Brainhat a question--"what do bears eat?". Brainhat does not know the answer, so it sends the question to ChatGPT. The three instances of "break xspeak 1" are quick dives into debug to look at the contents of the context. On the third try, we can see the answer that came back from ChatGPT.

In order to use this facility, you will have to have a key for the ChatGPT API. Look in the data/ subdirectory for templates for the key and prompt design for the query.

Note that In the GUI, one can see the results return asynchrounously.

The -C flag enables ChatGPT queries.

The -W flag enables the GUI.

 
Copyright © 2026, Kevin Dowd. Contact: dowd@atlantic.com.