{"id":22021914,"url":"https://github.com/functioncalling/functioncalling","last_synced_at":"2025-12-11T22:54:52.207Z","repository":{"id":251519907,"uuid":"799788588","full_name":"FunctionCalling/FunctionCalling","owner":"FunctionCalling","description":"A Swift macro that allows you to call your function from Function Calling.","archived":false,"fork":false,"pushed_at":"2025-11-18T02:00:21.000Z","size":102,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-18T04:05:16.162Z","etag":null,"topics":["anthropic","chatgpt","function-calling","gemini","swift"],"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/FunctionCalling.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}},"created_at":"2024-05-13T05:27:15.000Z","updated_at":"2025-11-18T02:00:14.000Z","dependencies_parsed_at":"2024-10-24T18:07:20.518Z","dependency_job_id":"04480d5b-8aff-4176-ac64-a8fc6650f4c7","html_url":"https://github.com/FunctionCalling/FunctionCalling","commit_stats":null,"previous_names":["fumito-ito/functioncalling"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/FunctionCalling/FunctionCalling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FunctionCalling%2FFunctionCalling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FunctionCalling%2FFunctionCalling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FunctionCalling%2FFunctionCalling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FunctionCalling%2FFunctionCalling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FunctionCalling","download_url":"https://codeload.github.com/FunctionCalling/FunctionCalling/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FunctionCalling%2FFunctionCalling/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27571843,"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-12-07T02:00:07.896Z","response_time":53,"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":["anthropic","chatgpt","function-calling","gemini","swift"],"created_at":"2024-11-30T06:16:17.595Z","updated_at":"2025-12-11T22:54:52.168Z","avatar_url":"https://github.com/FunctionCalling.png","language":"Swift","readme":"# FunctionCalling macro\n\nA Swift macro that allows you to call your function from Function Calling.\n\n## Usage\n\nThis macro consists of a combination of `@FunctionCalling` and `@CallableFunction`. Decorate any function within a struct or class marked with `@FunctionCalling` using `@CallableFunction`.\n\n```swift\n@FunctionCalling(service: .claude)\nstruct MyFunctionTools: ToolContainer {\n    @CallableFunction\n    /// Get the current stock price for a given ticker symbol\n    ///\n    /// - Parameter: The stock ticker symbol, e.g. AAPL for Apple Inc.\n    func getStockPrice(ticker: String) async throws -\u003e String {\n        // code to return stock price of passed ticker\n    }\n}\n```\n\nThat’s it! The macro will generate code like the following:\n\n```swift\nextension MyFunctionTools: ToolContainer {\n    func execute(methodName: String, parameters: [String: Any]) async -\u003e String {\n        do {\n            switch methodName {\n            case \"getStockPrice\":\n                let ticker = parameters[\"ticker\"] as! String\n                return try await getStockPrice(\n                    ticker: ticker\n                ).description\n            default:\n                throw FunctionCallingError.unknownFunctionCalled\n            }\n        } catch let error {\n            return error.localizedDescription\n        }\n    }\n\n    var allTools: [Tool]? {\n        guard let data = allToolsJSONString.replacingOccurrences(of: \"\\n\", with: \"\").data(using: .utf8) else {\n            return nil\n        }\n\n        return try? service.decoder.decode([Tool].self, from: data)\n    }\n}\n```\n\nBy using the `execute` function, you can easily call external functions from responses returned by APIs like [Anthropic Claude](https://www.anthropic.com/claude).\nAdditionally, by using the JSON string returned by `allTools`, you can easily use Function Calling with third-party libraries that call LLM services.\n\n## Known Issue\n\nOnly the following types are supported for the arguments and return values of functions annotated with `@CallableFunction`:\n\n- `String`\n- `Character`\n- `Int`\n- `Int8`\n- `Int16`\n- `Int32`\n- `Int64`\n- `UInt`\n- `UInt8`\n- `UInt16`\n- `UInt32`\n- `UInt64`\n- `Double`\n- `Float`\n- `Bool`\n- `Array of above`\n\n## Supporting Services\n\nCurrently, the generated `allTools` is available for the follwing services. \n\n-  [Anthropic Claude](https://www.anthropic.com/claude)\n- [ChatGPT](http://chatgpt.com)\n- [Llama](http://llama-api.com)\n- [Gemini](https://ai.google.dev/gemini-api)\n\nIf there are other services you would like to see supported, please create an issue or submit a pull request.\n\n## Installation\n\nTo use the `FunctionCalling` macro in a SwiftPM project, add the following line to the dependencies in your Package.swift file:\n\n```swift\n.package(url: \"https://github.com/FunctionCalling/FunctionCalling\", from: \"0.4.0\"),\n```\n\nInclude \"FunctionCalling\" as a dependency for your executable target:\n\n```swift\n.target(name: \"\u003ctarget\u003e\", dependencies: [\n    .product(name: \"FunctionCalling\", package: \"FunctionCalling\"),\n]),\n```\n\nFinally, add `import FunctionCalling` to your source code.\n\n## Why ?\n\nFunction Calling is a mechanism for presenting callable external functions to services like Anthropic Claude. For example, in Anthropic Claude, you add the following JSON to an API call:\n\n```json\n\"tools\": [\n  {\n    \"name\": \"get_stock_price\",\n    \"description\": \"Get the current stock price for a given ticker symbol.\",\n    \"input_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"ticker\": {\n          \"type\": \"string\",\n          \"description\": \"The stock ticker symbol, e.g. AAPL for Apple Inc.\"\n        }\n      },\n      \"required\": [\"ticker\"]\n    }\n  }\n]\n```\n\nThis enables Anthropic Claude to call this function. For example, it might instruct a function call with the following response:\n\n```json\n[\n  {\n    \"type\": \"tool_use\",\n    \"id\": \"toolu_01D7FLrfh4GYq7yT1ULFeyMV\",\n    \"name\": \"get_stock_price\",\n    \"input\": { \"ticker\": \"^GSPC\" }\n  }\n]\n```\n\nHowever, converting functions written in Swift into a JSON string usable for Function Calling is not easy and often requires tedious manual work.\nThis macro makes a vast number of functions written in Swift available for Function Calling with just two annotations.\n\n## LICENSE\n\n[The MIT License](https://opensource.org/license/mit)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunctioncalling%2Ffunctioncalling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunctioncalling%2Ffunctioncalling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunctioncalling%2Ffunctioncalling/lists"}