Support OpenAI-compatible inference endpoints
This commit is contained in:
@@ -364,3 +364,26 @@ final class GenerationConfigurationTests: XCTestCase {
|
||||
XCTAssertThrowsError(try DockerCommand.arguments("docker logs 'unclosed"))
|
||||
}
|
||||
}
|
||||
|
||||
final class CompatibleEndpointTests: XCTestCase {
|
||||
func testRequiresHTTPSForRemoteAndRejectsEmbeddedCredentials() throws {
|
||||
XCTAssertThrowsError(try CompatibleEndpoint(endpoint: "http://example.com/v1"))
|
||||
XCTAssertThrowsError(try CompatibleEndpoint(endpoint: "https://user:[email protected]/v1"))
|
||||
XCTAssertNoThrow(try CompatibleEndpoint(endpoint: "http://127.0.0.1:1234/v1"))
|
||||
}
|
||||
|
||||
func testAuthenticatedDiscoveryAndStreaming() async throws {
|
||||
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_COMPATIBLE_URL"] else {
|
||||
throw XCTSkip("Set AISTUDIO_TEST_COMPATIBLE_URL to the compatible endpoint fixture.")
|
||||
}
|
||||
let client = try CompatibleEndpoint(endpoint: endpoint, token: "fixture-token")
|
||||
let models = try await client.models()
|
||||
XCTAssertEqual(models, ["fixture-model"])
|
||||
let output = try await collect(client.generate(InferenceRequest(model: "fixture-model", messages: [
|
||||
Message(role: .system, content: "Silent instruction"),
|
||||
Message(role: .user, content: "Hello")
|
||||
], thinking: .automatic, parameters: GenerationParameters(temperature: 0, maxTokens: 32))))
|
||||
XCTAssertEqual(output, [.backend("Compatible API · fixture-model"),
|
||||
.thinking("Thinking"), .answer("Fixture response")])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user