Skip to content

Commit 1f9bb6c

Browse files
committed
Fix google llm use correct completion url
1 parent 74cb060 commit 1f9bb6c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/simulflow/processors/google.clj

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
[taoensso.telemere :as t]))
1717

1818
(def google-generative-api-url "https://generativelanguage.googleapis.com/v1beta/openai")
19+
(def google-completions-url (str google-generative-api-url "/chat/completions"))
1920

2021
(comment
2122
;; Get list of valid models
@@ -43,16 +44,29 @@
4344
"gemma-3-12b-it" "gemini-2.0-flash" "gemini-2.5-flash-preview-04-17" "gemini-2.0-flash-001" "gemini-1.5-flash-001" "gemma-3-1b-it" "gemini-2.5-pro-preview-05-06"
4445
"imagen-3.0-generate-002" "gemini-2.0-flash-exp"]))
4546

46-
(def GoogleLLMConfigSchema
47-
[:map
48-
{:description "Google LLM configuration"}
49-
[:llm/model model-schema]
50-
[:google/api-key {:optional true} [:string
51-
{:description "Google API key"
52-
:secret true
53-
:error/message "Invalid Google"}]]])
47+
(def GoogleLLMConfigSchema [:map
48+
{:description "Google LLM configuration"}
49+
[:llm/model {:default :gemini-2.0-flash} model-schema]
50+
[:google/api-key [:string
51+
{:description "Google API key"
52+
:secret true
53+
:error/message "Invalid Google"}]]])
5454

55-
(defn google-llm-process
55+
(comment
56+
57+
(:body (uai/normal-chat-completion {:api-key (secret [:google :api-key])
58+
:model :gemini-2.0-flash
59+
:messages [{:role "system"
60+
:content "You are a voice agent operating via phone. Be
61+
concise in your answers. The input you receive comes from a
62+
speech-to-text (transcription) system that isn't always
63+
efficient and may send unclear text. Ask for
64+
clarification when you're unsure what the person said."}
65+
{:role "user" :content "Do you hear me?"}]
66+
:completions-url google-completions-url}))
67+
,)
68+
69+
(defn google-llm-process-fn
5670
([]
5771
{:ins {:in "Channel for incoming context aggregations"}
5872
:outs {:out "Channel where streaming responses will go"}
@@ -73,10 +87,11 @@
7387
(assert (or (frame/llm-context? frame)
7488
(frame/control-interrupt-start? frame)) "Invalid frame sent to LLM. Only llm-context or interrupt-start")
7589
(let [context (:frame/data frame)
76-
stream-ch (request/stream-chat-completion {:model model
77-
:api-key api-key
78-
:messages (:messages context)
79-
:tools (mapv u/->tool-fn (:tools context))})]
90+
stream-ch (uai/stream-chat-completion {:model model
91+
:api-key api-key
92+
:messages (:messages context)
93+
:tools (mapv u/->tool-fn (:tools context))
94+
:completions-url google-completions-url})]
8095
(uai/handle-completion-request! stream-ch llm-read))
8196

8297
(recur)))
@@ -93,3 +108,5 @@
93108
(frame/llm-context? msg)
94109
[state {:llm-write [msg]
95110
:out [(frame/llm-full-response-start true)]}]))))
111+
112+
(def google-llm-process (flow/process google-llm-process-fn))

0 commit comments

Comments
 (0)