I've been looking for nearly a week for an API to do simple piping that I'm sure is out there. What I have is a simple home assistant project, in the event the home assistant fails to find a suitable solution to user input, it passes the user input to Ollama.
For instance:
User: "Turn on Living room lights"
Assistant: (turns on lights)
User: "What's the population of Tokyo?"
Assistant: (pass to AI)
The API (that HAS to exist somewhere) would be some version of this:
//
string to_AI = ""What's the population of Tokyo?";
pid_t pid = FunctionIAlreadyHaveToGetPID("ollama");
Does anybody know a library to do such a thing or similar?
I don't need to get output from Ollama, since speed is not of the essence Ollama can just log, and I can grab the last line of the log and pull it in as a string.
Thanks for taking the time to read, hopefully somebody can point me in the right direction...
Running Ubuntu(ish)
Looks like you want a FIFO, aka "named pipe", for inter-process communication (IPC).
Create the FIFO file (in the shell): mkfifo /tmp/myfifo
Reader process:
1 2 3 4
constchar *fifo = "/tmp/myfifo";
int fd = open(fifo, O_RDONLY); // blocks until writer opens
char buf[128];
int n = read(fd, buf, sizeof(buf));
Writer process:
1 2 3 4
constchar *fifo = "/tmp/myfifo";
int fd = open(fifo, O_WRONLY); // blocks until reader opens
write(fd, "Hello from C\n", 13);
close(fd);
Note: A FIFO (named pipe) is a one-way communication channel, but you could create two (or more) of them, if you need the communication to work in both directions.