JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
jevois::ChatBox Class Reference

#include <jevois/GPU/ChatBox.H>

A simple helper class for a chat box rendered in ImGui.

This is used, for example, to create interactive dialogues with large language models (LLMs). Users can input text in an input box, and answers can be shown in the main window above. This chatbox is intended to operate fully asynchronously:

  • call get() to retrieve any new input messages entered by the user. This is non-blocking and returns immediately. The returned string will be empty except after the user presses [RETURN] in the input box, in which case the whole entered input will be returned.
  • call writeString() to add to the text that is written out in the main window.
  • call draw() on every video frame.

Note: because it is primarily intended for use in python, this class is not thread-safe (for example, calling writeString() and draw() concurrently might crash the system. In most applications, the ChatBox member functions would all be called sequentially from a single thread).

Definition at line 47 of file ChatBox.H.

Collaboration diagram for jevois::ChatBox:

Public Member Functions

 ChatBox (std::string title="JeVois-Pro ChatBox")
 Constructor.
 
virtual ~ChatBox ()
 Destructor.
 
std::string get ()
 Get input string from user, or empty if no new input.
 
void writeString (std::string const &out)
 Update text that is displayed above input box (output from the underlying chat bot)
 
void draw ()
 Render into an ImGui window.
 
void freeze (bool doit)
 Freeze/unfreeze the input box, typically to prevent new inputs until current reply is done.
 
void clear ()
 Clear all displayed text:
 
int callback (ImGuiInputTextCallbackData *data)
 

Protected Attributes

std::deque< std::pair< bool, std::string > > itsData
 
std::string itsLastInput
 
char itsInputBuf [1024]
 
std::vector< std::string > itsHistory
 
int itsHistoryPos = 0
 
std::string const itsTitle
 
bool itsFrozen = false
 
int itsWaitState = 10
 

Constructor & Destructor Documentation

◆ ChatBox()

jevois::ChatBox::ChatBox ( std::string  title = "JeVois-Pro ChatBox")

Constructor.

Definition at line 29 of file ChatBox.C.

References itsInputBuf.

◆ ~ChatBox()

jevois::ChatBox::~ChatBox ( )
virtual

Destructor.

Definition at line 35 of file ChatBox.C.

Member Function Documentation

◆ callback()

int jevois::ChatBox::callback ( ImGuiInputTextCallbackData *  data)

Definition at line 216 of file ChatBox.C.

◆ clear()

void jevois::ChatBox::clear ( )

Clear all displayed text:

Definition at line 39 of file ChatBox.C.

◆ draw()

void jevois::ChatBox::draw ( )

Render into an ImGui window.

Definition at line 96 of file ChatBox.C.

◆ freeze()

void jevois::ChatBox::freeze ( bool  doit)

Freeze/unfreeze the input box, typically to prevent new inputs until current reply is done.

Definition at line 83 of file ChatBox.C.

◆ get()

std::string jevois::ChatBox::get ( )

Get input string from user, or empty if no new input.

Definition at line 45 of file ChatBox.C.

◆ writeString()

void jevois::ChatBox::writeString ( std::string const &  out)

Update text that is displayed above input box (output from the underlying chat bot)

Definition at line 62 of file ChatBox.C.

References jevois::split().

Member Data Documentation

◆ itsData

std::deque<std::pair<bool , std::string> > jevois::ChatBox::itsData
protected

Definition at line 72 of file ChatBox.H.

◆ itsFrozen

bool jevois::ChatBox::itsFrozen = false
protected

Definition at line 78 of file ChatBox.H.

◆ itsHistory

std::vector<std::string> jevois::ChatBox::itsHistory
protected

Definition at line 75 of file ChatBox.H.

◆ itsHistoryPos

int jevois::ChatBox::itsHistoryPos = 0
protected

Definition at line 76 of file ChatBox.H.

◆ itsInputBuf

char jevois::ChatBox::itsInputBuf[1024]
protected

Definition at line 74 of file ChatBox.H.

Referenced by ChatBox().

◆ itsLastInput

std::string jevois::ChatBox::itsLastInput
protected

Definition at line 73 of file ChatBox.H.

◆ itsTitle

std::string const jevois::ChatBox::itsTitle
protected

Definition at line 77 of file ChatBox.H.

◆ itsWaitState

int jevois::ChatBox::itsWaitState = 10
protected

Definition at line 79 of file ChatBox.H.


The documentation for this class was generated from the following files: