Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 63 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,73 @@
#include "ollama_client.hpp"
#include <iostream>

bool next_prompt(std::string* prompt) {
bool done = false;
printf("⏳ Type your prompt (q/Q to quit): ");
if (!std::getline(std::cin, *prompt, '\n')) {
fprintf(stderr, "Error reading user input.\n");
exit(1);
}

if (*prompt == "q" || *prompt == "Q") {
done = true;
}

return done;
}

int main(int argc, const char* argv[]) {
std::string model = "gemma3n:latest";
std::string prompt = "Hey! What's up!";
bool stream = false;
bool interactive = false;

bool done = false;

std::string arg{};
for (int i = 1; i < argc; i += 1) {
std::string arg = argv[i];
if (arg.starts_with("--model=") == 0) {
arg = argv[i];
if (arg.starts_with("--model=") == true) {
model = arg.substr(8);
} else if (arg.starts_with("--prompt=") == 0) {
} else if (arg.starts_with("--prompt=") == true) {
prompt = arg.substr(9);
} else if (arg.starts_with("--stream=") == 0) {
} else if (arg.starts_with("--stream=") == true) {
stream = arg.substr(9) == "true" ? true : false;
} else if (arg.starts_with("--interactive=") == true) {
interactive = arg.substr(14) == "true" ? true : false;
}
}

printf("\n");
printf("🛈 model = %s\n", model.c_str());
printf("🛈 prompt = %s\n", prompt.c_str());
printf("🛈 stream = %s\n", stream ? "true" : "false");
printf("🛈 interactive = %s\n", interactive ? "true" : "false");
printf("\n");

if (prompt.length() == 0) {
printf("Enter your prompt: ");
getline(std::cin, prompt);
if (interactive == true) {
while (prompt.length() == 0) {
done = next_prompt(&prompt);

if (done == true) {
printf("\n🏁 The session has ended.\n");
exit(0);
}
}
} else {
if (prompt.length() == 0) {
done = next_prompt(&prompt);

if (prompt.length() == 0) {
printf("\n🏁 Empty prompt. The session has ended.\n");
exit(0);
}

if (done == true) {
printf("\n🏁 The session has ended.\n");
exit(0);
}
}
}

OllamaClient client = OllamaClient();
Expand All @@ -39,5 +81,19 @@ int main(int argc, const char* argv[]) {

client.query_model(config);

if (interactive == true) {
while (done == false) {
done = next_prompt(&prompt);
if (done == true) {
continue;
}

config.prompt = prompt;
client.query_model(config);
}
}

printf("\n🏁 The session has ended.\n");

return 0;
}
Loading