summaryrefslogtreecommitdiff
path: root/epistemia/services/machine-learning.scm
blob: 3d9490868bf6c5b6cf59fe8449578a11676832b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(define-module (epistemia services machine-learning)
  #:use-module (gnu packages admin)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu system shadow)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:export (llama-swap-configuration
            llama-swap-configuration?
            llama-swap-service-type))

(define-record-type* <llama-swap-configuration>
  llama-swap-configuration make-llama-swap-configuration
  llama-swap-configuration?
  (package       llama-swap-configuration-package
                 (default llama-swap))
  (llama-cpp     llama-swap-configuration-llama-cpp
                 (default llama-cpp))
  (config        llama-swap-configuration-config)
  (listen        llama-swap-configuration-listen
                 (default ":8080"))
  (watch-config? llama-swap-configuration-watch-config?
                 (default #f)))

(define llama-swap-account-service
  (list (user-account
         (name "llama-swap")
         (group "nogroup")
         (system? #t)
         (comment "llama-swap daemon user")
         (home-directory "/var/empty")
         (shell (file-append shadow "/sbin/nologin")))))

(define (llama-swap-shepherd-service config)
  (let ((pkg       (llama-swap-configuration-package config))
        (lcpp      (llama-swap-configuration-llama-cpp config))
        (cfg       (llama-swap-configuration-config config))
        (listen    (llama-swap-configuration-listen config))
        (watch?    (llama-swap-configuration-watch-config? config)))
    (list
     (shepherd-service
      (documentation "llama-swap OpenAI-compatible model proxy")
      (provision '(llama-swap))
      (requirement '(networking))
      (start #~(make-forkexec-constructor
                (append
                 (list #$(file-append pkg "/bin/llama-swap")
                       "-config" #$cfg
                       "-listen" #$listen)
                 (if #$watch? '("-watch-config") '()))
		#:user "llama-swap"
                #:environment-variables
		(cons (string-append "PATH=" #$(file-append lcpp "/bin"))
		      (default-environment-variables))))
      (stop #~(make-kill-destructor))))))

(define llama-swap-service-type
  (service-type (name 'llama-swap)
		(extensions
		 (list (service-extension account-service-type
					  (const llama-swap-account-service))
		       (service-extension shepherd-root-service-type
					  llama-swap-shepherd-service)))
		(description
		 "llama-swap is an @code{OpenAI} API compatible server that gives you complete
control over how you use your hardware. It automatically swaps to the
configuration of your choice for serving a model.")))