ac75faa0cc
CI / build-and-test (push) Has been cancelled
- E4B-MarkBase model (42 layers, 4.4GB) loaded successfully - All Phase 1-6 tests passed (model loading, forward pass, vision/audio towers, token generation, performance) - All stress tests passed (5/5 in 127.6s) - Concurrent inference - Memory stress (67.5 tok/s, 0 NaN) - Continuous generation - Batch processing - Long-running stability - Swift Metal inference engine with multimodal support
117 lines
3.0 KiB
Swift
117 lines
3.0 KiB
Swift
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
|
|
}
|
|
}
|