-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers_query.clj
More file actions
53 lines (45 loc) · 1.92 KB
/
helpers_query.clj
File metadata and controls
53 lines (45 loc) · 1.92 KB
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
(ns helpers-query
(:require [clojure.core.async :refer [<!! go-loop <!]]
[github.copilot-sdk :as copilot :refer [evt]]
[github.copilot-sdk.helpers :as h]))
;; See examples/README.md for usage
(def defaults
{:prompt "What is the capital of Japan? Answer in one sentence."})
(def session-config
{:on-permission-request copilot/approve-all
:model "claude-haiku-4.5"})
(defn run
[{:keys [prompt] :or {prompt (:prompt defaults)}}]
(println "Query:" prompt)
(println "🤖:" (h/query prompt :session session-config)))
(defn run-multi
[{:keys [questions] :or {questions ["What is 2+2? Just the number."
"What is the capital of France? Just the city."
"Who wrote Hamlet? Just the name."]}}]
(doseq [q questions]
(println "Q:" q)
(println "A:" (h/query q :session session-config))
(println)))
;; Define a multimethod for handling events by type
(defmulti handle-event :type)
(defmethod handle-event :default [_] nil)
(defmethod handle-event (evt :assistant.message_delta) [{{:keys [delta-content]} :data}]
(print delta-content)
(flush))
(defmethod handle-event (evt :assistant.message) [_] (println))
(defn run-streaming
[{:keys [prompt] :or {prompt "Explain the concept of immutability in 2-3 sentences."}}]
(println "Query:" prompt)
(println)
(run! handle-event (h/query-seq! prompt :session {:on-permission-request copilot/approve-all
:model "gpt-5.4" :streaming? true})))
(defn run-async
[{:keys [prompt] :or {prompt "Tell me a short joke."}}]
(println "Query:" prompt)
(println)
(let [ch (h/query-chan prompt :session {:on-permission-request copilot/approve-all
:model "gpt-5.4" :streaming? true})]
(<!! (go-loop []
(when-let [event (<! ch)]
(handle-event event)
(recur))))))