-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e84f3d
commit 9cb57e6
Showing
1 changed file
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,62 @@ | ||
(ns semantic-router-clj.core | ||
(:gen-class)) | ||
(:gen-class) | ||
(:require [cheshire.core :as cc] | ||
[semantic-router-clj.layer :as srcl] | ||
[semantic-router-clj.openai :as srco] | ||
[semantic-router-clj.route :as srcr])) | ||
|
||
(defn -main | ||
"I don't do a whole lot ... yet." | ||
[& args] | ||
(println "Hello, World!")) | ||
|
||
(defn router | ||
[layer-ns query] | ||
{:pre [(keyword? layer-ns)]} | ||
(let [layer (srcl/get-layer layer-ns) | ||
embedding (-> {:input query} | ||
(assoc :model (:model layer)) | ||
(cc/generate-string true) | ||
srco/generate-embeddings | ||
first)] | ||
(srcr/get-top-route layer embedding))) | ||
|
||
|
||
;; Usage example | ||
(comment | ||
;; Set API key | ||
(srco/set-api-key "<api-key>") | ||
|
||
;; Create a new layer | ||
(srcl/layer :test | ||
:threshold 0.5 | ||
:model "text-embedding-3-small" | ||
:aggregation-method :mean) | ||
|
||
(srcl/get-layer :test) | ||
|
||
;; Define routes for the layer | ||
(srcr/add-route :test | ||
{:name :chitchat | ||
:utterances ["how's the weather today?", | ||
"how are things going?", | ||
"lovely weather today", | ||
"the weather is horrendous", | ||
"let's go to the chippy"]}) | ||
|
||
(srcr/get-route :test :chitchat) | ||
|
||
(srcr/add-route :test | ||
{:name :politics | ||
:utterances ["isn't politics the best thing ever", | ||
"why don't you tell me about your political opinions", | ||
"don't you just love the president", | ||
"they're going to destroy this country!", | ||
"they will save the country!"]}) | ||
|
||
;; Query the layer | ||
(router :test "How are you?") | ||
|
||
(router :test "I'm interested in learning about llama 2") | ||
|
||
(srcl/update-layer :test | ||
:threshold 0.5 | ||
:aggregation-method :mean) | ||
|
||
(router :test "don't you love politics?")) |