@@ -85,57 +85,52 @@ ProviderDatabricks <- new_class(
8585 properties = list (credentials = class_function )
8686)
8787
88- method(chat_request , ProviderDatabricks ) <- function (
88+ method(base_request , ProviderDatabricks ) <- function (provider ) {
89+ req <- request(provider @ base_url )
90+ req <- ellmer_req_credentials(req , provider @ credentials )
91+ req <- req_retry(req , max_tries = 2 )
92+ req <- ellmer_req_timeout(req , stream )
93+ req <- ellmer_req_user_agent(req , databricks_user_agent())
94+ req <- base_request_error(provider , req )
95+ req
96+ }
97+
98+ method(chat_body , ProviderDatabricks ) <- function (
8999 provider ,
90100 stream = TRUE ,
91101 turns = list (),
92102 tools = list (),
93103 type = NULL
94104) {
95- req <- request(provider @ base_url )
105+ body <- chat_body(
106+ super(provider , ProviderOpenAI ),
107+ stream = stream ,
108+ turns = turns ,
109+ tools = tools ,
110+ type = type
111+ )
112+
113+ # Databricks doensn't support stream options
114+ body $ stream_options <- NULL
115+
116+ body
117+ }
118+
119+ method(chat_path , ProviderDatabricks ) <- function (provider ) {
96120 # Note: this API endpoint is undocumented and seems to exist primarily for
97121 # compatibility with the OpenAI Python SDK. The documented endpoint is
98122 # `/serving-endpoints/<model>/invocations`.
99- req <- req_url_path_append(req , " /serving-endpoints/chat/completions" )
100- req <- ellmer_req_credentials(req , provider @ credentials )
101- req <- ellmer_req_user_agent(req , databricks_user_agent())
102- req <- req_retry(req , max_tries = 2 )
103- req <- ellmer_req_timeout(req , stream )
104- req <- req_error(req , body = function (resp ) {
123+ " /serving-endpoints/chat/completions"
124+ }
125+
126+ method(base_request_error , ProviderDatabricks ) <- function (provider , req ) {
127+ req_error(req , body = function (resp ) {
105128 if (resp_content_type(resp ) == " application/json" ) {
106129 # Databrick's "OpenAI-compatible" API has a slightly incompatible error
107130 # response format, which we account for here.
108131 resp_body_json(resp )$ message
109132 }
110133 })
111-
112- messages <- compact(unlist(as_json(provider , turns ), recursive = FALSE ))
113- tools <- as_json(provider , unname(tools ))
114-
115- if (! is.null(type )) {
116- response_format <- list (
117- type = " json_schema" ,
118- json_schema = list (
119- name = " structured_data" ,
120- schema = as_json(provider , type ),
121- strict = TRUE
122- )
123- )
124- } else {
125- response_format <- NULL
126- }
127-
128- body <- compact(list (
129- messages = messages ,
130- model = provider @ model ,
131- stream = stream ,
132- tools = tools ,
133- response_format = response_format
134- ))
135- body <- modify_list(body , provider @ extra_args )
136- req <- req_body_json(req , body )
137-
138- req
139134}
140135
141136method(as_json , list (ProviderDatabricks , Turn )) <- function (provider , x ) {
0 commit comments