File tree Expand file tree Collapse file tree 4 files changed +32
-16
lines changed
Expand file tree Collapse file tree 4 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 55- Add env support for MCPs
66- Add web_search capability
77- Add ` o3 ` model support.
8+ - Support custom API urls for OpenAI and Anthropic
89
910## 0.0.3
1011
Original file line number Diff line number Diff line change 5555(defn cache-tools! [db*]
5656 (let [obj-mapper (ObjectMapper. )]
5757 (doseq [[name {:keys [client]}] (:mcp-clients @db*)]
58- (doseq [^McpSchema$Tool tool-client (.tools (.listTools ^McpSyncClient client))]
59- (let [tool {:name (.name tool-client)
60- :mcp-name name
61- :mcp-client client
62- :description (.description tool-client)
63- ; ; We convert to json to then read so we have the clojrue map
64- ; ; TODO avoid this converting to clojure map directly
65- :parameters (json/parse-string (.writeValueAsString obj-mapper (.inputSchema tool-client)) true )}]
66- (swap! db* assoc-in [:mcp-tools (:name tool)] tool))))))
58+ (when (.isInitialized client)
59+ (doseq [^McpSchema$Tool tool-client (.tools (.listTools ^McpSyncClient client))]
60+ (let [tool {:name (.name tool-client)
61+ :mcp-name name
62+ :mcp-client client
63+ :description (.description tool-client)
64+ ; ; We convert to json to then read so we have the clojrue map
65+ ; ; TODO avoid this converting to clojure map directly
66+ :parameters (json/parse-string (.writeValueAsString obj-mapper (.inputSchema tool-client)) true )}]
67+ (swap! db* assoc-in [:mcp-tools (:name tool)] tool)))))))
6768
6869(defn list-tools [db]
6970 (vals (:mcp-tools db)))
Original file line number Diff line number Diff line change 1010
1111(def ^:private logger-tag " [ANTHROPIC]" )
1212
13- (def ^:private url " https://api.anthropic.com/v1/messages" )
13+ (def ^:private anthropic-url " https://api.anthropic.com" )
14+ (def ^:private messages-path " /v1/messages" )
15+
16+ (defn ^:private url [path]
17+ (format " %s%s"
18+ (or (System/getenv " ANTHROPIC_API_URL" )
19+ anthropic-url)
20+ path))
1421
1522(defn ^:private ->tools [tools web-search]
1623 (cond->
2532 (let [api-key (or api-key
2633 (System/getenv " ANTHROPIC_API_KEY" ))]
2734 (http/post
28- url
35+ ( url messages-path)
2936 {:headers {" x-api-key" api-key
3037 " anthropic-version" " 2023-06-01"
3138 " Content-Type" " application/json" }
Original file line number Diff line number Diff line change 1010
1111(def ^:private logger-tag " [OPENAI]" )
1212
13- (def ^:private url " https://api.openai.com/v1/responses" )
13+ (def ^:private openai-url " https://api.openai.com/" )
14+ (def ^:private responses-path " /v1/responses" )
1415
15- (defn ^:private base-request! [{:keys [body api-key on-error on-response]}]
16+ (defn ^:private url [path]
17+ (format " %s%s"
18+ (or (System/getenv " OPENAI_API_URL" )
19+ openai-url)
20+ path))
21+
22+ (defn ^:private base-completion-request! [{:keys [body api-key on-error on-response]}]
1623 (let [api-key (or api-key
1724 (System/getenv " OPENAI_API_KEY" ))]
1825 (http/post
19- url
26+ ( url responses-path)
2027 {:headers {" Authorization" (str " Bearer " api-key)
2128 " Content-Type" " application/json" }
2229 :body (json/generate-string body)
5865 function-args (-> data :item :arguments )
5966 response (on-tool-called {:name function-name
6067 :arguments (json/parse-string function-args)})]
61- (base-request!
68+ (base-completion- request!
6269 {:body (assoc body :input (concat input
6370 [{:type " function_call"
6471 :call_id (-> data :item :call_id )
8491 (on-message-received {:type :finish
8592 :finish-reason (-> data :response :status )}))
8693 nil ))]
87- (base-request!
94+ (base-completion- request!
8895 {:body body
8996 :api-key api-key
9097 :on-error on-error
You can’t perform that action at this time.
0 commit comments