forked from copilot-community-sdk/copilot-sdk-clojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata_api.clj
More file actions
73 lines (63 loc) · 3.01 KB
/
metadata_api.clj
File metadata and controls
73 lines (63 loc) · 3.01 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(ns metadata-api
"Demonstrates the metadata API functions introduced in v0.1.24:
- list-sessions with context filtering
- list-tools with model-specific overrides
- get-quota for account usage information
- get-current-model and switch-model for dynamic model switching
Note: Some methods (tools.list, account.getQuota, session.model.*)
require a CLI version that supports them. The example gracefully
handles unsupported methods."
(:require [github.copilot-sdk :as copilot]
[github.copilot-sdk.helpers :as h]))
;; See examples/README.md for usage
(defn run
[& _]
(println "=== Copilot Metadata API Demo ===\n")
(copilot/with-client [client {:log-level :warning}]
;; 1. List sessions (supported on all CLI versions)
(println "1. Active Sessions:")
(let [sessions (copilot/list-sessions client)]
(println (str " Found " (count sessions) " session(s)"))
(when (seq sessions)
(doseq [session (take 3 sessions)]
(println (str " - " (:session-id session)))
(when-let [ctx (:context session)]
(println (str " Repository: " (:repository ctx)))
(println (str " Branch: " (:branch ctx)))))))
;; 2. List available tools
(println "\n2. Available Tools:")
(try
(let [tools (copilot/list-tools client)]
(println (str " Found " (count tools) " tools"))
(doseq [tool (take 5 tools)]
(println (str " - " (:name tool) ": " (:description tool)))))
(catch Exception e
(println (str " Skipped: " (.getMessage e)))))
;; 3. Get quota information
(println "\n3. Account Quota:")
(try
(let [quotas (copilot/get-quota client)]
(doseq [[quota-type snapshot] quotas]
(println (str " " quota-type ":"))
(println (str " Entitlement: " (:entitlement-requests snapshot)))
(println (str " Used: " (:used-requests snapshot)))
(println (str " Remaining: " (:remaining-percentage snapshot) "%"))))
(catch Exception e
(println (str " Skipped: " (.getMessage e)))))
;; 4. Model switching within a session
(println "\n4. Dynamic Model Switching:")
(copilot/with-session [session client {}]
;; Query with default model
(println " Query: 'What is 2+2? Answer briefly.'")
(println (str " Response: " (h/query "What is 2+2? Answer briefly." :session session)))
;; Try model introspection (requires CLI support)
(try
(let [current (copilot/get-current-model session)]
(println (str "\n Current model: " current))
(copilot/switch-model! session "gpt-4o")
(println (str " Switched to: " (copilot/get-current-model session)))
(println " Query: 'What was my previous question?'")
(println (str " Response: " (h/query "What was my previous question?" :session session))))
(catch Exception e
(println (str "\n Model switching skipped: " (.getMessage e)))))))
(println "\n=== Demo Complete ==="))