Skip to content

Commit 02d6984

Browse files
committed
Prepare for Xcode Codex support
1 parent 392344e commit 02d6984

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

Tool/Sources/OpenAIService/APIs/OpenAIChatCompletionsService.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ public actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatComplet
7474
case assistant
7575
case function
7676
case tool
77+
case developer
7778

7879
var formalized: ChatCompletionsRequestBody.Message.Role {
7980
switch self {
8081
case .system: return .system
82+
case .developer: return .system
8183
case .user: return .user
8284
case .assistant: return .assistant
8385
case .function: return .tool
@@ -271,10 +273,10 @@ public actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatComplet
271273

272274
public struct RequestBody: Codable, Equatable {
273275
public typealias ClaudeCacheControl = ClaudeChatCompletionsService.RequestBody.CacheControl
274-
276+
275277
public struct GitHubCopilotCacheControl: Codable, Equatable, Sendable {
276278
public var type: String
277-
279+
278280
public init(type: String = "ephemeral") {
279281
self.type = type
280282
}
@@ -435,6 +437,14 @@ public actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatComplet
435437
errors.append(error)
436438
}
437439

440+
do { // Null
441+
_ = try container.decode([ContentPart]?.self)
442+
self = .contentParts([])
443+
return
444+
} catch {
445+
errors.append(error)
446+
}
447+
438448
struct E: Error, LocalizedError {
439449
let errors: [Error]
440450

@@ -785,7 +795,7 @@ public actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatComplet
785795
}
786796
}
787797
}
788-
798+
789799
static func setupGitHubCopilotVisionField(_ request: inout URLRequest, model: ChatModel) {
790800
guard model.format == .gitHubCopilot else { return }
791801
if model.info.supportsImage {
@@ -1001,7 +1011,7 @@ extension OpenAIChatCompletionsService.RequestBody {
10011011
) {
10021012
if supportsMultipartMessageContent {
10031013
switch message.role {
1004-
case .system, .assistant, .user:
1014+
case .system, .developer, .assistant, .user:
10051015
let newParts = Self.convertContentPart(
10061016
content: content,
10071017
images: images,
@@ -1021,7 +1031,7 @@ extension OpenAIChatCompletionsService.RequestBody {
10211031
}
10221032
} else {
10231033
switch message.role {
1024-
case .system, .assistant, .user:
1034+
case .system, .developer, .assistant, .user:
10251035
if case let .text(existingText) = message.content {
10261036
message.content = .text(existingText + "\n\n" + content)
10271037
} else {

Tool/Sources/OpenAIService/Memory/AutoManagedChatGPTMemoryStrategy/AutoManagedChatGPTMemoryOpenAIStrategy.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ extension TokenEncoder {
5858
}
5959
return await group.reduce(0, +)
6060
})
61+
for image in message.images {
62+
encodingContent.append(image.urlString)
63+
total += Int(Double(image.urlString.count) * 1.1)
64+
}
6165
return total
6266
}
6367

0 commit comments

Comments
 (0)