feat: finally nailed down phases 1-4
This commit is contained in:
44
MLXServerTests/Server/APIServerResponseResolutionTests.swift
Normal file
44
MLXServerTests/Server/APIServerResponseResolutionTests.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
import MLXLMCommon
|
||||
import XCTest
|
||||
@testable import MLX_Server
|
||||
|
||||
final class APIServerResponseResolutionTests: XCTestCase {
|
||||
@MainActor
|
||||
func testResolveAssistantResponseUsesFrameworkToolCalls() throws {
|
||||
let frameworkToolCalls = [
|
||||
ToolCall(function: ToolCall.Function(name: "weather", arguments: ["city": "Berlin"]))
|
||||
]
|
||||
|
||||
let resolved = APIServer.resolveAssistantResponse(
|
||||
fullText: "I will call the tool.",
|
||||
frameworkToolCalls: frameworkToolCalls,
|
||||
tools: [mockWeatherTool]
|
||||
)
|
||||
|
||||
XCTAssertEqual(resolved.finishReason, "tool_calls")
|
||||
XCTAssertEqual(resolved.content, "I will call the tool.")
|
||||
let toolCall = try XCTUnwrap(resolved.toolCalls?.first)
|
||||
XCTAssertEqual(toolCall.function.name, "weather")
|
||||
XCTAssertEqual(toolCall.function.arguments, #"{"city":"Berlin"}"#)
|
||||
}
|
||||
|
||||
private var mockWeatherTool: APIToolDefinition {
|
||||
APIToolDefinition(
|
||||
type: "function",
|
||||
function: APIFunctionDefinition(
|
||||
name: "weather",
|
||||
description: "Look up weather for a city.",
|
||||
parameters: [
|
||||
"type": AnyCodable("object"),
|
||||
"properties": AnyCodable([
|
||||
"city": [
|
||||
"type": "string",
|
||||
"description": "City name"
|
||||
]
|
||||
]),
|
||||
"required": AnyCodable(["city"])
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user