OverviewFilesCommitsIssuesDocsReleasesPeers

hypercore-kb / opencog-kb / language-learning / chatbot / client.sh

33 lines · bash ref:
#!/bin/bash
#
# client.sh - Query the AtomSpace chatbot daemon
#
# Usage:
#   ./client.sh "fish swim in water"   # Teach it
#   ./client.sh /stats                  # Get stats
#   ./client.sh "/assoc fish"           # Get associations
#   ./client.sh "/pmi fish swim"        # Get PMI
#

SOCKET="/tmp/atomspace-chatbot.sock"

if [ -z "$1" ]; then
    echo "Usage: $0 <message or command>"
    echo ""
    echo "Examples:"
    echo "  $0 'fish swim in water'    # Teach"
    echo "  $0 /stats                   # Stats"
    echo "  $0 '/assoc fish'            # Associations"
    echo "  $0 '/pmi fish swim'         # PMI score"
    exit 1
fi

if [ ! -S "$SOCKET" ]; then
    echo "Error: Daemon not running. Start with:"
    echo "  cd $(dirname $0) && guile daemon.scm socket &"
    exit 1
fi

# Send command and get response
echo "$1" | nc -U "$SOCKET" -q 1