Skip to content

Commit 2ad4e6d

Browse files
committed
Remove tool calling content if function calling is not supported
1 parent ef396be commit 2ad4e6d

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

Tool/Sources/OpenAIService/ChatGPTService.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -587,24 +587,37 @@ extension ChatGPTService {
587587
}(),
588588
content: chatMessage.content ?? "",
589589
name: chatMessage.name,
590-
toolCalls: chatMessage.toolCalls?.map {
591-
.init(
592-
id: $0.id,
593-
type: $0.type,
594-
function: .init(
595-
name: $0.function.name,
596-
arguments: $0.function.arguments
597-
)
598-
)
599-
}
590+
toolCalls: {
591+
if model.info.supportsFunctionCalling {
592+
chatMessage.toolCalls?.map {
593+
.init(
594+
id: $0.id,
595+
type: $0.type,
596+
function: .init(
597+
name: $0.function.name,
598+
arguments: $0.function.arguments
599+
)
600+
)
601+
}
602+
} else {
603+
nil
604+
}
605+
}()
600606
))
601607

602608
for call in chatMessage.toolCalls ?? [] {
603-
all.append(ChatCompletionsRequestBody.Message(
604-
role: .tool,
605-
content: call.response.content,
606-
toolCallId: call.response.id
607-
))
609+
if model.info.supportsFunctionCalling {
610+
all.append(ChatCompletionsRequestBody.Message(
611+
role: .tool,
612+
content: call.response.content,
613+
toolCallId: call.response.id
614+
))
615+
} else {
616+
all.append(ChatCompletionsRequestBody.Message(
617+
role: .user,
618+
content: call.response.content
619+
))
620+
}
608621
}
609622

610623
return all

0 commit comments

Comments
 (0)