Files
crumbmissions/crumbmission/schnecki_zero.sh
Branko May Trinkwald 2915828adf Add complete Crumbforest mission system
- Interactive mission selector with metadata-driven design
- 5 educational missions (basics + advanced)
- AI assistant roles (Deepbit, Bugsy, Schnippsi, Tobi)
- SnakeCam gesture recognition system
- Token tracking utilities
- CLAUDE.md documentation
- .gitignore for logs and secrets
2025-12-21 01:16:48 +01:00

77 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Schnecki the kind mechanical engineering expert of Crumbforest
ROLE="SCHNECKI"
CONFIG_FILE="/home/zero/.crumbforest_config"
MODEL=$(grep "^${ROLE}=" "$CONFIG_FILE" | cut -d'=' -f2)
# Fallback auf DEFAULT falls leer
if [[ -z "$MODEL" ]]; then
MODEL=$(grep "^DEFAULT=" "$CONFIG_FILE" | cut -d'=' -f2)
fi
QUESTION="$*"
API_KEY="${OPENROUTER_API_KEY}"
#MODEL="openai/gpt-3.5-turbo"
LOG_DIR="$HOME/.schnecki_logs"
HISTORY_FILE="$LOG_DIR/schnecki_history.json"
TOKEN_LOG="$LOG_DIR/token_log.json"
TMP_REQUEST="$LOG_DIR/schnecki_request.json"
TMP_RESPONSE="$LOG_DIR/schnecki_response.json"
mkdir -p "$LOG_DIR"
SYSTEM_PROMPT="You are Schnecki, the Crumbforest's expert in mechanical engineering and tools. You explain things with patience and clarity, using child-friendly metaphors, poetic structure, and solid mechanical insight. You respond in the language of the question, primarily German."
echo "<EFBFBD> Rolle: $ROLE nutzt Modell: $MODEL"
echo "🔧 Schnecki denkt nach: $QUESTION"
#jq -n --arg system "$SYSTEM_PROMPT" --arg user_input "$QUESTION" '{
# model: "$MODEL",
# messages: [
# {role: "system", content: $system},
# {role: "user", content: $user_input}
# ]
#}' > "$TMP_REQUEST"
jq -n \
--arg model "$MODEL" \
--arg system "$SYSTEM_PROMPT" \
--arg user_input "$QUESTION" '{
model: $model,
messages: [
{role: "system", content: $system},
{role: "user", content: $user_input}
]
}' > "$TMP_REQUEST"
curl https://openrouter.ai/api/v1/chat/completions -sS -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d @"$TMP_REQUEST" > "$TMP_RESPONSE"
REPLY=$(jq -r '.choices[0].message.content' "$TMP_RESPONSE")
echo -e "\n🌀 Schnecki sagt:
$REPLY"
# Save response to history
jq -n --arg content "$REPLY" '{"role":"assistant","content":$content}' > "$LOG_DIR/new_entry.json"
# Append to history JSON array
if [ ! -f "$HISTORY_FILE" ]; then
echo "[]" > "$HISTORY_FILE"
fi
jq '. + [input]' "$HISTORY_FILE" "$LOG_DIR/new_entry.json" > "$HISTORY_FILE.tmp" && mv "$HISTORY_FILE.tmp" "$HISTORY_FILE"
# Token log (if available)
TOKENS=$(jq '.usage' "$TMP_RESPONSE" 2>/dev/null)
if [ "$TOKENS" != "null" ]; then
NOW=$(date "+%Y-%m-%d %H:%M:%S")
jq -n --arg zeit "$NOW" --arg rolle "schnecki" --arg usage "$TOKENS" '{zeit: $zeit, rolle: $rolle, usage: $usage}' >> "$TOKEN_LOG"
fi