Skip to content

Commit 56cd3c4

Browse files
committed
Merge branch 'add/more-models' of https://github.com/Compiler-Inc/CompilerSwiftAI into add/more-models
2 parents 8e8911f + ae846ff commit 56cd3c4

File tree

4 files changed

+14
-44
lines changed

4 files changed

+14
-44
lines changed

Sources/CompilerSwiftAI/CompilerClient.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public final actor CompilerClient {
1010
/// Whether to enable debug logging
1111
public var enableDebugLogging: Bool
1212

13+
/// Initialize a new Configuration instance
14+
/// - Parameters:
15+
/// - streamingChat: The streaming configuration to use for chat interactions, defaults to OpenAI GPT-4
16+
/// - enableDebugLogging: Whether to enable detailed debug logging output, defaults to false
1317
public init(
1418
streamingChat: StreamConfiguration = .openAI(.gpt4o),
1519
enableDebugLogging: Bool = false
@@ -24,8 +28,8 @@ public final actor CompilerClient {
2428

2529
private(set) var configuration: Configuration
2630

27-
// internal let baseURL: String = "https://backend.compiler.inc"
28-
internal let baseURL: String = "http://localhost:3000"
31+
internal let baseURL: String = "https://backend.compiler.inc"
32+
// internal let baseURL: String = "http://localhost:3000"
2933
internal let keychain: KeychainHelper = KeychainHelper.standard
3034
internal let functionLogger: DebugLogger
3135
internal let modelLogger: DebugLogger

Sources/CompilerSwiftAI/Model Calling/ChatResponseDTO.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sources/CompilerSwiftAI/Model Calling/CompilerClient+Streaming.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import OSLog
44

5+
struct ChatResponseDataTransferObject: Decodable {
6+
let content: String
7+
}
8+
59
extension CompilerClient {
610
var streamingProviders: [ModelProvider] { [.openai, .anthropic, .gemini] }
711

@@ -181,14 +185,14 @@ extension CompilerClient {
181185
return parsedResponse.content
182186
}
183187

184-
private func parseEventMessage(from line: String) throws -> ChatResponseDTO? {
188+
private func parseEventMessage(from line: String) throws -> ChatResponseDataTransferObject? {
185189
guard let data = line.data(using: .utf8) else {
186190
print("[ChatStreamer] ❌ Failed to convert string to data: \(line)")
187191
return nil
188192
}
189193

190194
do {
191-
let message = try JSONDecoder().decode(ChatResponseDTO.self, from: data)
195+
let message = try JSONDecoder().decode(ChatResponseDataTransferObject.self, from: data)
192196
return message
193197
} catch {
194198
print("[ChatStreamer] ❌ JSON decode error: \(error)")

Sources/CompilerSwiftAI/UI/Chat/ChatView/ChatViewModel.swift

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ class ChatViewModel: Transcribable {
128128

129129
/// Continuously read `chatHistory.messagesStream` and publish changes to SwiftUI.
130130
private func observeMessageStream() async {
131-
let throttleInterval: TimeInterval = 0.15
132-
var lastUpdateTime = Date.distantPast
133-
// var lastMessages: [Message] = []
134-
135131
logger.log("observeMessageStream started. Now waiting for new messages...")
136132

137133
// Continuously receive updates from chatHistory
@@ -142,34 +138,12 @@ class ChatViewModel: Transcribable {
142138
// Log how many messages we got
143139
logger.log("Received newMessages from actor, count = \(newMessages.count). Checking diff...")
144140

145-
// 1) Check if the array is truly different from what we last published
146-
// guard newMessages != lastMessages else {
147-
// logger.log("No diff from lastMessages (count=\(lastMessages.count)). Skipping update to avoid spam.")
148-
// continue
149-
// }
150-
151-
// 2) If we have *too many updates in quick succession*, we do a small throttle
152-
// let now = Date()
153-
// let elapsed = now.timeIntervalSince(lastUpdateTime)
154-
// let needed = throttleInterval - elapsed
155-
// if needed > 0 {
156-
// logger.log("Throttling. Sleeping for \(String(format: "%.2f", needed))s")
157-
// try? await Task.sleep(nanoseconds: UInt64(needed * 1_000_000_000))
158-
//
159-
// // Check again after sleep if task was cancelled
160-
// guard !Task.isCancelled else { break }
161-
// }
162-
//
163-
// 3) Now actually publish these messages to SwiftUI
141+
142+
// Now actually publish these messages to SwiftUI
164143
logger.log("Publishing updated messages to SwiftUI. count=\(newMessages.count)")
165144
await MainActor.run {
166-
// Only update if the messages are still different
167-
// guard self.messages != newMessages else { return }
168145
self.messages = newMessages
169146
}
170-
171-
// lastMessages = newMessages
172-
// lastUpdateTime = now
173147
}
174148

175149
logger.log("observeMessageStream completed or was cancelled.")

0 commit comments

Comments
 (0)