<commit_before>#lang racket

(provide agt)

(require fractalide/modules/rkt/rkt-fbp/agent)
(require fractalide/modules/rkt/rkt-fbp/graph)

(define (interpolated-by-nix? type)
  (define dot-path (regexp-match #px"\\$\\{(.*)\\}" type))
  (if (equal? (substring type 0 2) "${")
      ; it's not interpolated nix code
      (string-append "agents/"
                     (string-trim
                      (string-replace (cadr dot-path) "." "/")) ".rkt")
      ; nix has interpolated it, use the path as is
      type))

(define agt
  (define-agent
    #:input '("in")
    #:output '("out")
    #:proc
    (lambda (input output input-array output-array)
      (let* ([agt (recv (input "in"))])
        (define new-type (interpolated-by-nix? (g-agent-type agt)))
        (define new-agent (struct-copy g-agent agt
                                       [type new-type]))
        (send (output "out") new-agent)))))<commit_msg>Problem: load-graph can accept only relative paths<commit_after>#lang racket

(provide agt)

(require fractalide/modules/rkt/rkt-fbp/agent)
(require fractalide/modules/rkt/rkt-fbp/graph)

(define (maybe-nix-string->module-path-or-passthrough type)
  (cond
    ; Fully processed, ready for dynamic-require
    [((or/c module-path? resolved-module-path? module-path-index?) type) type]
    ; Needs processing, transform into relative path
    [(equal? (substring type 0 2) "${")
     (define dot-path (regexp-match #px"\\$\\{(.*)\\}" type))
     (string-append "agents/"
                    (string-trim
                      (string-replace (cadr dot-path) "." "/")) ".rkt")]
    [else
     (raise-argument-error 'get-path
                           "type required to be a nix interpolation string or something recognized by dynamic-require"
                           type)]))

(define agt
  (define-agent
    #:input '("in")
    #:output '("out")
    #:proc
    (lambda (input output input-array output-array)
      (let* ([agt (recv (input "in"))])
        (define new-type (maybe-nix-string->module-path-or-passthrough (g-agent-type agt)))
        (define new-agent (struct-copy g-agent agt
                                       [type new-type]))
        (send (output "out") new-agent)))))
{'fraction_non_alphanumeric': 0.15936794582392777, 'fraction_numerical': 0.0018058690744920992, 'mean_word_length': 2.2588235294117647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6260810', 'n_tokens_mistral': 737, 'n_tokens_neox': 698, 'n_words': 180}