@@ -8,17 +8,20 @@ actor GoogleAIChatCompletionsService: ChatCompletionsAPI, ChatCompletionsStreamA
88 let model : ChatModel
99 var requestBody : ChatCompletionsRequestBody
1010 let prompt : ChatGPTPrompt
11+ let baseURL : String
1112
1213 init (
1314 apiKey: String ,
1415 model: ChatModel ,
1516 requestBody: ChatCompletionsRequestBody ,
16- prompt: ChatGPTPrompt
17+ prompt: ChatGPTPrompt ,
18+ baseURL: String
1719 ) {
1820 self . apiKey = apiKey
1921 self . model = model
2022 self . requestBody = requestBody
2123 self . prompt = prompt
24+ self . baseURL = baseURL
2225 }
2326
2427 func callAsFunction( ) async throws -> ChatCompletionResponseBody {
@@ -27,7 +30,8 @@ actor GoogleAIChatCompletionsService: ChatCompletionsAPI, ChatCompletionsStreamA
2730 apiKey: apiKey,
2831 generationConfig: . init( GenerationConfig (
2932 temperature: requestBody. temperature. map ( Float . init)
30- ) )
33+ ) ) ,
34+ baseURL: baseURL
3135 )
3236 let history = prompt. googleAICompatible. history. map { message in
3337 ModelContent ( message)
@@ -53,6 +57,12 @@ actor GoogleAIChatCompletionsService: ChatCompletionsAPI, ChatCompletionsStreamA
5357 throw error
5458 case . responseStoppedEarly:
5559 throw error
60+ case . promptImageContentError:
61+ throw error
62+ case let . invalidAPIKey( message: message) :
63+ throw error
64+ case . unsupportedUserLocation:
65+ throw error
5666 }
5767 } catch {
5868 throw error
@@ -67,7 +77,8 @@ actor GoogleAIChatCompletionsService: ChatCompletionsAPI, ChatCompletionsStreamA
6777 apiKey: apiKey,
6878 generationConfig: . init( GenerationConfig (
6979 temperature: requestBody. temperature. map ( Float . init)
70- ) )
80+ ) ) ,
81+ baseURL: baseURL
7182 )
7283 let history = prompt. googleAICompatible. history. map { message in
7384 ModelContent ( message)
@@ -100,6 +111,12 @@ actor GoogleAIChatCompletionsService: ChatCompletionsAPI, ChatCompletionsStreamA
100111 continuation. finish ( throwing: error)
101112 case . responseStoppedEarly:
102113 continuation. finish ( throwing: error)
114+ case let . promptImageContentError( underlying: underlying) :
115+ continuation. finish ( throwing: error)
116+ case let . invalidAPIKey( message: message) :
117+ continuation. finish ( throwing: error)
118+ case . unsupportedUserLocation:
119+ continuation. finish ( throwing: error)
103120 }
104121 } catch {
105122 continuation. finish ( throwing: error)
0 commit comments