-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_ai.clj
84 lines (67 loc) · 2.29 KB
/
gen_ai.clj
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(ns is.simm.languages.gen-ai
"Providing high-level generative AI functions for the runtime.
The syntax is async (go-routine) functions that invoke
lower level runtimes/downstreams with a piece of derived syntax (IR) and handle the replies transparently."
(:require [is.simm.languages.dispatch :refer [create-downstream-msg-handler get-runtime]]
[clojure.spec.alpha :as s]))
(let [handler (create-downstream-msg-handler ::cheap-llm)]
(defn cheap-llm [msg]
(handler msg)))
(let [handler (create-downstream-msg-handler ::reasoner-llm)]
(defn reasoner-llm [msg]
(handler msg)))
(let [handler (create-downstream-msg-handler ::stt-basic)]
(defn stt-basic [voice-path]
(handler voice-path)))
(let [handler (create-downstream-msg-handler ::image-gen)]
(defn image-gen [prompt]
(handler prompt)))
(defprotocol GenAI
(-cheap-llm [this msg]
"Generates text from a prompt using a cheap language model.")
(-reasoner-llm [this msg]
"Generates text from a prompt using a reasoner language model.")
(-stt-basic [this voice-path]
"Converts a voice file to text.")
(-image-gen [this prompt]
"Generates an image from a prompt."))
(def msg? string?)
(def voice-path? string?)
(def prompt? string?)
(s/fdef cheap-llm
:args (s/cat :ctx map? :msg msg?)
:ret msg?)
(defn cheap-llm-
"Generates text from a prompt using a cheap language model."
[ctx msg]
(-cheap-llm (get-runtime ctx :gen-ai) msg))
(s/fdef reasoner-llm
:args (s/cat :ctx map? :msg msg?)
:ret msg?)
(defn reasoner-llm-
"Generates text from a prompt using a reasoner language model."
[ctx msg]
(-reasoner-llm (get-runtime ctx :gen-ai) msg))
(s/fdef stt-basic
:args (s/cat :ctx map? :voice-path voice-path?)
:ret msg?)
(defn stt-basic-
"Converts a voice file to text."
[ctx voice-path]
(-stt-basic (get-runtime ctx :gen-ai) voice-path))
(s/fdef image-gen
:args (s/cat :ctx map? :prompt prompt?)
:ret msg?)
(defn image-gen-
"Generates an image from a prompt."
[ctx prompt]
(-image-gen (get-runtime ctx :gen-ai) prompt))
(comment
(require '[is.simm.runtimes.openai :refer [openai]])
;; TODO needs to use pub-sub
(let [in (chan)
out (chan)]
(openai [S nil [in out]])
(binding [*chans* [in out]]
(<?? S (cheap-llm "What is the capital of Ireland?"))))
)