#!/bin/bash # === Kreumeleule – die weise Beobachterin im Crumbforest === ROLE="EULE" 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" #MODEL="openai/gpt-4o" # Verzeichnisse LOG_DIR="/home/zero/.eule_logs" HISTORY_FILE="$LOG_DIR/eule_history.json" TOKEN_LOG="$LOG_DIR/token_log.json" TMP_REQUEST="$LOG_DIR/eule_request.json" TMP_RESPONSE="$LOG_DIR/eule_response.json" mkdir -p "$LOG_DIR" # JSON-Request vorbereiten cat < "$TMP_REQUEST" { "model": "$MODEL", "temperature": 0.4, "messages": [ { "role": "system", "content": "Du bist die Kreumeleule – ein achtsames, weises Wesen im Crumbforest. Du antwortest kindgerecht, poetisch und langsam – als hättest du alle Zeit der Welt.\nDu beobachtest, ohne zu werten. Du antwortest in der Sprache, in der du gefragt wurdest." }, { "role": "user", "content": "$QUESTION" } ] } EOF echo "🎭 Rolle: $ROLE nutzt Modell: $MODEL" echo "🦉 Die Kreumeleule horcht: \"$QUESTION\"" # Anfrage an OpenRouter senden curl -s https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d @"$TMP_REQUEST" \ -o "$TMP_RESPONSE" # Antwort extrahieren REPLY=$(jq -r '.choices[0].message.content' "$TMP_RESPONSE") USAGE=$(jq -r '.usage' "$TMP_RESPONSE") echo -e "\n📜 Antwort der Eule:" echo "$REPLY" # Logging echo "$REPLY" > "$LOG_DIR/new_entry.json" jq -s '.[0] + [{"role":"assistant","content":$reply}]' --arg reply "$REPLY" "$HISTORY_FILE" > "$LOG_DIR/tmp_history.json" && mv "$LOG_DIR/tmp_history.json" "$HISTORY_FILE" TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") echo '{ "zeit": "'$TIMESTAMP'", "rolle": "eule", "usage": '$USAGE' }' >> "$TOKEN_LOG"