<commit_before>(use-modules (opencog) (rnrs bytevectors))

(define server "127.0.0.1")
(define port 1024)
(define username "opencog")
(define bot-name "rose")

(define-public (setup-chatscript robot)
    (call-chatscript (string-append ":build " robot) #f)
)

(define (call-chatscript msg rec)
    (define bv (make-bytevector 10000))
    (define s (socket AF_INET SOCK_STREAM 6))

    (connect s AF_INET (inet-pton AF_INET server) port)

    (send s (string->utf8 (string-append username "\0" bot-name "\0" msg "\0")))

    (if rec (begin
        (recv! s bv)
        ; TODO: Store in the AtomSpace
        (display (utf8->string bv))
    ))

    (shutdown s 2)
)

(setup-chatscript "han")
(call-chatscript "what is your name" #t)<commit_msg>Split into functions<commit_after>(use-modules (opencog) (rnrs bytevectors))

(define server "127.0.0.1")
(define port 1024)
(define username "opencog")
(define bot-name "rose")

(define-public (setup-chatscript robot)
    (shutdown (car (send-to-chatscript (string-append ":build " robot))) 2)
)

(define (send-to-chatscript msg)
    (define bv (make-bytevector 10000))
    (define s (socket AF_INET SOCK_STREAM 6))

    (connect s AF_INET (inet-pton AF_INET server) port)

    (send s (string->utf8 (string-append username "\0" bot-name "\0" msg "\0")))

    (cons s bv)
)

(define (call-chatscript msg)
    (define prtn (send-to-chatscript msg))
    (define s (car prtn))
    (define bv (cdr prtn))

    (recv! s bv)

    ; TODO: Store in the AtomSpace
    (display (utf8->string bv))
    (newline)

    (shutdown s 2)
)

(setup-chatscript "han")
(call-chatscript "what is your name")
{'fraction_non_alphanumeric': 0.14917127071823205, 'fraction_numerical': 0.027624309392265192, 'mean_word_length': 3.4657534246575343, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6800397', 'n_tokens_mistral': 626, 'n_tokens_neox': 585, 'n_words': 177}