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
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Function Calling API Models
|
||||
// OpenAI Compatible Format
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// Tool definition
|
||||
public struct Tool: Codable {
|
||||
public let type: String
|
||||
public let function: FunctionDefinition
|
||||
|
||||
public init(type: String = "function", function: FunctionDefinition) {
|
||||
self.type = type
|
||||
self.function = function
|
||||
}
|
||||
}
|
||||
|
||||
/// Function definition
|
||||
public struct FunctionDefinition: Codable {
|
||||
public let name: String
|
||||
public let description: String?
|
||||
public let parameters: FunctionParameters?
|
||||
|
||||
public init(
|
||||
name: String,
|
||||
description: String? = nil,
|
||||
parameters: FunctionParameters? = nil
|
||||
) {
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.parameters = parameters
|
||||
}
|
||||
}
|
||||
|
||||
/// Function parameters (JSON Schema)
|
||||
public struct FunctionParameters: Codable {
|
||||
public let type: String
|
||||
public let properties: [String: PropertySchema]?
|
||||
public let required: [String]?
|
||||
|
||||
public init(
|
||||
type: String = "object",
|
||||
properties: [String: PropertySchema]? = nil,
|
||||
required: [String]? = nil
|
||||
) {
|
||||
self.type = type
|
||||
self.properties = properties
|
||||
self.required = required
|
||||
}
|
||||
}
|
||||
|
||||
/// Property schema
|
||||
public struct PropertySchema: Codable {
|
||||
public let type: String
|
||||
public let description: String?
|
||||
public let `enum`: [String]?
|
||||
|
||||
public init(
|
||||
type: String,
|
||||
description: String? = nil,
|
||||
enum: [String]? = nil
|
||||
) {
|
||||
self.type = type
|
||||
self.description = description
|
||||
self.enum = `enum`
|
||||
}
|
||||
}
|
||||
|
||||
/// Tool call in response
|
||||
public struct ToolCall: Codable, Sendable {
|
||||
public let id: String
|
||||
public let type: String
|
||||
public let function: FunctionCall
|
||||
|
||||
public init(
|
||||
id: String = "call_\(UUID().uuidString.replacingOccurrences(of: "-", with: "").prefix(9))",
|
||||
type: String = "function",
|
||||
function: FunctionCall
|
||||
) {
|
||||
self.id = id
|
||||
self.type = type
|
||||
self.function = function
|
||||
}
|
||||
}
|
||||
|
||||
/// Function call
|
||||
public struct FunctionCall: Codable, Sendable {
|
||||
public let name: String
|
||||
public let arguments: String
|
||||
|
||||
public init(name: String, arguments: String) {
|
||||
self.name = name
|
||||
self.arguments = arguments
|
||||
}
|
||||
}
|
||||
|
||||
/// Tool message
|
||||
public struct ToolMessage: Codable {
|
||||
public let role: String
|
||||
public let content: String?
|
||||
public let tool_call_id: String?
|
||||
public let name: String?
|
||||
|
||||
public init(
|
||||
role: String = "tool",
|
||||
content: String?,
|
||||
tool_call_id: String?,
|
||||
name: String?
|
||||
) {
|
||||
self.role = role
|
||||
self.content = content
|
||||
self.tool_call_id = tool_call_id
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user