|
15 | 15 | (def groq-api-url "https://api.groq.com/openai/v1") |
16 | 16 | (def groq-completions-url (str groq-api-url "/chat/completions")) |
17 | 17 |
|
18 | | -(defn stream-groq-chat-completion |
19 | | - [{:keys [api-key messages tools model]}] |
20 | | - (:body (request/sse-request {:request {:url groq-completions-url |
21 | | - :headers {"Authorization" (str "Bearer " api-key) |
22 | | - "Content-Type" "application/json"} |
23 | | - |
24 | | - :method :post |
25 | | - :body (u/json-str (cond-> {:messages messages |
26 | | - :stream true |
27 | | - :model model} |
28 | | - (pos? (count tools)) (assoc :tools tools)))} |
29 | | - :params {:stream/close? true}}))) |
30 | | - |
31 | | -(defn normal-chat-completion |
32 | | - [{:keys [api-key messages tools model]}] |
33 | | - (http/request {:url groq-completions-url |
34 | | - :headers {"Authorization" (str "Bearer " api-key) |
35 | | - "Content-Type" "application/json"} |
36 | | - |
37 | | - :throw-on-error? false |
38 | | - :method :post |
39 | | - :body (u/json-str (cond-> {:messages messages |
40 | | - :stream true |
41 | | - :model model} |
42 | | - (pos? (count tools)) (assoc :tools tools)))})) |
43 | | - |
44 | | -(comment |
45 | | - |
46 | | - (map u/token-content (a/<!! (a/into [] (stream-groq-chat-completion |
47 | | - {:model "llama-3.3-70b-versatile" |
48 | | - :api-key (secret [:groq :api-key]) |
49 | | - :messages [{:role "system" :content "Ești un agent vocal care funcționează prin telefon. Răspunde doar în limba română și fii succint. Inputul pe care îl primești vine dintr-un sistem de speech to text (transcription) care nu este intotdeauna eficient și poate trimite text neclar. Cere clarificări când nu ești sigur pe ce a spus omul."} |
50 | | - {:role "user" :content "Salutare ma auzi?"}]})))) |
51 | | - |
52 | | - ,) |
53 | | - |
54 | | -(comment |
55 | | - |
56 | | - (->> (http/get (str groq-api-url "/models") |
57 | | - {:headers {"Authorization" (str "Bearer " (secret [:groq :api-key])) |
58 | | - "Content-Type" "application/json"}}) |
59 | | - :body |
60 | | - u/parse-if-json |
61 | | - :data |
62 | | - (map :id)) |
63 | | - ,) |
64 | | - |
65 | | -(def delta (comp :delta first :choices)) |
66 | | - |
67 | 18 | (def GroqLLMConfigSchema |
68 | 19 | [:map |
69 | 20 | {:closed true |
|
0 commit comments