Skip to content

Commit 42e5934

Browse files
committed
Lower APIs from package to internal access
1 parent 5e5ed58 commit 42e5934

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

Sources/AnyLanguageModel/Extensions/Character+Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
extension Character {
2-
package static let jsonQuoteScalars: Set<UInt32> = [0x22, 0x201C, 0x201D, 0x2018, 0x2019]
3-
package static let jsonAllowedWhitespaceCharacters: Set<Character> = [" ", "\t", "\n"]
2+
static let jsonQuoteScalars: Set<UInt32> = [0x22, 0x201C, 0x201D, 0x2018, 0x2019]
3+
static let jsonAllowedWhitespaceCharacters: Set<Character> = [" ", "\t", "\n"]
44

5-
package var containsEmojiScalar: Bool {
5+
var containsEmojiScalar: Bool {
66
unicodeScalars.contains { scalar in
77
scalar.properties.isEmojiPresentation || scalar.properties.isEmoji
88
}
99
}
1010

11-
package var isValidJSONStringCharacter: Bool {
11+
var isValidJSONStringCharacter: Bool {
1212
guard self != "\\" else { return false }
1313
guard let scalar = unicodeScalars.first, scalar.value >= 0x20 else { return false }
1414
guard !Self.jsonQuoteScalars.contains(scalar.value) else { return false }

Sources/AnyLanguageModel/Extensions/JSONDecoder+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
extension JSONDecoder.DateDecodingStrategy {
4-
package static let iso8601WithFractionalSeconds = custom { decoder in
4+
static let iso8601WithFractionalSeconds = custom { decoder in
55
let container = try decoder.singleValueContainer()
66
let string = try container.decode(String.self)
77

Sources/AnyLanguageModel/Extensions/URLSession+Extensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import JSONSchema
66
import FoundationNetworking
77
#endif
88

9-
package enum HTTP {
10-
package enum Method: String {
9+
enum HTTP {
10+
enum Method: String {
1111
case get = "GET"
1212
case post = "POST"
1313
}
1414
}
1515

1616
extension URLSession {
17-
package func fetch<T: Decodable>(
17+
func fetch<T: Decodable>(
1818
_ method: HTTP.Method,
1919
url: URL,
2020
headers: [String: String] = [:],
@@ -57,7 +57,7 @@ extension URLSession {
5757
}
5858
}
5959

60-
package func fetchStream<T: Decodable & Sendable>(
60+
func fetchStream<T: Decodable & Sendable>(
6161
_ method: HTTP.Method,
6262
url: URL,
6363
headers: [String: String] = [:],
@@ -120,7 +120,7 @@ extension URLSession {
120120
}
121121
}
122122

123-
package func fetchEventStream<T: Decodable & Sendable>(
123+
func fetchEventStream<T: Decodable & Sendable>(
124124
_ method: HTTP.Method,
125125
url: URL,
126126
headers: [String: String] = [:],

Sources/AnyLanguageModel/GenerationGuide.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import class Foundation.NSDecimalNumber
33

44
/// Guides that control how values are generated.
55
public struct GenerationGuide<Value>: Sendable {
6-
package var minimumCount: Int?
7-
package var maximumCount: Int?
8-
package var minimum: Double?
9-
package var maximum: Double?
6+
var minimumCount: Int?
7+
var maximumCount: Int?
8+
var minimum: Double?
9+
var maximum: Double?
1010

1111
public init() {}
1212

13-
package init(minimumCount: Int?, maximumCount: Int?) {
13+
init(minimumCount: Int?, maximumCount: Int?) {
1414
self.minimumCount = minimumCount
1515
self.maximumCount = maximumCount
1616
}
1717

18-
package init(minimum: Double?, maximum: Double?) {
18+
init(minimum: Double?, maximum: Double?) {
1919
self.minimum = minimum
2020
self.maximum = maximum
2121
}
@@ -114,19 +114,19 @@ extension GenerationGuide where Value == Float {
114114
///
115115
/// The bounds are inclusive.
116116
public static func minimum(_ value: Float) -> GenerationGuide<Float> {
117-
GenerationGuide<Float>()
117+
GenerationGuide<Float>(minimum: Double(value), maximum: nil)
118118
}
119119

120120
/// Enforces a maximum value.
121121
///
122122
/// The bounds are inclusive.
123123
public static func maximum(_ value: Float) -> GenerationGuide<Float> {
124-
GenerationGuide<Float>()
124+
GenerationGuide<Float>(minimum: nil, maximum: Double(value))
125125
}
126126

127127
/// Enforces values fall within a range.
128128
public static func range(_ range: ClosedRange<Float>) -> GenerationGuide<Float> {
129-
GenerationGuide<Float>()
129+
GenerationGuide<Float>(minimum: Double(range.lowerBound), maximum: Double(range.upperBound))
130130
}
131131
}
132132

@@ -138,19 +138,22 @@ extension GenerationGuide where Value == Decimal {
138138
///
139139
/// The bounds are inclusive.
140140
public static func minimum(_ value: Decimal) -> GenerationGuide<Decimal> {
141-
GenerationGuide<Decimal>()
141+
GenerationGuide<Decimal>(minimum: NSDecimalNumber(decimal: value).doubleValue, maximum: nil)
142142
}
143143

144144
/// Enforces a maximum value.
145145
///
146146
/// The bounds are inclusive.
147147
public static func maximum(_ value: Decimal) -> GenerationGuide<Decimal> {
148-
GenerationGuide<Decimal>()
148+
GenerationGuide<Decimal>(minimum: nil, maximum: NSDecimalNumber(decimal: value).doubleValue)
149149
}
150150

151151
/// Enforces values fall within a range.
152152
public static func range(_ range: ClosedRange<Decimal>) -> GenerationGuide<Decimal> {
153-
GenerationGuide<Decimal>()
153+
GenerationGuide<Decimal>(
154+
minimum: NSDecimalNumber(decimal: range.lowerBound).doubleValue,
155+
maximum: NSDecimalNumber(decimal: range.upperBound).doubleValue
156+
)
154157
}
155158
}
156159

Sources/AnyLanguageModel/GenerationSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ extension GenerationSchema {
871871
/// ```
872872
static let omitAdditionalPropertiesKey = CodingUserInfoKey(rawValue: "GenerationSchema.omitAdditionalProperties")!
873873

874-
package func schemaPrompt() -> String {
874+
func schemaPrompt() -> String {
875875
let encoder = JSONEncoder()
876876
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
877877
guard let data = try? encoder.encode(self),

Sources/AnyLanguageModel/StructuredGeneration.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66
///
77
/// Implementations provide tokenization, sampling, and decoding state so the
88
/// generator can constrain output to valid JSON for a schema.
9-
package protocol TokenBackend {
9+
protocol TokenBackend {
1010
func tokenize(_ text: String) throws -> [Int]
1111
func tokenText(_ token: Int) -> String?
1212
func isSpecialToken(_ token: Int) -> Bool
@@ -23,7 +23,7 @@ package protocol TokenBackend {
2323
// MARK: - JSON Generator
2424

2525
/// Generates JSON that conforms to a schema using constrained token sampling.
26-
package struct ConstrainedJSONGenerator<Backend: TokenBackend> {
26+
struct ConstrainedJSONGenerator<Backend: TokenBackend> {
2727
private var backend: Backend
2828
private let schema: GenerationSchema
2929
private var emittedText = ""
@@ -44,7 +44,7 @@ package struct ConstrainedJSONGenerator<Backend: TokenBackend> {
4444
/// - backend: A backend that provides tokenization and sampling.
4545
/// - schema: The generation schema to satisfy.
4646
/// - Throws: ``ConstrainedGenerationError`` when required tokens cannot be tokenized.
47-
package init(backend: Backend, schema: GenerationSchema) throws {
47+
init(backend: Backend, schema: GenerationSchema) throws {
4848
self.backend = backend
4949
self.schema = schema
5050

@@ -71,7 +71,7 @@ package struct ConstrainedJSONGenerator<Backend: TokenBackend> {
7171
///
7272
/// - Returns: A JSON string that satisfies the schema.
7373
/// - Throws: ``ConstrainedGenerationError`` if generation fails.
74-
package mutating func generate() throws -> String {
74+
mutating func generate() throws -> String {
7575
do {
7676
return try generateNode(schema.root)
7777
} catch let error as ConstrainedGenerationError {
@@ -429,7 +429,7 @@ package struct ConstrainedJSONGenerator<Backend: TokenBackend> {
429429
// MARK: - Errors
430430

431431
/// An error that can occur during constrained JSON generation.
432-
package enum ConstrainedGenerationError: LocalizedError {
432+
enum ConstrainedGenerationError: LocalizedError {
433433
/// A required value failed to tokenize.
434434
case tokenizationFailed
435435

@@ -467,7 +467,7 @@ package enum ConstrainedGenerationError: LocalizedError {
467467
/// An any-of schema has no choices.
468468
case emptyAnyOf
469469

470-
package var errorDescription: String? {
470+
var errorDescription: String? {
471471
switch self {
472472
case .tokenizationFailed:
473473
return "Failed to tokenize a required value"

0 commit comments

Comments
 (0)