Skip to content

Commit 060866f

Browse files
authored
Add public initializers in LanguageModelSession (#102)
1 parent c77ed79 commit 060866f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Sources/AnyLanguageModel/LanguageModelSession.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ public final class LanguageModelSession: @unchecked Sendable {
160160
public let rawContent: GeneratedContent
161161
public let transcriptEntries: ArraySlice<Transcript.Entry>
162162

163-
init(
163+
/// Creates a response value from generated content and transcript entries.
164+
/// - Parameters:
165+
/// - content: The decoded response content.
166+
/// - rawContent: The raw content produced by the model.
167+
/// - transcriptEntries: Transcript entries associated with the response.
168+
public init(
164169
content: Content,
165170
rawContent: GeneratedContent,
166171
transcriptEntries: ArraySlice<Transcript.Entry>
@@ -768,12 +773,18 @@ extension LanguageModelSession {
768773
private let fallbackSnapshot: Snapshot?
769774
private let streaming: AsyncThrowingStream<Snapshot, any Error>?
770775

771-
init(content: Content, rawContent: GeneratedContent) {
776+
/// Creates a response stream that yields a single snapshot.
777+
/// - Parameters:
778+
/// - content: The complete response content.
779+
/// - rawContent: The raw content produced by the model.
780+
public init(content: Content, rawContent: GeneratedContent) {
772781
self.fallbackSnapshot = Snapshot(content: content.asPartiallyGenerated(), rawContent: rawContent)
773782
self.streaming = nil
774783
}
775784

776-
init(stream: AsyncThrowingStream<Snapshot, any Error>) {
785+
/// Creates a response stream that yields snapshots from an async stream.
786+
/// - Parameter stream: The snapshot stream to relay.
787+
public init(stream: AsyncThrowingStream<Snapshot, any Error>) {
777788
// When streaming, snapshots arrive from the upstream sequence, so no fallback is required.
778789
self.fallbackSnapshot = nil
779790
self.streaming = stream
@@ -782,6 +793,15 @@ extension LanguageModelSession {
782793
public struct Snapshot: Sendable where Content.PartiallyGenerated: Sendable {
783794
public var content: Content.PartiallyGenerated
784795
public var rawContent: GeneratedContent
796+
797+
/// Creates a snapshot from partially generated content and raw content.
798+
/// - Parameters:
799+
/// - content: The partially generated content.
800+
/// - rawContent: The raw content produced by the model.
801+
public init(content: Content.PartiallyGenerated, rawContent: GeneratedContent) {
802+
self.content = content
803+
self.rawContent = rawContent
804+
}
785805
}
786806
}
787807
}

0 commit comments

Comments
 (0)