{"id":22100604,"url":"https://github.com/mrgraversen/replicate-java","last_synced_at":"2025-03-24T01:47:45.303Z","repository":{"id":261221809,"uuid":"865929854","full_name":"MrGraversen/replicate-java","owner":"MrGraversen","description":"Effortlessly integrate Replicate’s powerful AI models with Java 21 + Spring Boot. This project offers fast, modular access to advanced AI features. Perfect for bringing cutting-edge AI into your apps! 🚀","archived":false,"fork":false,"pushed_at":"2024-11-05T10:54:32.000Z","size":92,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-02-05T08:51:35.176Z","etag":null,"topics":["ai","large-language-models","llm","replicate","replicate-ai","text-to-image"],"latest_commit_sha":null,"homepage":"","language":"Java","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/MrGraversen.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}},"created_at":"2024-10-01T11:12:47.000Z","updated_at":"2025-01-11T08:03:38.000Z","dependencies_parsed_at":"2024-11-05T11:49:10.953Z","dependency_job_id":"0a947940-c4a6-486e-94c9-e9433706ad56","html_url":"https://github.com/MrGraversen/replicate-java","commit_stats":null,"previous_names":["mrgraversen/replicate-java"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrGraversen%2Freplicate-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrGraversen%2Freplicate-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrGraversen%2Freplicate-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrGraversen%2Freplicate-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrGraversen","download_url":"https://codeload.github.com/MrGraversen/replicate-java/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195916,"owners_count":20575937,"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","large-language-models","llm","replicate","replicate-ai","text-to-image"],"created_at":"2024-12-01T05:15:03.598Z","updated_at":"2025-03-24T01:47:45.270Z","avatar_url":"https://github.com/MrGraversen.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Replicate AI, powered by Java 21 ☕ \u0026 Spring Boot 3 🍃\n\nWelcome to the [**Replicate AI**](https://replicate.com/) Integration project! 🎉\n\nThis project provides a streamlined Java 21-based framework to effortlessly interact with and create predictions for **Replicate**'s\npowerful AI models. Built with **Spring Boot**, it enables quick and modular access to various AI services, making integration a breeze for\ndevelopers.\n\nThe project allows downloading of **Replicate AI** models' JSONSchemas for requests and responses through the official API, and dynamically\ncreates a Maven module to enable developers to interact with the AI models using strongly typed Java code.\n\nFurthermore, it supports **Spring Boot AutoConfiguration**, allowing efficient and powerful integration with Spring Boot applications to\nenable easy access to **Replicate**'s AI offerings—just add your API key!\n\n## 🚀 Quick Start\n\nThe quickest way to get off the ground is depending on `spring-boot-starter-replicate`. The module, provided an API key to Replicate,\nhandles all configuration of the underlying modules to ensure a smooth start.\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.graversen\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-starter-replicate\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nAdd your Replicate API key to your `application.yml` file.\n\n```yml\nreplicate:\n  token: r8...\n```\n\n... And you're good to go!\n\n## Replicate Models\n\nBy default, this project supports a number of common AI models for text completion using large language models and text-to-image models for\nimage generation. Specifically, the following models are currently supported out of the box:\n\n### Meta Llama 3\n\n* [`meta-llama-3-8b-instruct`](https://replicate.com/meta/meta-llama-3-8b-instruct)\n* [`meta-llama-3-70b-instruct`](https://replicate.com/meta/meta-llama-3-70b-instruct)\n* [`meta-llama-3.1-405b-instruct`](https://replicate.com/meta/meta-llama-3.1-405b-instruct)\n\nFor the Llama 3 family of models, tokenization for text completion is supported by `spring-boot-starter-replicate`, making it easy to\ncreate and maintain stateful conversations.\n\n### Black Forest Labs Flux\n\n* [`flux-dev`](https://replicate.com/black-forest-labs/flux-dev)\n* [`flux-schnell`](https://replicate.com/black-forest-labs/flux-schnell)\n* [`flux-pro`](https://replicate.com/black-forest-labs/flux-pro)\n\n---\n\n\u003e [!TIP]\n\u003e It is possible to build this project to support different AI models that are not included by default for simplicity reasons.\n\u003e Please see the section describing the `replicate-tools` module.\n\n## 📂 Module Overview\n\nBelow is a more focused description of each discrete module of this project.\n\n### `replicate-client`\n\nCore module for handling API requests and responses from **Replicate**. Use this if you only want to create predictions with Java code in\nthe simplest possible manner.\n\n### `replicate-models`\n\nAuto-generated models from **Replicate**’s JSONSchemas, providing strongly typed Java interfaces for AI models. The models supported are\ngenerated using `replicate-tools`. From this repository, the following packages are supported:\n\n* [`default`](https://github.com/MrGraversen/replicate-java/packages/2297525?version=0.0.8-default): Default models as described above.\n* [`llama3`](https://github.com/MrGraversen/replicate-java/packages/2297525?version=0.0.8-llama3): A specialised module consisting only of\n  the Llama 3 family of AI models.\n* [`flux`](https://github.com/MrGraversen/replicate-java/packages/2297525?version=0.0.8-flux): A specialised module consisting only of the\n  Flux family of AI models.\n\n### `replicate-tools`\n\nPython project to interact with **Replicate** API services to get all JSONSchemas of supplied models.\n\n### Example Usage\n\nInstall:\n\n```shell\npython -m pip install --upgrade pip\npip install -r replicate-tools/requirements.txt\n```\n\nRun Python script with your supplied `REPLICATE_MODELS`.\n\n\u003e [!TIP]\n\u003e The models follow a `owner` / `model-name` convention, just fetch it from the Replicate URL.\n\u003e For example: `https://replicate.com/black-forest-labs/flux-dev` → `black-forest-labs/flux-dev`\n\n```shell\nREPLICATE_API_TOKEN=\"r8...\" REPLICATE_MODELS=\"meta/meta-llama-3-8b-instruct,black-forest-labs/flux-dev\" python download_replicate_schemas.py\n```\n\nAfter this, you are able to build the `replicate-models` module using Maven.\n\n```shell\nmvn compile\n```\n\n\u003e [!TIP]\n\u003e If you decide to use AI models that are more complex than simple text completion or text-to-image generators, note that you may depend on\n\u003e just `replicate-client` and `replicate-models` with your custom set of models, to enable easy, strongly typed access to the Replicate API.\n\n### `spring-boot-starter-replicate`\n\nAuto-configures **Replicate** integration, provided an API token. Through this, you will have access to more advanced encapsulations to\ncreate images and manage conversations.\n\n## 📈 Examples\n\n### Example 1 - Conversations with Llama 3\n\n```java\n\n@Slf4j\n@RequiredArgsConstructor\npublic class LlamaConversationExample {\n    private final ConversationFacade conversationFacade;\n\n    /**\n     * Simple example of exchanging one message with meta-llama-3-70b-instruct\n     */\n    public void runExampleOne() {\n        final var conversationOptions = new ConversationOptions(\n                1.25 // temperature\n        );\n\n        final var createConversation = new CreateConversation(\n                \"You are a friendly and witty assistant! Respond in one short sentence only.\", // systemMessage\n                Llama3Models.LLAMA_3_70B_INSTRUCT // meta-llama-3-70b-instruct\n        );\n\n        final var conversation = conversationFacade.create(createConversation, conversationOptions);\n\n        conversationFacade.chat(conversation.getId(), TextMessage.user(\"Introduce yourself to me 😊\")).whenComplete(logConversation());\n        // =\u003e I'm LLaMA, your go-to sidekick for banter, advice, and getting stuff done, with a healthy dose of sarcasm and humor! 😉\n    }\n\n    /**\n     * Example of exchanging a \"deeper\" conversation with meta-llama-3-70b-instruct\n     */\n    public void runExampleTwo() {\n        final var conversationOptions = new ConversationOptions(\n                0.75 // temperature\n        );\n\n        final var createConversation = new CreateConversation(\n                \"You are a calculator app. Respond only with the result of the math query.\", // systemMessage\n                Llama3Models.LLAMA_3_70B_INSTRUCT // meta-llama-3-70b-instruct\n        );\n\n        final var conversation = conversationFacade.create(createConversation, conversationOptions);\n\n        conversationFacade.chat(conversation.getId(), TextMessage.user(\"What is 2 + 2?\")) // =\u003e 4\n                .thenCompose(conversationFacade.chat(TextMessage.user(\"What is 3 * 3?\"))) // =\u003e 9\n                .thenCompose(conversationFacade.chat(TextMessage.user(\"What is seven minus two?\"))) // =\u003e 5\n                .whenComplete(logConversation());\n    }\n\n    private BiConsumer\u003cConversation, Throwable\u003e logConversation() {\n        return (conversation, throwable) -\u003e {\n            if (throwable == null) {\n                log.info(\"{}\", conversation.getConversation());\n            } else {\n                log.error(throwable.getMessage(), throwable);\n            }\n        };\n    }\n}\n```\n\n### Example 2 - Image generation with Flux\n\n```java\n\n@Slf4j\n@RequiredArgsConstructor\npublic class FluxExample {\n    private final ReplicateFacade replicateFacade;\n\n    /**\n     * Create one image using flux-dev\n     */\n    public void runExampleOne() {\n        final var createImagePrediction = new CreateImagePrediction(\n                TextToImagePrompt.portrait(\"A photo of a sheep on a grassy field on a beautiful summer day\"),\n                1, // outputs\n                25, // inferenceSteps\n                null // seed (random)\n        );\n\n        replicateFacade.createPrediction(\n                FluxModels.FLUX_DEV,\n                createImagePrediction\n        );\n    }\n}\n```\n\n---\n\n\u003e [!NOTE]  \n\u003e This project is still in the early stages of development.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgraversen%2Freplicate-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrgraversen%2Freplicate-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgraversen%2Freplicate-java/lists"}