JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
ChatBox.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
20#ifdef JEVOIS_PRO
21#include <string>
22#include <vector>
23#include <deque>
24
25class ImGuiInputTextCallbackData;
26
27namespace jevois
28{
29//! A simple helper class for a chat box rendered in ImGui
30/*! This is used, for example, to create interactive dialogues with large language models (LLMs). Users can input text
31 in an input box, and answers can be shown in the main window above. This chatbox is intended to operate fully
32 asynchronously:
33
34 - call get() to retrieve any new input messages entered by the user. This is non-blocking and returns
35 immediately. The returned string will be empty except after the user presses [RETURN] in the input box, in which
36 case the whole entered input will be returned.
37
38 - call writeString() to add to the text that is written out in the main window.
39
40 - call draw() on every video frame.
41
42 Note: because it is primarily intended for use in python, this class is not thread-safe (for example, calling
43 writeString() and draw() concurrently might crash the system. In most applications, the ChatBox member functions
44 would all be called sequentially from a single thread).
45
46 \ingroup core */
47 class ChatBox
48 {
49 public:
50 //! Constructor
51 ChatBox(std::string title = "JeVois-Pro ChatBox");
52
53 //! Destructor
54 virtual ~ChatBox();
55
56 //! Get input string from user, or empty if no new input
57 std::string get();
58
59 //! Update text that is displayed above input box (output from the underlying chat bot)
60 void writeString(std::string const & out);
61
62 //! Render into an ImGui window
63 void draw();
64
65 //! Freeze/unfreeze the input box, typically to prevent new inputs until current reply is done
66 void freeze(bool doit);
67
68 //! Clear all displayed text:
69 void clear();
70
71 protected:
72 std::deque<std::pair<bool /* user/jevois */, std::string> > itsData;
73 std::string itsLastInput;
74 char itsInputBuf[1024];
75 std::vector<std::string> itsHistory;
77 std::string const itsTitle;
78 bool itsFrozen = false;
79 int itsWaitState = 10; // number of dots to display while frozen, in [0..20]
80
81 public:
82 int callback(ImGuiInputTextCallbackData * data);
83 };
84
85} // namespace jevois
86
87#endif // JEVOIS_PRO
A simple helper class for a chat box rendered in ImGui.
Definition ChatBox.H:48
void draw()
Render into an ImGui window.
Definition ChatBox.C:96
std::string get()
Get input string from user, or empty if no new input.
Definition ChatBox.C:45
std::string itsLastInput
Definition ChatBox.H:73
char itsInputBuf[1024]
Definition ChatBox.H:74
void freeze(bool doit)
Freeze/unfreeze the input box, typically to prevent new inputs until current reply is done.
Definition ChatBox.C:83
virtual ~ChatBox()
Destructor.
Definition ChatBox.C:35
int callback(ImGuiInputTextCallbackData *data)
Definition ChatBox.C:216
void writeString(std::string const &out)
Update text that is displayed above input box (output from the underlying chat bot)
Definition ChatBox.C:62
int itsHistoryPos
Definition ChatBox.H:76
std::string const itsTitle
Definition ChatBox.H:77
std::vector< std::string > itsHistory
Definition ChatBox.H:75
void clear()
Clear all displayed text:
Definition ChatBox.C:39
std::deque< std::pair< bool, std::string > > itsData
Definition ChatBox.H:72
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2