Skip to content

Commit bb330b7

Browse files
committed
Handle new chat model format case
1 parent 7604e87 commit bb330b7

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct ChatModelEditView: View {
2222
azureOpenAI
2323
case .openAICompatible:
2424
openAICompatible
25+
case .googleAI:
26+
googleAI
2527
}
2628
}
2729
}
@@ -88,6 +90,8 @@ struct ChatModelEditView: View {
8890
Text("Azure OpenAI").tag(format)
8991
case .openAICompatible:
9092
Text("OpenAI Compatible").tag(format)
93+
case .googleAI:
94+
Text("Google Generative AI").tag(format)
9195
}
9296
}
9397
},
@@ -269,6 +273,20 @@ struct ChatModelEditView: View {
269273
maxTokensTextField
270274
supportsFunctionCallingToggle
271275
}
276+
277+
@ViewBuilder
278+
var googleAI: some View {
279+
apiKeyNamePicker
280+
281+
WithViewStore(
282+
store,
283+
removeDuplicates: { $0.modelName == $1.modelName }
284+
) { viewStore in
285+
TextField("Model Name", text: viewStore.$modelName)
286+
}
287+
288+
maxTokensTextField
289+
}
272290
}
273291

274292
#Preview("OpenAI") {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extension ChatModel: ManageableAIModel {
1010
case .openAI: return "OpenAI"
1111
case .azureOpenAI: return "Azure OpenAI"
1212
case .openAICompatible: return "OpenAI Compatible"
13+
case .googleAI: return "Google Generative AI"
1314
}
1415
}
1516

Tool/Sources/AIModel/ChatModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public struct ChatModel: Codable, Equatable, Identifiable {
2020
case openAI
2121
case azureOpenAI
2222
case openAICompatible
23+
case googleAI
2324
}
2425

2526
public struct Info: Codable, Equatable {
@@ -69,6 +70,10 @@ public struct ChatModel: Codable, Equatable, Identifiable {
6970
let version = "2023-07-01-preview"
7071
if baseURL.isEmpty { return "" }
7172
return "\(baseURL)/openai/deployments/\(deployment)/chat/completions?api-version=\(version)"
73+
case .googleAI:
74+
let baseURL = info.baseURL
75+
if baseURL.isEmpty { return "https://generativelanguage.googleapis.com/v1" }
76+
return "\(baseURL)/v1/chat/completions"
7277
}
7378
}
7479
}

Tool/Sources/OpenAIService/APIs/OpenAICompletionAPI.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct OpenAICompletionAPI: CompletionAPI {
9494
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
9595
case .azureOpenAI:
9696
request.setValue(apiKey, forHTTPHeaderField: "api-key")
97+
case .googleAI:
98+
assert(false, "Unsupported")
9799
}
98100
}
99101

Tool/Sources/OpenAIService/APIs/OpenAICompletionStreamAPI.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ struct OpenAICompletionStreamAPI: CompletionStreamAPI {
186186
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
187187
case .azureOpenAI:
188188
request.setValue(apiKey, forHTTPHeaderField: "api-key")
189+
case .googleAI:
190+
assert(false, "Unsupported")
189191
}
190192
}
191193

0 commit comments

Comments
 (0)