v2: Initial clean branch with unit tests + CI/CD pipeline
- Started from ac75faa (initial E4B-MarkBase integration)
- Kept Sources/ (all engine code) + Package.swift + .gitignore
- Removed all ad-hoc tests, documentation, scripts, Python files
- Added Tests/00_Unit/ (MathTest, TokenizerTest, SamplerTest)
- Added .gitea/workflows/ci.yaml (build + unit tests + lint)
- Added Scripts/check_resources.sh (memory-aware test runner)
- Added Tests/Manifest.json (resource requirements for all tests)
- Focus: 4-bit quantized models only
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import Foundation
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// JSON Schema Response API Models
|
||||
// OpenAI Compatible Format
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// Response format specification
|
||||
public enum ResponseFormat: Codable {
|
||||
case text
|
||||
case jsonObject
|
||||
case jsonSchema(JSONSchemaDefinition)
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case type
|
||||
case jsonSchema = "json_schema"
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let type = try container.decode(String.self, forKey: .type)
|
||||
|
||||
switch type {
|
||||
case "text":
|
||||
self = .text
|
||||
case "json_object":
|
||||
self = .jsonObject
|
||||
case "json_schema":
|
||||
let schema = try container.decode(JSONSchemaDefinition.self, forKey: .jsonSchema)
|
||||
self = .jsonSchema(schema)
|
||||
default:
|
||||
throw DecodingError.dataCorruptedError(
|
||||
forKey: .type,
|
||||
in: container,
|
||||
debugDescription: "Unknown response format type: \(type)"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
switch self {
|
||||
case .text:
|
||||
try container.encode("text", forKey: .type)
|
||||
case .jsonObject:
|
||||
try container.encode("json_object", forKey: .type)
|
||||
case .jsonSchema(let schema):
|
||||
try container.encode("json_schema", forKey: .type)
|
||||
try container.encode(schema, forKey: .jsonSchema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON Schema definition
|
||||
public struct JSONSchemaDefinition: Codable {
|
||||
public let name: String
|
||||
public let description: String?
|
||||
public let schema: JSONSchema
|
||||
public let strict: Bool?
|
||||
|
||||
public init(
|
||||
name: String,
|
||||
description: String? = nil,
|
||||
schema: JSONSchema,
|
||||
strict: Bool? = nil
|
||||
) {
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.schema = schema
|
||||
self.strict = strict
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON Schema
|
||||
public struct JSONSchema: Codable {
|
||||
public let type: String
|
||||
public let properties: [String: SchemaProperty]?
|
||||
public let required: [String]?
|
||||
public let additionalProperties: Bool?
|
||||
|
||||
public init(
|
||||
type: String,
|
||||
properties: [String: SchemaProperty]? = nil,
|
||||
required: [String]? = nil,
|
||||
additionalProperties: Bool? = false
|
||||
) {
|
||||
self.type = type
|
||||
self.properties = properties
|
||||
self.required = required
|
||||
self.additionalProperties = additionalProperties
|
||||
}
|
||||
}
|
||||
|
||||
/// Schema property
|
||||
public struct SchemaProperty: Codable {
|
||||
public let type: String
|
||||
public let description: String?
|
||||
public let `enum`: [String]?
|
||||
public let properties: [String: SchemaProperty]?
|
||||
public let required: [String]?
|
||||
|
||||
public init(
|
||||
type: String,
|
||||
description: String? = nil,
|
||||
enum: [String]? = nil,
|
||||
properties: [String: SchemaProperty]? = nil,
|
||||
required: [String]? = nil
|
||||
) {
|
||||
self.type = type
|
||||
self.description = description
|
||||
self.enum = `enum`
|
||||
self.properties = properties
|
||||
self.required = required
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user