Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/Agent/AgentClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum AgentClientError: LocalizedError {
}
}

public enum Source: Identifiable, Sendable {
public enum Source: Identifiable, Sendable, Equatable {
case openAI(client: OpenAIClient, models: [Model])
case openRouter(client: OpenRouterClient, models: [Model])

Expand All @@ -35,6 +35,11 @@ public enum Source: Identifiable, Sendable {
}
}

public static func == (lhs: Source, rhs: Source) -> Bool {
// Compare by id and models for SwiftUI change detection
lhs.id == rhs.id && lhs.models == rhs.models
}

public var displayName: String {
switch self {
case .openAI: return "OpenAI"
Expand Down
15 changes: 10 additions & 5 deletions Sources/Agent/chat/openaiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public actor OpenAIClient: ChatClient {

public static let defaultBaseURL = URL(string: "https://api.openai.com/v1")!

public init(apiKey: String, baseURL: URL? = nil) {
public init(
apiKey: String = ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "",
baseURL: URL? = URL(
string: ProcessInfo.processInfo.environment["OPENAI_API_BASE_URL"] ?? "")
) {
self.apiKey = apiKey
self.baseURL = baseURL ?? Self.defaultBaseURL
}
Expand Down Expand Up @@ -165,10 +169,11 @@ public actor OpenAIClient: ChatClient {
if let json = try? JSONDecoder().decode(StreamChunk.self, from: data),
let choice = json.choices.first
{
continuation.yield(StreamDelta(
delta: choice.delta,
finishReason: choice.finishReason
))
continuation.yield(
StreamDelta(
delta: choice.delta,
finishReason: choice.finishReason
))
}
}
}
Expand Down
Loading