summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c18
-rw-r--r--producer.sh36
2 files changed, 49 insertions, 5 deletions
diff --git a/main.c b/main.c
index cae13c5..4294b8e 100644
--- a/main.c
+++ b/main.c
@@ -7,6 +7,8 @@
#include "mem.h"
#include "llama.h"
+#define MODEL_PATH "qwen2.5-3b-instruct-q4_k_m.gguf"
+
#define SYSTEM_PROMPT \
"You are a lexicographer. Define the target word in the context provided.\n\n" \
"Output format strictly as follows:\n" \
@@ -191,13 +193,20 @@ static void process_request(struct llama_model *model, const char *user_prompt)
int main(int argc , char *argv[])
{
+ const char *prompt;
+ const char *model_path;
struct llama_model *model;
struct llama_model_params mparams;
- if (argc < 3)
- errx(1, "usage: %s [model] [prompt]", argv[0]);
-
- const char *model_path = argv[1];
+ if (argc == 2) {
+ model_path = MODEL_PATH;
+ prompt = argv[1];
+ } else if (argc == 3) {
+ model_path = argv[1];
+ prompt = argv[2];
+ } else {
+ errx(1, "usage: %s [model_path] <prompt>", argv[0]);
+ }
if (unveil(model_path, "r") == -1)
err(1, "unveil %s failed", model_path);
@@ -221,7 +230,6 @@ int main(int argc , char *argv[])
if (pledge("stdio", NULL) == -1)
err(1, "secondary pledge failed");
- const char *prompt = argv[2];
process_request(model, prompt);
llama_model_free(model);
diff --git a/producer.sh b/producer.sh
new file mode 100644
index 0000000..e05dca4
--- /dev/null
+++ b/producer.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+FIFO_PATH="${QUEUE_FIFO_PATH:-/tmp/job_queue}"
+
+# Validate argument
+if [ $# -eq 0 ] || [ -z "$1" ]; then
+ echo "Usage: $0 \"message to publish\"" >&2
+ exit 1
+fi
+
+MESSAGE="$1"
+
+# Ensure the FIFO exists (create if missing)
+if [ ! -p "$FIFO_PATH" ]; then
+ mkfifo -m 0600 "$FIFO_PATH" || {
+ echo "[$(date '+%H:%M:%S')] ERROR: Failed to create FIFO at $FIFO_PATH" >&2
+ exit 1
+ }
+fi
+
+# Handle SIGPIPE gracefully so the producer doesn't crash if the consumer disconnects
+trap '' PIPE
+
+# Publish message to the FIFO
+if echo "$MESSAGE" > "$FIFO_PATH" 2>/dev/null; then
+ # Format and cap log line at 72 chars
+ log_line="[$(date '+%H:%M:%S')] Published: ${MESSAGE}"
+ if [ ${#log_line} -gt 72 ]; then
+ printf "[%s] Published: %.45s...\n" "$(date '+%H:%M:%S')" "$MESSAGE"
+ else
+ echo "$log_line"
+ fi
+else
+ echo "[$(date '+%H:%M:%S')] ERROR: Failed to write to FIFO at $FIFO_PATH" >&2
+ exit 1
+fi