Skip to content

Commit bc43b91

Browse files
committed
Disable function calling for models that don't support it
1 parent 8dc12f0 commit bc43b91

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

Tool/Sources/OpenAIService/ChatGPTService.swift

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension ChatGPTService {
196196
)
197197
}
198198
let remainingTokens = await memory.remainingTokens
199-
199+
200200
let model = configuration.model
201201

202202
let requestBody = CompletionRequestBody(
@@ -209,14 +209,19 @@ extension ChatGPTService {
209209
maxToken: model.info.maxTokens,
210210
remainingTokens: remainingTokens
211211
),
212-
function_call: functionProvider.functionCallStrategy,
213-
functions: functionProvider.functions.map {
214-
ChatGPTFunctionSchema(
215-
name: $0.name,
216-
description: $0.description,
217-
parameters: $0.argumentSchema
218-
)
219-
}
212+
function_call: model.info.supportsFunctionCalling
213+
? functionProvider.functionCallStrategy
214+
: nil,
215+
functions:
216+
model.info.supportsFunctionCalling
217+
? functionProvider.functions.map {
218+
ChatGPTFunctionSchema(
219+
name: $0.name,
220+
description: $0.description,
221+
parameters: $0.argumentSchema
222+
)
223+
}
224+
: []
220225
)
221226

222227
let api = buildCompletionStreamAPI(
@@ -298,7 +303,7 @@ extension ChatGPTService {
298303
)
299304
}
300305
let remainingTokens = await memory.remainingTokens
301-
306+
302307
let model = configuration.model
303308

304309
let requestBody = CompletionRequestBody(
@@ -311,14 +316,19 @@ extension ChatGPTService {
311316
maxToken: model.info.maxTokens,
312317
remainingTokens: remainingTokens
313318
),
314-
function_call: functionProvider.functionCallStrategy,
315-
functions: functionProvider.functions.map {
316-
ChatGPTFunctionSchema(
317-
name: $0.name,
318-
description: $0.description,
319-
parameters: $0.argumentSchema
320-
)
321-
}
319+
function_call: model.info.supportsFunctionCalling
320+
? functionProvider.functionCallStrategy
321+
: nil,
322+
functions:
323+
model.info.supportsFunctionCalling
324+
? functionProvider.functions.map {
325+
ChatGPTFunctionSchema(
326+
name: $0.name,
327+
description: $0.description,
328+
parameters: $0.argumentSchema
329+
)
330+
}
331+
: []
322332
)
323333

324334
let api = buildCompletionAPI(

0 commit comments

Comments
 (0)