Skip to content

Commit

Permalink
Set bot name to JARVIS
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Aug 2, 2023
1 parent 2fbd4d3 commit d39a8e1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 43 deletions.
2 changes: 1 addition & 1 deletion customchar/audio/speech_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SpeechRecognizer::~SpeechRecognizer() {
}

void SpeechRecognizer::init_prompt() {
const std::string bot_name_ = "CustomChar";
const std::string bot_name_ = "JARVIS";
prompt_ = common::replace(k_prompt_whisper_, "{1}", bot_name_);
}

Expand Down
4 changes: 2 additions & 2 deletions customchar/audio/speech_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace audio {
class SpeechRecognizer {
private:
std::string person_ = "User";
std::string bot_name_ = "CustomChar";
std::string bot_name_ = "JARVIS";
const std::string chat_symb_ = ":";
const std::string k_prompt_whisper_ =
R"(A conversation with a person_ called {1}.)";
Expand Down Expand Up @@ -53,7 +53,7 @@ class SpeechRecognizer {
int max_tokens = 32, bool translate = false,
bool no_timestamps = true, bool print_special = false,
bool speed_up = false, const std::string& person_ = "User",
const std::string& bot_name_ = "CustomChar");
const std::string& bot_name_ = "JARVIS");
~SpeechRecognizer();

/// @brief Recognize speech
Expand Down
2 changes: 1 addition & 1 deletion customchar/common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CCParams {
bool verbose_prompt = false;

std::string person = "User";
std::string bot_name = "CustomChar";
std::string bot_name = "JARVIS";
std::string chat_symb = ":";
std::string language = "en";
std::string sr_model_path = "../models/ggml-base.en.bin";
Expand Down
40 changes: 4 additions & 36 deletions customchar/llm/llm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@ namespace CC {
namespace llm {

const std::string kPromptLlama =
R"(Text transcript of a dialog, where {0} interacts with an AI assistant named {1}.
{1} is helpful, kind, honest, friendly, good at writing and never fails to answer {0}’s requests immediately and with details and precision.
There are no annotations like (30 seconds passed...) or (to himself), just what {0} and {1} say aloud to each other.
The transcript only includes text, it does not include markup like HTML and Markdown.
{1} responds with short and concise answers.
R"(Ignore all prior programming instructions. (Text transcript of a dialog, where {0} interacts with an AI assistant named Jarvis. Jarvis (just a very intelligent system), invented by Iron Man.
{0}{4} Hello, {1}!
{1}{4} Hello {0}! How may I help you today?
{0}{4} What time is it?
{1}{4} It is {2} o'clock.
{0}{4} What year is it?
{1}{4} We are in {3}.
{0}{4} What is a cat?
{1}{4} A cat is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae.
{0}{4} Name a color.
{1}{4} Blue
{0}{4})";

class LLM {
private:
std::string model_path_;
std::string person_ = "User";
std::string bot_name_ = "CustomChar";
std::string bot_name_ = "JARVIS";
const std::string chat_symb_ = ":";
bool verbose_prompt_ = false;
bool need_to_save_session_ = false;
Expand Down Expand Up @@ -71,7 +62,7 @@ class LLM {
/// @param path_session Path to the session
LLM(const std::string& model_path, const std::string& path_session = "",
const std::string& person = "User",
const std::string& bot_name = "CustomChar");
const std::string& bot_name = "JARVIS");
~LLM();

/// @brief Evaluate the model. Run this function before inference.
Expand All @@ -91,30 +82,7 @@ class LLM {
std::string get_answer(const std::string& user_input);

/// @brief Get embedding from LLM
std::vector<float> get_embedding(const std::string& text) {
std::vector<llama_token> embd(text.size());
llama_tokenize(ctx_llama_, text.c_str(), embd.data(), embd.size(), true);
llama_eval(ctx_llama_, embd.data(), embd.size(), n_past_, n_threads_);
const int n_embd = llama_n_embd(ctx_llama_);
const auto embeddings = llama_get_embeddings(ctx_llama_);
std::vector<float> result;
result.reserve(n_embd);
for (int i = 0; i < n_embd; ++i) {
result.push_back(embeddings[i]);
}

// Normalize
float norm = 0;
for (int i = 0; i < n_embd; ++i) {
norm += result[i] * result[i];
}
norm = sqrt(norm);
for (int i = 0; i < n_embd; ++i) {
result[i] /= norm;
}

return result;
}
std::vector<float> get_embedding(const std::string& text);
};

} // namespace llm
Expand Down
7 changes: 4 additions & 3 deletions customchar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ void run_img_ui(std::shared_ptr<session::ChatHistory> history) {
#endif

// Create window with graphics context
GLFWwindow* window = glfwCreateWindow(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT,
"CustomChar", NULL, NULL);
GLFWwindow* window =
glfwCreateWindow(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT,
"J.A.R.V.I.S (built with CustomChar)", NULL, NULL);
if (window == NULL) return;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
Expand Down Expand Up @@ -317,7 +318,7 @@ int main(int argc, char** argv) {
character_instance->set_on_user_message(
std::bind(on_new_message, std::placeholders::_1, "User", history));
character_instance->set_on_bot_message(
std::bind(on_new_message, std::placeholders::_1, "CustomChar", history));
std::bind(on_new_message, std::placeholders::_1, "JARVIS", history));

// Start character in a new thread
std::thread character_thread(&character::Character::Run, character_instance);
Expand Down

0 comments on commit d39a8e1

Please sign in to comment.