Skip to content

Commit 2f9e5c3

Browse files
committed
Add OpenAI-Organization and OpenAI-Project
1 parent e534a45 commit 2f9e5c3

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct ChatModelEdit {
2929
var apiKeySelection: APIKeySelection.State = .init()
3030
var baseURLSelection: BaseURLSelection.State = .init()
3131
var enforceMessageOrder: Bool = false
32+
var openAIOrganizationID: String = ""
33+
var openAIProjectID: String = ""
3234
}
3335

3436
enum Action: Equatable, BindableAction {
@@ -197,6 +199,10 @@ extension ChatModel {
197199
}
198200
}(),
199201
modelName: state.modelName.trimmingCharacters(in: .whitespacesAndNewlines),
202+
openAIInfo: .init(
203+
organizationID: state.openAIOrganizationID,
204+
projectID: state.openAIProjectID
205+
),
200206
ollamaInfo: .init(keepAlive: state.ollamaKeepAlive),
201207
googleGenerativeAIInfo: .init(apiVersion: state.apiVersion),
202208
openAICompatibleInfo: .init(enforceMessageOrder: state.enforceMessageOrder)
@@ -219,7 +225,9 @@ extension ChatModel {
219225
apiKeyManagement: .init(availableAPIKeyNames: [info.apiKeyName])
220226
),
221227
baseURLSelection: .init(baseURL: info.baseURL, isFullURL: info.isFullURL),
222-
enforceMessageOrder: info.openAICompatibleInfo.enforceMessageOrder
228+
enforceMessageOrder: info.openAICompatibleInfo.enforceMessageOrder,
229+
openAIOrganizationID: info.openAIInfo.organizationID,
230+
openAIProjectID: info.openAIInfo.projectID
223231
)
224232
}
225233
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ struct ChatModelEditView: View {
243243

244244
MaxTokensTextField(store: store)
245245
SupportsFunctionCallingToggle(store: store)
246+
247+
TextField(text: $store.openAIOrganizationID, prompt: Text("Optional")) {
248+
Text("Organization ID")
249+
}
250+
251+
TextField(text: $store.openAIProjectID, prompt: Text("Optional")) {
252+
Text("Project ID")
253+
}
246254

247255
VStack(alignment: .leading, spacing: 8) {
248256
Text(Image(systemName: "exclamationmark.triangle.fill")) + Text(
@@ -308,7 +316,7 @@ struct ChatModelEditView: View {
308316

309317
MaxTokensTextField(store: store)
310318
SupportsFunctionCallingToggle(store: store)
311-
319+
312320
Toggle(isOn: $store.enforceMessageOrder) {
313321
Text("Enforce message order to be user/assistant alternated")
314322
}
@@ -387,9 +395,9 @@ struct ChatModelEditView: View {
387395
BaseURLTextField(store: store, prompt: Text("https://api.anthropic.com")) {
388396
Text("/v1/messages")
389397
}
390-
398+
391399
ApiKeyNamePicker(store: store)
392-
400+
393401
TextField("Model Name", text: $store.modelName)
394402
.overlay(alignment: .trailing) {
395403
Picker(
@@ -411,9 +419,9 @@ struct ChatModelEditView: View {
411419
)
412420
.frame(width: 20)
413421
}
414-
422+
415423
MaxTokensTextField(store: store)
416-
424+
417425
VStack(alignment: .leading, spacing: 8) {
418426
Text(Image(systemName: "exclamationmark.triangle.fill")) + Text(
419427
" For more details, please visit [https://anthropic.com](https://anthropic.com)."

Tool/Sources/AIModel/ChatModel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ public struct ChatModel: Codable, Equatable, Identifiable {
3838
public struct OpenAIInfo: Codable, Equatable {
3939
@FallbackDecoding<EmptyString>
4040
public var organizationID: String
41+
@FallbackDecoding<EmptyString>
42+
public var projectID: String
4143

42-
public init(organizationID: String = "") {
44+
public init(organizationID: String = "", projectID: String = "") {
4345
self.organizationID = organizationID
46+
self.projectID = projectID
4447
}
4548
}
4649

Tool/Sources/OpenAIService/APIs/OpenAIChatCompletionsService.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatCompletionsAPI
350350
forHTTPHeaderField: "OpenAI-Organization"
351351
)
352352
}
353+
354+
if !model.info.openAIInfo.projectID.isEmpty {
355+
request.setValue(
356+
model.info.openAIInfo.projectID,
357+
forHTTPHeaderField: "OpenAI-Project"
358+
)
359+
}
360+
353361
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
354362
case .openAICompatible:
355363
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")

0 commit comments

Comments
 (0)