Skip to content

Commit 7e0a6ad

Browse files
authored
Merge pull request #394 from MacPaw/chore/improve-chat-query-description
Improve ChatQuery description readability
2 parents 3f2cac9 + 8542896 commit 7e0a6ad

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

Demo/DemoChat/Package.resolved

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/DemoChat/Sources/ResponsesStore.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ public final class ResponsesStore: ObservableObject {
656656
case .mcpToolCall(_ /* let mcpCall */):
657657
// MCP tool call in progress - no UI action needed
658658
break
659+
case .reasoning(let reasoningItem):
660+
print("reasoning output item added, summary: \(reasoningItem.summary)")
659661
default:
660662
throw StoreError.unhandledOutputItem(outputItem)
661663
}
@@ -693,6 +695,8 @@ public final class ResponsesStore: ObservableObject {
693695
if let output = mcpCall.output {
694696
print("Result: \(output)")
695697
}
698+
case .reasoning(let reasoningItem):
699+
print("reasoning output item done, summary: \(reasoningItem.summary)")
696700
default:
697701
throw StoreError.unhandledOutputItem(outputItem)
698702
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// ChatQuery+CustomStringConvertible.swift
3+
// OpenAI
4+
//
5+
// Created by Oleksii Nezhyborets on 19.11.2025.
6+
//
7+
8+
import Foundation
9+
10+
extension ChatQuery: CustomStringConvertible, CustomDebugStringConvertible {
11+
12+
public var description: String { jsonDescription(prettyPrinted: true) }
13+
14+
public var debugDescription: String { jsonDescription(prettyPrinted: true) }
15+
16+
private func jsonDescription(prettyPrinted: Bool) -> String {
17+
let encoder = JSONEncoder()
18+
var formatting: JSONEncoder.OutputFormatting = [.sortedKeys]
19+
if prettyPrinted {
20+
formatting.insert(.prettyPrinted)
21+
}
22+
encoder.outputFormatting = formatting
23+
guard
24+
let data = try? encoder.encode(self),
25+
let string = String(data: data, encoding: .utf8)
26+
else {
27+
return "ChatQuery(model: \(model), messages: \(messages.count))"
28+
}
29+
return string
30+
}
31+
}

0 commit comments

Comments
 (0)