{"id":31725554,"url":"https://github.com/mattt/anylanguagemodel","last_synced_at":"2026-01-19T21:00:45.630Z","repository":{"id":318538929,"uuid":"1070177613","full_name":"mattt/AnyLanguageModel","owner":"mattt","description":"An API-compatible, drop-in replacement for Apple's Foundation Models framework with support for custom language model providers.","archived":false,"fork":false,"pushed_at":"2026-01-05T17:03:39.000Z","size":280,"stargazers_count":644,"open_issues_count":14,"forks_count":44,"subscribers_count":10,"default_branch":"main","last_synced_at":"2026-01-11T07:30:33.328Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-05T12:32:00.000Z","updated_at":"2026-01-09T14:44:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"de77eb2f-dd38-4355-af69-e225b92fa7e7","html_url":"https://github.com/mattt/AnyLanguageModel","commit_stats":null,"previous_names":["mattt/anylanguagemodel"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/mattt/AnyLanguageModel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FAnyLanguageModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FAnyLanguageModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FAnyLanguageModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FAnyLanguageModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattt","download_url":"https://codeload.github.com/mattt/AnyLanguageModel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FAnyLanguageModel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28585185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T20:45:59.482Z","status":"ssl_error","status_checked_at":"2026-01-19T20:45:41.500Z","response_time":67,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-09T05:49:51.976Z","updated_at":"2026-01-19T21:00:45.593Z","avatar_url":"https://github.com/mattt.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnyLanguageModel\n\nA Swift package that provides a drop-in replacement for\n[Apple's Foundation Models framework](https://developer.apple.com/documentation/FoundationModels)\nwith support for custom language model providers.\nAll you need to do is change your import statement:\n\n```diff\n- import FoundationModels\n+ import AnyLanguageModel\n```\n\n```swift\nstruct WeatherTool: Tool {\n    let name = \"getWeather\"\n    let description = \"Retrieve the latest weather information for a city\"\n\n    @Generable\n    struct Arguments {\n        @Guide(description: \"The city to fetch the weather for\")\n        var city: String\n    }\n\n    func call(arguments: Arguments) async throws -\u003e String {\n        \"The weather in \\(arguments.city) is sunny and 72°F / 23°C\"\n    }\n}\n\nlet model = SystemLanguageModel.default\nlet session = LanguageModelSession(model: model, tools: [WeatherTool()])\n\nlet response = try await session.respond {\n    Prompt(\"How's the weather in Cupertino?\")\n}\nprint(response.content)\n```\n\n## Features\n\n### Supported Providers\n\n- [x] [Apple Foundation Models](https://developer.apple.com/documentation/FoundationModels)\n- [x] [Core ML](https://developer.apple.com/documentation/coreml) models\n- [x] [MLX](https://github.com/ml-explore/mlx-swift) models\n- [x] [llama.cpp](https://github.com/ggml-org/llama.cpp) (GGUF models)\n- [x] Ollama [HTTP API](https://github.com/ollama/ollama/blob/main/docs/api.md)\n- [x] Anthropic [Messages API](https://docs.claude.com/en/api/messages)\n- [x] Google [Gemini API](https://ai.google.dev/api/generate-content)\n- [x] OpenAI [Chat Completions API](https://platform.openai.com/docs/api-reference/chat)\n- [x] OpenAI [Responses API](https://platform.openai.com/docs/api-reference/responses)\n\n## Requirements\n\n- Swift 6.1+\n- iOS 17.0+ / macOS 14.0+ / visionOS 1.0+ / Linux\n\n\u003e [!IMPORTANT]\n\u003e A bug in Xcode 26 may cause build errors\n\u003e when targeting macOS 15 / iOS 18 or earlier\n\u003e (e.g. `Conformance of 'String' to 'Generable' is only available in macOS 26.0 or newer`).\n\u003e As a workaround, build your project with Xcode 16.\n\u003e For more information, see [issue #15](https://github.com/mattt/AnyLanguageModel/issues/15).\n\n## Installation\n\nAdd this package to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/mattt/AnyLanguageModel\", from: \"0.5.0\")\n]\n```\n\n### Package Traits\n\nAnyLanguageModel uses [Swift 6.1 traits](https://docs.swift.org/swiftpm/documentation/packagemanagerdocs/packagetraits/)\nto conditionally include heavy dependencies,\nallowing you to opt-in only to the language model backends you need.\nThis results in smaller binary sizes and faster build times.\n\n**Available traits**:\n\n- `CoreML`: Enables Core ML model support\n  (depends on `huggingface/swift-transformers`)\n- `MLX`: Enables MLX model support\n  (depends on `ml-explore/mlx-swift-lm`)\n- `Llama`: Enables llama.cpp support\n  (requires `mattt/llama.swift`)\n\nBy default, no traits are enabled.\nTo enable specific traits, specify them in your package's dependencies:\n\n```swift\n// In your Package.swift\ndependencies: [\n    .package(\n        url: \"https://github.com/mattt/AnyLanguageModel.git\",\n        from: \"0.5.0\",\n        traits: [\"CoreML\", \"MLX\"] // Enable CoreML and MLX support\n    )\n]\n```\n\n### Using Traits in Xcode Projects\n\nXcode doesn't yet provide a built-in way to declare package dependencies with traits.\nAs a workaround,\nyou can create an internal Swift package that acts as a shim,\nexporting the `AnyLanguageModel` module with the desired traits enabled.\nYour Xcode project can then add this internal package as a local dependency.\n\nFor example,\nto use AnyLanguageModel with MLX support in an Xcode app project:\n\n**1. Create a local Swift package**\n(in root directory containing Xcode project):\n\n```shell\nmkdir -p Packages/MyAppKit\ncd Packages/MyAppKit\nswift package init\n```\n\n**2. Specify AnyLanguageModel package dependency**\n(in `Packages/MyAppKit/Package.swift`):\n\n```swift\n// swift-tools-version: 6.1\nimport PackageDescription\n\nlet package = Package(\n    name: \"MyAppKit\",\n    platforms: [\n        .macOS(.v14),\n        .iOS(.v17),\n        .visionOS(.v1),\n    ],\n    products: [\n        .library(\n            name: \"MyAppKit\",\n            targets: [\"MyAppKit\"]\n        )\n    ],\n    dependencies: [\n        .package(\n            url: \"https://github.com/mattt/AnyLanguageModel\",\n            from: \"0.4.0\",\n            traits: [\"MLX\"]\n        )\n    ],\n    targets: [\n        .target(\n            name: \"MyAppKit\",\n            dependencies: [\n                .product(name: \"AnyLanguageModel\", package: \"AnyLanguageModel\")\n            ]\n        )\n    ]\n)\n```\n\n**3. Export the AnyLanguageModel module**\n(in `Sources/MyAppKit/Export.swift`):\n\n```swift\n@_exported import AnyLanguageModel\n```\n\n**4. Add the local package to your Xcode project**:\n\nOpen your project settings,\nnavigate to the \"Package Dependencies\" tab,\nand click \"+\" → \"Add Local...\" to select the `Packages/MyAppKit` directory.\n\nYour app can now import `AnyLanguageModel` with MLX support enabled.\n\n\u003e [!TIP]\n\u003e For a working example of package traits in an Xcode app project,\n\u003e see [chat-ui-swift](https://github.com/mattt/chat-ui-swift).\n\n## API Credentials and Security\n\nWhen using third-party language model providers like OpenAI, Anthropic, or Google Gemini,\nyou must handle API credentials securely.\n\n\u003e [!CAUTION]\n\u003e **Never hardcode API credentials in your app**.\n\u003e Malicious actors can reverse‑engineer your application binary\n\u003e or observe outgoing network requests\n\u003e (for example, on a compromised device or via a debugging proxy)\n\u003e to extract embedded credentials.\n\u003e There have been documented cases of attackers successfully exfiltrating\n\u003e API keys from mobile apps and racking up thousands of dollars in charges.\n\nHere are two approaches for managing API credentials in production apps:\n\n### Bring Your Own Key (BYO)\n\nUsers provide their own API keys,\nwhich are stored securely in the system Keychain\nand sent directly to the provider in API requests.\n\n**Security considerations**:\n\n- Keychain data is encrypted using hardware-backed keys\n  (protected by the Secure Enclave on supported devices)\n- An attacker would need access to a running process to intercept credentials\n- TLS encryption protects credentials in transit on the network\n- Users can only compromise their own keys, not other users' keys\n\n**Trade-offs**:\n\n- Apple App Review has often rejected apps using this model\n- Reviewers may be unable to test functionality — even with provided credentials\n- Apple may require in-app purchase integration for usage credits\n- Some users may find it inconvenient to obtain and enter API keys\n\n### Proxy Server\n\nInstead of connecting directly to the provider,\nroute requests through your own authenticated service endpoint.\nAPI credentials are stored securely on your server,\nnever in the client app.\n\nAuthenticate users with [OAuth 2.1](https://oauth.net/2.1/) or similar,\nissuing short-lived, scoped bearer tokens for client requests.\nIf an attacker extracts tokens from your app,\nthey're limited in scope and expire automatically.\n\n**Security considerations**:\n\n- API keys never leave your server infrastructure\n- Client tokens can be scoped\n  (e.g., rate-limited, feature-restricted)\n- Client tokens can be revoked or expired independently\n- Compromised tokens have limited blast radius\n\n**Trade-offs**:\n\n- Additional infrastructure complexity\n  (server, authentication, monitoring)\n- Operational costs\n  (hosting, maintenance, support)\n- Network latency from additional hop\n\nFortunately, there are platforms and services that simplify proxy implementation,\nhandling authentication, rate limiting, and billing for you.\n\n\u003e [!TIP]\n\u003e For development and testing, it's fine to use API keys from environment variables.\n\u003e Just make sure production builds use one of the secure approaches above.\n\nFor more information about security best practices for your app,\nsee OWASP's\n[Mobile Application Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Mobile_Application_Security_Cheat_Sheet.html).\n\n## Usage\n\n### Apple Foundation Models\n\nUses Apple's [system language model](https://developer.apple.com/documentation/FoundationModels)\n(requires macOS 26 / iOS 26 / visionOS 26 or later).\n\n```swift\nlet model = SystemLanguageModel.default\nlet session = LanguageModelSession(model: model)\n\nlet response = try await session.respond {\n    Prompt(\"Explain quantum computing in one sentence\")\n}\n```\n\n\u003e [!NOTE]\n\u003e Image inputs are not yet supported by Apple Foundation Models.\n\n### Core ML\n\nRun [Core ML](https://developer.apple.com/documentation/coreml) models\n(requires `CoreML` trait):\n\n```swift\nlet model = CoreMLLanguageModel(url: URL(fileURLWithPath: \"path/to/model.mlmodelc\"))\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond {\n    Prompt(\"Summarize this text\")\n}\n```\n\nEnable the trait in Package.swift:\n\n```swift\n.package(\n    url: \"https://github.com/mattt/AnyLanguageModel.git\",\n    branch: \"main\",\n    traits: [\"CoreML\"]\n)\n```\n\n\u003e [!NOTE]\n\u003e Image inputs are not currently supported with `CoreMLLanguageModel`.\n\n### MLX\n\nRun [MLX](https://github.com/ml-explore/mlx-swift) models on Apple Silicon\n(requires `MLX` trait):\n\n```swift\nlet model = MLXLanguageModel(modelId: \"mlx-community/Qwen3-0.6B-4bit\")\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond {\n    Prompt(\"What is the capital of France?\")\n}\n```\n\nVision support depends on the specific MLX model you load.\nUse a vision‑capable model for multimodal prompts\n(for example, a VLM variant).\nThe following shows extracting text from an image:\n\n```swift\nlet ocr = try await session.respond(\n    to: \"Extract the total amount from this receipt\",\n    images: [\n        .init(url: URL(fileURLWithPath: \"/path/to/receipt_page1.png\")),\n        .init(url: URL(fileURLWithPath: \"/path/to/receipt_page2.png\"))\n    ]\n)\nprint(ocr.content)\n```\n\nEnable the trait in Package.swift:\n\n```swift\n.package(\n    url: \"https://github.com/mattt/AnyLanguageModel.git\",\n    branch: \"main\",\n    traits: [\"MLX\"]\n)\n```\n\n### llama.cpp (GGUF)\n\nRun GGUF quantized models via [llama.cpp](https://github.com/ggml-org/llama.cpp)\n(requires `Llama` trait):\n\n```swift\nlet model = LlamaLanguageModel(modelPath: \"/path/to/model.gguf\")\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond {\n    Prompt(\"Translate 'hello world' to Spanish\")\n}\n```\n\nEnable the trait in Package.swift:\n\n```swift\n.package(\n    url: \"https://github.com/mattt/AnyLanguageModel.git\",\n    branch: \"main\",\n    traits: [\"Llama\"]\n)\n```\n\nConfiguration is done via custom generation options,\nallowing you to control runtime parameters per request:\n\n```swift\nvar options = GenerationOptions(temperature: 0.8)\noptions[custom: LlamaLanguageModel.self] = .init(\n    contextSize: 4096,        // Context window size\n    batchSize: 512,           // Batch size for evaluation\n    threads: 8,               // Number of threads\n    seed: 42,                 // Random seed for deterministic output\n    temperature: 0.7,         // Sampling temperature\n    topK: 40,                 // Top-K sampling\n    topP: 0.95,               // Top-P (nucleus) sampling\n    repeatPenalty: 1.2,       // Penalty for repeated tokens\n    repeatLastN: 128,         // Number of tokens to consider for repeat penalty\n    frequencyPenalty: 0.1,    // Frequency-based penalty\n    presencePenalty: 0.1,     // Presence-based penalty\n    mirostat: .v2(tau: 5.0, eta: 0.1)  // Adaptive perplexity control\n)\n\nlet response = try await session.respond(\n    to: \"Write a story\",\n    options: options\n)\n```\n\n\u003e [!NOTE]\n\u003e Image inputs are not currently supported with `LlamaLanguageModel`.\n\n### OpenAI\n\nSupports both\n[Chat Completions](https://platform.openai.com/docs/api-reference/chat) and\n[Responses](https://platform.openai.com/docs/api-reference/responses) APIs:\n\n```swift\nlet model = OpenAILanguageModel(\n    apiKey: ProcessInfo.processInfo.environment[\"OPENAI_API_KEY\"]!,\n    model: \"gpt-4o-mini\"\n)\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond(\n    to: \"List the objects you see\",\n    images: [\n        .init(url: URL(string: \"https://example.com/desk.jpg\")!),\n        .init(\n            data: try Data(contentsOf: URL(fileURLWithPath: \"/path/to/closeup.png\")),\n            mimeType: \"image/png\"\n        )\n    ]\n)\nprint(response.content)\n```\n\nFor OpenAI-compatible endpoints that use older Chat Completions API:\n\n```swift\nlet model = OpenAILanguageModel(\n    baseURL: URL(string: \"https://api.example.com\")!,\n    apiKey: apiKey,\n    model: \"gpt-4o-mini\",\n    apiVariant: .chatCompletions\n)\n```\n\nUse custom generation options for advanced parameters like sampling controls,\nreasoning effort (for o-series models), and vendor-specific extensions:\n\n```swift\nvar options = GenerationOptions(temperature: 0.8)\noptions[custom: OpenAILanguageModel.self] = .init(\n    topP: 0.9,\n    frequencyPenalty: 0.5,\n    presencePenalty: 0.3,\n    stopSequences: [\"END\"],\n    reasoningEffort: .high,        // For reasoning models (o3, o4-mini)\n    serviceTier: .priority,\n    extraBody: [                   // Vendor-specific parameters\n        \"custom_param\": .string(\"value\")\n    ]\n)\n```\n\n### Anthropic\n\nUses the [Messages API](https://docs.claude.com/en/api/messages) with Claude models:\n\n```swift\nlet model = AnthropicLanguageModel(\n    apiKey: ProcessInfo.processInfo.environment[\"ANTHROPIC_API_KEY\"]!,\n    model: \"claude-sonnet-4-5-20250929\"\n)\n\nlet session = LanguageModelSession(model: model, tools: [WeatherTool()])\nlet response = try await session.respond {\n    Prompt(\"What's the weather like in San Francisco?\")\n}\n```\n\nYou can include images with your prompt.\nYou can point to remote URLs or construct from image data:\n\n```swift\nlet response = try await session.respond(\n    to: \"Explain the key parts of this diagram\",\n    image: .init(\n        data: try Data(contentsOf: URL(fileURLWithPath: \"/path/to/diagram.png\")),\n        mimeType: \"image/png\"\n    )\n)\nprint(response.content)\n```\n\nUse custom generation options for Anthropic-specific parameters like\nextended thinking, tool choice control, and sampling parameters:\n\n```swift\nvar options = GenerationOptions(temperature: 0.7)\noptions[custom: AnthropicLanguageModel.self] = .init(\n    topP: 0.9,\n    topK: 40,\n    stopSequences: [\"END\", \"STOP\"],\n    thinking: .init(budgetTokens: 4096),  // Extended thinking\n    toolChoice: .auto,                     // Tool selection control\n    serviceTier: .priority\n)\n```\n\n### Google Gemini\n\nUses the [Gemini API](https://ai.google.dev/api/generate-content) with Gemini models:\n\n```swift\nlet model = GeminiLanguageModel(\n    apiKey: ProcessInfo.processInfo.environment[\"GEMINI_API_KEY\"]!,\n    model: \"gemini-2.5-flash\"\n)\n\nlet session = LanguageModelSession(model: model, tools: [WeatherTool()])\nlet response = try await session.respond {\n    Prompt(\"What's the weather like in Tokyo?\")\n}\n```\n\nSend images with your prompt using remote or local sources:\n\n```swift\nlet response = try await session.respond(\n    to: \"Identify the plants in this photo\",\n    image: .init(url: URL(string: \"https://example.com/garden.jpg\")!)\n)\nprint(response.content)\n```\n\nGemini models use an internal [\"thinking process\"](https://ai.google.dev/gemini-api/docs/thinking)\nthat improves reasoning and multi-step planning.\nConfigure thinking mode through custom generation options:\n\n```swift\nvar options = GenerationOptions()\n\n// Enable thinking with dynamic budget allocation\noptions[custom: GeminiLanguageModel.self] = .init(thinking: .dynamic)\n\n// Or set an explicit number of tokens for its thinking budget\noptions[custom: GeminiLanguageModel.self] = .init(thinking: .budget(1024))\n\n// Disable thinking (default)\noptions[custom: GeminiLanguageModel.self] = .init(thinking: .disabled)\n\nlet response = try await session.respond(to: \"Solve this problem\", options: options)\n```\n\nGemini supports [server-side tools](https://ai.google.dev/gemini-api/docs/google-search)\nthat execute transparently on Google's infrastructure:\n\n```swift\nvar options = GenerationOptions()\noptions[custom: GeminiLanguageModel.self] = .init(\n    serverTools: [\n        .googleSearch,\n        .googleMaps(latitude: 35.6580, longitude: 139.7016)\n    ]\n)\n\nlet response = try await session.respond(\n    to: \"What coffee shops are nearby?\",\n    options: options\n)\n```\n\n**Available server tools**:\n\n- `.googleSearch`\n  Grounds responses with real-time web information\n- `.googleMaps`\n  Provides location-aware responses\n- `.codeExecution`\n  Generates and runs Python code to solve problems\n- `.urlContext`\n  Fetches and analyzes content from URLs mentioned in prompts\n\n\u003e [!TIP]\n\u003e Gemini server tools are not available as client tools (`Tool`) for other models.\n\n### Ollama\n\nRun models locally via Ollama's\n[HTTP API](https://github.com/ollama/ollama/blob/main/docs/api.md):\n\n```swift\n// Default: connects to http://localhost:11434\nlet model = OllamaLanguageModel(model: \"qwen3\") // `ollama pull qwen3:8b`\n\n// Custom endpoint\nlet model = OllamaLanguageModel(\n    endpoint: URL(string: \"http://remote-server:11434\")!,\n    model: \"llama3.2\"\n)\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond {\n    Prompt(\"Tell me a joke\")\n}\n```\n\nFor local models, make sure you're using a vision‑capable model\n(for example, a `-vl` variant).\nYou can combine multiple images:\n\n```swift\nlet model = OllamaLanguageModel(model: \"qwen3-vl\") // `ollama pull qwen3-vl:8b`\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond(\n    to: \"Compare these posters and summarize their differences\",\n    images: [\n        .init(url: URL(string: \"https://example.com/poster1.jpg\")!),\n        .init(url: URL(fileURLWithPath: \"/path/to/poster2.jpg\"))\n    ]\n)\nprint(response.content)\n```\n\nPass any model-specific parameters using custom generation options:\n\n```swift\nvar options = GenerationOptions(temperature: 0.8)\noptions[custom: OllamaLanguageModel.self] = [\n    \"seed\": .int(42),\n    \"repeat_penalty\": .double(1.2),\n    \"num_ctx\": .int(4096),\n    \"stop\": .array([.string(\"###\")])\n]\n```\n\n## Testing\n\nRun the test suite to verify everything works correctly:\n\n```bash\nswift test\n```\n\nTests for different language model backends have varying requirements:\n\n| Backend | Traits | Environment Variables |\n|---------|--------|----------------------|\n| CoreML | `CoreML` | `HF_TOKEN` |\n| MLX | `MLX` | `HF_TOKEN` |\n| Llama | `Llama` | `LLAMA_MODEL_PATH` |\n| Anthropic | — | `ANTHROPIC_API_KEY` |\n| OpenAI | — | `OPENAI_API_KEY` |\n| Ollama | — | — |\n\nExample setup for running multiple tests at once:\n\n```bash\nexport HF_TOKEN=your_huggingface_token\nexport LLAMA_MODEL_PATH=/path/to/model.gguf\nexport ANTHROPIC_API_KEY=your_anthropic_key\nexport OPENAI_API_KEY=your_openai_key\n\nswift test --traits CoreML,Llama\n```\n\n\u003e [!TIP]\n\u003e Tests that perform generation are skipped in CI environments (when `CI` is set).\n\u003e Override this by setting `ENABLE_COREML_TESTS=1` or `ENABLE_MLX_TESTS=1`.\n\n\u003e [!NOTE]\n\u003e MLX tests must be run with `xcodebuild` rather than `swift test`\n\u003e due to Metal library loading requirements.\n\u003e Since `xcodebuild` doesn't support package traits directly,\n\u003e you'll first need to update `Package.swift` to enable the MLX trait by default.\n\u003e\n\u003e ```diff\n\u003e - .default(enabledTraits: []),\n\u003e + .default(enabledTraits: [\"MLX\"]),\n\u003e ```\n\u003e \n\u003e Pass environment variables with `TEST_RUNNER_` prefix:\n\u003e\n\u003e ```bash\n\u003e export TEST_RUNNER_HF_TOKEN=your_huggingface_token\n\u003e xcodebuild test \\\n\u003e   -scheme AnyLanguageModel \\\n\u003e   -destination 'platform=macOS' \\\n\u003e   -only-testing:AnyLanguageModelTests/MLXLanguageModelTests\n\u003e ```\n\n## License\n\nThis project is available under the MIT license.\nSee the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2Fanylanguagemodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattt%2Fanylanguagemodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2Fanylanguagemodel/lists"}