@@ -175,15 +175,18 @@ public final class GenerativeModel {
175
175
-> GenerateContentResponse {
176
176
let response : GenerateContentResponse
177
177
do {
178
- let generateContentRequest = try GenerateContentRequest ( model: modelResourceName,
179
- contents: content ( ) ,
180
- generationConfig: generationConfig,
181
- safetySettings: safetySettings,
182
- tools: tools,
183
- toolConfig: toolConfig,
184
- systemInstruction: systemInstruction,
185
- isStreaming: false ,
186
- options: requestOptions)
178
+ let generateContentRequest = try GenerateContentRequest (
179
+ model: modelResourceName,
180
+ isModelEncoded: false ,
181
+ contents: content ( ) ,
182
+ generationConfig: generationConfig,
183
+ safetySettings: safetySettings,
184
+ tools: tools,
185
+ toolConfig: toolConfig,
186
+ systemInstruction: systemInstruction,
187
+ isStreaming: false ,
188
+ options: requestOptions
189
+ )
187
190
response = try await generativeAIService. loadRequest ( request: generateContentRequest)
188
191
} catch {
189
192
if let imageError = error as? ImageConversionError {
@@ -249,15 +252,18 @@ public final class GenerativeModel {
249
252
}
250
253
}
251
254
252
- let generateContentRequest = GenerateContentRequest ( model: modelResourceName,
253
- contents: evaluatedContent,
254
- generationConfig: generationConfig,
255
- safetySettings: safetySettings,
256
- tools: tools,
257
- toolConfig: toolConfig,
258
- systemInstruction: systemInstruction,
259
- isStreaming: true ,
260
- options: requestOptions)
255
+ let generateContentRequest = GenerateContentRequest (
256
+ model: modelResourceName,
257
+ isModelEncoded: false ,
258
+ contents: evaluatedContent,
259
+ generationConfig: generationConfig,
260
+ safetySettings: safetySettings,
261
+ tools: tools,
262
+ toolConfig: toolConfig,
263
+ systemInstruction: systemInstruction,
264
+ isStreaming: true ,
265
+ options: requestOptions
266
+ )
261
267
262
268
var responseIterator = generativeAIService. loadRequestStream ( request: generateContentRequest)
263
269
. makeAsyncIterator ( )
@@ -325,9 +331,19 @@ public final class GenerativeModel {
325
331
public func countTokens( _ content: @autoclosure ( ) throws -> [ ModelContent ] ) async throws
326
332
-> CountTokensResponse {
327
333
do {
328
- let countTokensRequest = try CountTokensRequest (
334
+ let generateContentRequest = try GenerateContentRequest ( model: modelResourceName,
335
+ isModelEncoded: true ,
336
+ contents: content ( ) ,
337
+ generationConfig: generationConfig,
338
+ safetySettings: safetySettings,
339
+ tools: tools,
340
+ toolConfig: toolConfig,
341
+ systemInstruction: systemInstruction,
342
+ isStreaming: false ,
343
+ options: requestOptions)
344
+ let countTokensRequest = CountTokensRequest (
329
345
model: modelResourceName,
330
- contents : content ( ) ,
346
+ generateContentRequest : generateContentRequest ,
331
347
options: requestOptions
332
348
)
333
349
return try await generativeAIService. loadRequest ( request: countTokensRequest)
0 commit comments