{"id":22599546,"url":"https://github.com/alexcheng1982/llm-openapi-function-spring-ai-generator","last_synced_at":"2025-03-28T19:47:04.680Z","repository":{"id":230335951,"uuid":"779109686","full_name":"alexcheng1982/llm-openapi-function-spring-ai-generator","owner":"alexcheng1982","description":"Generate Spring AI functions from OpenAPI spec","archived":false,"fork":false,"pushed_at":"2024-03-29T07:06:49.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-02T23:06:51.676Z","etag":null,"topics":["ai","llm","openapi","openapi-generator","spring","spring-ai"],"latest_commit_sha":null,"homepage":"","language":"Mustache","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexcheng1982.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-03-29T04:02:08.000Z","updated_at":"2024-03-29T08:19:45.000Z","dependencies_parsed_at":"2024-03-29T05:22:11.864Z","dependency_job_id":"1870d718-b4d3-48ad-8834-9701298956bf","html_url":"https://github.com/alexcheng1982/llm-openapi-function-spring-ai-generator","commit_stats":null,"previous_names":["alexcheng1982/llm-openapi-function-spring-ai-generator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcheng1982%2Fllm-openapi-function-spring-ai-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcheng1982%2Fllm-openapi-function-spring-ai-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcheng1982%2Fllm-openapi-function-spring-ai-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcheng1982%2Fllm-openapi-function-spring-ai-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexcheng1982","download_url":"https://codeload.github.com/alexcheng1982/llm-openapi-function-spring-ai-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246093100,"owners_count":20722395,"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","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","llm","openapi","openapi-generator","spring","spring-ai"],"created_at":"2024-12-08T11:10:00.563Z","updated_at":"2025-03-28T19:47:04.661Z","avatar_url":"https://github.com/alexcheng1982.png","language":"Mustache","readme":"# OpenAPI Generator for Spring AI Functions\n\n[![build](https://github.com/alexcheng1982/llm-openapi-function-spring-ai-generator/actions/workflows/build.yaml/badge.svg)](https://github.com/alexcheng1982/llm-openapi-function-spring-ai-generator/actions/workflows/build.yaml)\n![Maven Central Version](https://img.shields.io/maven-central/v/io.github.alexcheng1982/openapi-function-spring-ai-generator)\n\nGenerate Spring\nAI [functions](https://docs.spring.io/spring-ai/reference/api/functions.html)\nfrom OpenAPI spec to\nbe used with LLMs. Connect existing APIs with LLMs.\n\nEach OpenAPI operation will be converted into a `Function` and register to\nSpring context.\n\n`native` library is used to minimize external dependencies.\n\nSee [example](example).\n\n## Code Generation\n\nSee [pom.xml](example/pom.xml) of the example. Add the custom generator as a\ndependency of OpenAPI Generator Maven plugin.\n\n```xml\n\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.alexcheng1982\u003c/groupId\u003e\n  \u003cartifactId\u003eopenapi-function-spring-ai-generator\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nFor each API defined in OpenAPI spec, a Spring `Configuration` will be\ngenerated. For each operation, the generator will generate:\n\n* A record for request type.\n* A record for response type.\n* A bean of `Function` to invoke the corresponding operation.\n\nSee the sample configuration below.\n\n```java\n\n@Configuration\npublic class UniversitiesApiSpringAiFunctionConfiguration {\n\n  public record Request_searchUniversities(String country, Integer limit) {\n\n  }\n\n  public record Response_searchUniversities(List\u003cUniversity\u003e value) {\n\n  }\n\n  @Bean\n  @Description(\"Search universities\")\n  public Function\u003cRequest_searchUniversities, Response_searchUniversities\u003e searchUniversities(\n      UniversitiesApi apiInvoker) {\n    return (request) -\u003e {\n      try {\n        return new Response_searchUniversities(\n            apiInvoker.searchUniversities(request.country(), request.limit()));\n      } catch (ApiException e) {\n        throw new RuntimeException(e);\n      }\n    };\n  }\n}\n```\n\n## Use Generated Client\n\nTo use the generated OpenAPI client in Spring AI:\n\n1. Add the library into your project.\n\n2. Import the `Configuration` or use component scanning.\n\n```java\n@Import({\n    UniversitiesApiSpringAiFunctionConfiguration.class\n})\n```\n\n3. Declare an API bean.\n\n```java\n\n@Bean\npublic UniversitiesApi universitiesApi() {\n  return new UniversitiesApi();\n}\n```\n\n4. Use the function in Spring AI.\n\nSee [here](https://docs.spring.io/spring-ai/reference/api/clients/functions/openai-chat-functions.html)\nfor a guide of how to use functions with OpenAI.\n\n`searchUniversities` is the name of an operation defined in the OpenAPI spec,\nwhich is also the name of function to call.\n\n```java\nOpenAiChatClient chatClient = ...\n\nUserMessage userMessage = new UserMessage(\n    \"Find 10 universities in United Kingdom, output the name and website in CSV format.\");\n\nChatResponse response = chatClient.call(new Prompt(List.of(userMessage),\n    OpenAiChatOptions.builder().withFunction(\"searchUniversities\")\n        .build())); // (1) Enable the function\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcheng1982%2Fllm-openapi-function-spring-ai-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexcheng1982%2Fllm-openapi-function-spring-ai-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcheng1982%2Fllm-openapi-function-spring-ai-generator/lists"}