Skip to content

Commit f2ed55d

Browse files
committed
Fix function calling settings for ollama
1 parent e9b88b7 commit f2ed55d

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

Core/Sources/HostApp/AccountSettings/ChatModelManagement/ChatModelEdit.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ extension ChatModel {
195195
if case .googleAI = state.format {
196196
return false
197197
}
198+
if case .ollama = state.format {
199+
return false
200+
}
198201
return state.supportsFunctionCalling
199202
}(),
200203
modelName: state.modelName.trimmingCharacters(in: .whitespacesAndNewlines),

Tool/Sources/OpenAIService/ChatGPTService.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,13 @@ extension ChatGPTService {
575575
model: ChatModel,
576576
stream: Bool
577577
) -> ChatCompletionsRequestBody {
578+
let serviceSupportsFunctionCalling = switch model.format {
579+
case .openAI, .openAICompatible, .azureOpenAI:
580+
model.info.supportsFunctionCalling
581+
case .ollama, .googleAI:
582+
false
583+
}
584+
578585
let messages = prompt.history.flatMap { chatMessage in
579586
var all = [ChatCompletionsRequestBody.Message]()
580587
all.append(ChatCompletionsRequestBody.Message(
@@ -588,7 +595,7 @@ extension ChatGPTService {
588595
content: chatMessage.content ?? "",
589596
name: chatMessage.name,
590597
toolCalls: {
591-
if model.info.supportsFunctionCalling {
598+
if serviceSupportsFunctionCalling {
592599
chatMessage.toolCalls?.map {
593600
.init(
594601
id: $0.id,
@@ -606,7 +613,7 @@ extension ChatGPTService {
606613
))
607614

608615
for call in chatMessage.toolCalls ?? [] {
609-
if model.info.supportsFunctionCalling {
616+
if serviceSupportsFunctionCalling {
610617
all.append(ChatCompletionsRequestBody.Message(
611618
role: .tool,
612619
content: call.response.content,
@@ -635,10 +642,10 @@ extension ChatGPTService {
635642
maxToken: model.info.maxTokens,
636643
remainingTokens: remainingTokens
637644
),
638-
toolChoice: model.info.supportsFunctionCalling
645+
toolChoice: serviceSupportsFunctionCalling
639646
? functionProvider.functionCallStrategy
640647
: nil,
641-
tools: model.info.supportsFunctionCalling
648+
tools: serviceSupportsFunctionCalling
642649
? functionProvider.functions.map {
643650
.init(function: ChatGPTFunctionSchema(
644651
name: $0.name,

0 commit comments

Comments
 (0)