{"id":30700089,"url":"https://github.com/flinedev/intelligencekit","last_synced_at":"2025-09-02T11:43:59.417Z","repository":{"id":312343922,"uuid":"1047100266","full_name":"FlineDev/IntelligenceKit","owner":"FlineDev","description":"Unified Swift package for OpenAI API integration with GPT-5 support and advanced reasoning capabilities.","archived":false,"fork":false,"pushed_at":"2025-08-29T23:01:08.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-30T01:07:54.489Z","etag":null,"topics":["ai","intelligence","openai-api","swift","swift6"],"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/FlineDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":"Jeehut","patreon":"Jeehut","custom":["paypal.me/FlineDev"]}},"created_at":"2025-08-29T18:34:13.000Z","updated_at":"2025-08-29T23:00:18.000Z","dependencies_parsed_at":"2025-08-30T01:07:59.995Z","dependency_job_id":"6876815d-8fed-449e-b492-384ac2fedc31","html_url":"https://github.com/FlineDev/IntelligenceKit","commit_stats":null,"previous_names":["flinedev/intelligencekit"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/FlineDev/IntelligenceKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlineDev%2FIntelligenceKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlineDev%2FIntelligenceKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlineDev%2FIntelligenceKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlineDev%2FIntelligenceKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlineDev","download_url":"https://codeload.github.com/FlineDev/IntelligenceKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlineDev%2FIntelligenceKit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273279895,"owners_count":25077318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ai","intelligence","openai-api","swift","swift6"],"created_at":"2025-09-02T11:43:26.822Z","updated_at":"2025-09-02T11:43:59.402Z","avatar_url":"https://github.com/FlineDev.png","language":"Swift","readme":"[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FFlineDev%2FIntelligenceKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/FlineDev/IntelligenceKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FFlineDev%2FIntelligenceKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/FlineDev/IntelligenceKit)\n\n# IntelligenceKit\n\nUnified Swift package for OpenAI API integration with GPT-5 support and advanced reasoning capabilities.\n\n## Platform Support\n\n- **Apple Platforms**: iOS 18+, macOS 15+, tvOS 18+, visionOS 2+, watchOS 11+\n- **Linux**: Full server-side Swift support for deployment on Linux servers\n\n## Features\n\n- **OpenAI GPT-5 family**: GPT-5, GPT-5-mini, GPT-5-nano with reasoning capabilities\n- **Legacy model support**: GPT-4.1, o3, o4-mini for comparison and migration\n- **Advanced reasoning**: Multiple reasoning effort levels (minimal, low, medium, high)\n- **Responses API**: Modern OpenAI API with better performance and lower costs\n- **Cross-platform compatibility**: Apple platforms + Linux server support\n- **ErrorKit integration**: Localized error messages with typed error handling\n- **Structured response parsing**: JSON Schema support for data extraction\n- **Multi-turn conversations**: Automatic conversation state management\n- **Pricing transparency**: Built-in cost tracking and optimization\n\n## Usage\n\n### Basic Text Generation\n```swift\nimport IntelligenceKit\n\nlet openAI = OpenAI(apiKey: \"your-key\")\n\n// Simple text generation with GPT-5-mini (medium reasoning by default)\nlet response = try await openAI.ask(\n    model: .gpt5Mini(reasoning: .medium),\n    input: \"Write a haiku about coding\"\n)\n\n// Get the response text with proper error handling\nlet text = try response.textMessage()\nprint(text)\n\n// Advanced reasoning with specific effort level\nlet response2 = try await openAI.ask(\n    model: .gpt5(reasoning: .high),\n    instructions: \"You are a helpful coding assistant\",\n    input: \"Explain the benefits of Swift's type system\",\n    verbosity: .high\n)\nlet detailedText = try response2.textMessage()\nprint(detailedText)\n```\n\n### Reasoning and Verbosity Options\n```swift\n// Reasoning effort levels (specified in model)\n.gpt5Mini(reasoning: .minimal)  // Fastest, fewer reasoning tokens\n.gpt5Mini(reasoning: .low)      // Balanced speed and reasoning\n.gpt5Mini(reasoning: .medium)   // Good balance for mini model\n.gpt5(reasoning: .high)         // Most thorough reasoning (full model only)\n\n// Text verbosity levels (as parameter)\nverbosity: .low      // Concise responses\nverbosity: .medium   // Default length\nverbosity: .high     // Detailed explanations\n```\n\n### Multi-turn Conversations\n```swift\n// First message\nlet response1 = try await openAI.ask(\n    model: .gpt5Mini(reasoning: .medium),\n    input: \"What is Swift?\"\n)\nlet firstAnswer = try response1.textMessage()\n\n// Continue conversation (automatic context)\nlet response2 = try await openAI.ask(\n    model: .gpt5Mini(reasoning: .low),\n    input: \"How does it compare to Objective-C?\",\n    previousResponseID: response1.id\n)\nlet followUpAnswer = try response2.textMessage()\n```\n\n### Structured JSON Output\n```swift\n// Define your data structure\nstruct Person: Codable {\n    let name: String\n    let age: Int\n    let occupation: String\n}\n\n// Create JSON schema for structured output\nlet responseFormat = OpenAI.ResponseFormat(\n    name: \"PersonInfo\",\n    description: \"Generate person information\",\n    schema: .object(\n        properties: [\n            \"name\": .string(description: \"Person's full name\"),\n            \"age\": .integer(description: \"Person's age in years\"),\n            \"occupation\": .string(description: \"Person's job title\")\n        ]\n    )\n)\n\n// Request structured JSON response\nlet response = try await openAI.ask(\n    model: .gpt5Mini(reasoning: .low),\n    input: \"Generate a random person with a creative occupation\",\n    responseFormat: responseFormat\n)\n\n// Decode JSON directly into your type\nlet person = try response.jsonMessage(decodedTo: Person.self)\nprint(\"\\(person.name) is \\(person.age) years old and works as a \\(person.occupation)\")\n```\n\n### Image Generation with DALL-E\n```swift\n// Generate an image with DALL-E 3\nlet imageRequest = OpenAI.ImageRequest(\n    prompt: \"A serene Japanese garden with cherry blossoms at sunset\",\n    model: .dallE3,\n    quality: .hd,\n    style: .natural\n)\n\nlet imageResponse = try await openAI.createImage(request: imageRequest)\nif let imageURL = imageResponse.data.first?.url {\n    print(\"Generated image: \\(imageURL)\")\n}\n```\n\n## Dependencies\n\n- [HandySwift](https://github.com/FlineDev/HandySwift) - REST client and utilities\n- [ErrorKit](https://github.com/FlineDev/ErrorKit) - Typed error handling\n\n## Error Handling\n\nAll functions use typed throws (`throws(OpenAI.Error)`) for better error handling. Errors conform to ErrorKit's `Throwable` protocol with localized user-friendly messages:\n\n```swift\ndo {\n    let response = try await openAI.ask(\n        model: .gpt5Mini(reasoning: .medium),\n        input: \"Hello!\"\n    )\n    let message = try response.textMessage()  // Throws if no content\n    print(message)\n} catch {\n    print(error.userFriendlyMessage)  // Localized error message\n    switch error {\n    case .emptyResponse:\n        print(\"No response content received\")\n    case .jsonSchemaDecodingError(let decodingError):\n        print(\"Failed to decode JSON: \\(decodingError)\")\n    case .requestError(let underlyingError):\n        print(\"Request failed: \\(underlyingError)\")\n    }\n}\n```\n\n## Token Usage and Cost Tracking\n\n```swift\nlet response = try await openAI.ask(\n    model: .gpt5Mini(reasoning: .medium),\n    input: \"Explain quantum computing\"\n)\n\n// Access token usage information\nlet usage = response.usage\nprint(\"Input tokens: \\(usage.inputTokens)\")\nprint(\"Output tokens: \\(usage.outputTokens)\")\nprint(\"Total tokens: \\(usage.totalTokens)\")\n\n// Calculate approximate cost (prices are examples)\nlet inputCost = Double(usage.inputTokens) * 0.15 / 1_000_000  // $0.15 per million\nlet outputCost = Double(usage.outputTokens) * 0.60 / 1_000_000  // $0.60 per million\nprint(\"Estimated cost: $\\(String(format: \"%.4f\", inputCost + outputCost))\")\n```\n\n## Cross-Platform Notes\n\n- **Linux Deployment**: Fully supported for server-side Swift applications\n- **API Compatibility**: Identical API surface across all platforms\n\n## Showcase\n\nI extracted this library from my following Indie apps (rate them with 5 stars to thank me!):\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eApp Icon\u003c/th\u003e\n    \u003cth\u003eApp Name \u0026 Description\u003c/th\u003e\n    \u003cth\u003eSupported Platforms\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6476773066?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/TranslateKit.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6476773066?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003eTranslateKit: App Localizer\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Simple drag \u0026 drop translation of String Catalog files with support for multiple translation services \u0026 smart correctness checks.\n    \u003c/td\u003e\n    \u003ctd\u003eMac\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6587583340?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/PleydiaOrganizer.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6587583340?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003ePleydia Organizer: Movie \u0026 Series Renamer\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Simple, fast, and smart media management for your Movie, TV Show and Anime collection.\n    \u003c/td\u003e\n    \u003ctd\u003eMac\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6502914189?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/FreemiumKit.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6502914189?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003eFreemiumKit: In-App Purchases\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Simple In-App Purchases and Subscriptions for Apple Platforms: Automation, Paywalls, A/B Testing, Live Notifications, PPP, and more.\n    \u003c/td\u003e\n    \u003ctd\u003eiPhone, iPad, Mac, Vision\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6480134993?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/FreelanceKit.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6480134993?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003eFreelanceKit: Time Tracking\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Simple \u0026 affordable time tracking with a native experience for all  devices. iCloud sync \u0026 CSV export included.\n    \u003c/td\u003e\n    \u003ctd\u003eiPhone, iPad, Mac, Vision\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6472669260?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/CrossCraft.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6472669260?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003eCrossCraft: Custom Crosswords\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Create themed \u0026 personalized crosswords. Solve them yourself or share them to challenge others.\n    \u003c/td\u003e\n    \u003ctd\u003eiPhone, iPad, Mac, Vision\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6477829138?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/FocusBeats.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6477829138?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003eFocusBeats: Pomodoro + Music\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Deep Focus with proven Pomodoro method \u0026 select Apple Music playlists \u0026 themes. Automatically pauses music during breaks.\n    \u003c/td\u003e\n    \u003ctd\u003eiPhone, iPad, Mac, Vision\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6478062053?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/FlineDev/HandySwift/main/Images/Apps/Posters.webp\" width=\"64\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://apps.apple.com/app/apple-store/id6478062053?pt=549314\u0026ct=github.com\u0026mt=8\"\u003e\n        \u003cstrong\u003ePosters: Discover Movies at Home\u003c/strong\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      Auto-updating \u0026 interactive posters for your home with trailers, showtimes, and links to streaming services.\n    \u003c/td\u003e\n    \u003ctd\u003eVision\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e","funding_links":["https://github.com/sponsors/Jeehut","https://patreon.com/Jeehut","paypal.me/FlineDev"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflinedev%2Fintelligencekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflinedev%2Fintelligencekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflinedev%2Fintelligencekit/lists"}