{"id":15343640,"url":"https://github.com/kezhenxu94/chatgpt-java","last_synced_at":"2025-04-15T02:37:14.514Z","repository":{"id":114780014,"uuid":"609574012","full_name":"kezhenxu94/chatgpt-java","owner":"kezhenxu94","description":"ChatGPT SDK for Java, CLI, GitHub Actions, demo, etc.","archived":false,"fork":false,"pushed_at":"2024-09-04T04:12:48.000Z","size":151,"stargazers_count":25,"open_issues_count":25,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T15:48:27.457Z","etag":null,"topics":["chatgpt","chatgpt-api","chatgpt-bot","chatgpt-cli","chatgpt-github-action","chatgpt-java","chatgpt-sdk","java"],"latest_commit_sha":null,"homepage":"","language":"Java","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/kezhenxu94.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}},"created_at":"2023-03-04T15:36:43.000Z","updated_at":"2024-09-27T12:20:47.000Z","dependencies_parsed_at":"2023-12-20T17:00:53.782Z","dependency_job_id":"111698e4-1fa4-4106-a74d-b3ed7ccb2c01","html_url":"https://github.com/kezhenxu94/chatgpt-java","commit_stats":{"total_commits":60,"total_committers":1,"mean_commits":60.0,"dds":0.0,"last_synced_commit":"dfa6988775b825b4bf6e24d4b547831328a17378"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kezhenxu94%2Fchatgpt-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kezhenxu94%2Fchatgpt-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kezhenxu94%2Fchatgpt-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kezhenxu94%2Fchatgpt-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kezhenxu94","download_url":"https://codeload.github.com/kezhenxu94/chatgpt-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248982155,"owners_count":21193352,"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":["chatgpt","chatgpt-api","chatgpt-bot","chatgpt-cli","chatgpt-github-action","chatgpt-java","chatgpt-sdk","java"],"created_at":"2024-10-01T10:48:02.231Z","updated_at":"2025-04-15T02:37:14.465Z","avatar_url":"https://github.com/kezhenxu94.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TL;DR;\n\n[Chat with ChatGPT Now](https://github.com/kezhenxu94/chatgpt-java/issues/new?assignees=\u0026labels=question\u0026template=q--.md\u0026title=Q%3A+).\n\n# ChatGPT Java SDK\n\n## Add the dependency\n\n![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fkezhenxu94%2Fchatgpt-java-sdk%2Fmaven-metadata.xml)\n\n### Maven\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.kezhenxu94\u003c/groupId\u003e\n    \u003cartifactId\u003echatgpt-java-sdk\u003c/artifactId\u003e\n    \u003cversion\u003e${chatgpt-java.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```groovy\nimplementation 'io.github.kezhenxu94:chatgpt-java-sdk:${chatgpt-java.version}'\n```\n\n## Usage\n\n```java\npublic class ChatGPTTest {\n    public static void main(String[] args) throws IOException, InterruptedException {\n        final var chatGPT = ChatGPT\n                .builder()\n                .dataPath(Files.createTempDirectory(\"chatgpt\")) // Persist the chat history to a data path\n                .build();\n\n        // Start a new conversation\n        final var conversation = chatGPT.newConversation();\n        System.out.println(conversation.ask(\"What's your name?\").content());\n        // Output: I'm an AI language model developed by OpenAI, and I don't have a name. What can I help you with today?\n        System.out.println(conversation.ask(\"What did I ask you?\").content());\n        // Output: You asked for my name.\n        conversation.save(); // Save the history manually, conversations are saved on shutdown by default.\n\n        final var conversation2 = chatGPT.newConversation(\"You are a software engineer.\");\n        System.out.println(conversation2.ask(\"What's your job?\").content());\n        System.out.println(conversation2.ask(\"What's your day to day work?\").content());\n\n        // Load a conversation by the ID\n        final var conversation3 = chatGPT.loadConversation(conversation.id());\n        conversation3.ask(\"What did I ask you?\");\n        // Should print the same as the first conversation\n    }\n}\n```\n\nA demo usage of ChatGPT Java SDK is the [ChatGPT CLI](#chatgpt-cli), built with Spring Shell and Graalvm.\n\n# ChatGPT CLI\n\n\u003e Who on earth would want to use CLI to interact with ChatGPT? Developers!\n\n## Prerequisites\n\nAn API key from OpenAI platform is required before using the CLI, head\nto [OpenAI Account](https://platform.openai.com/account/api-keys) to create one.\n\n```shell\nexport CHATGPT_API_KEY=\u003cyour-api-key\u003e\n```\n\n## Download the CLI\n\nHead to [Releases](https://github.com/kezhenxu94/chatgpt-java/releases) to download the CLI according to your os.\n\n```shell\nsudo install chatgpt-cli.macos /usr/local/bin/chatgpt\n```\n\n## Running the CLI in Docker\n\n```shell\ndocker run -it --rm -e CHATGPT_API_KEY kezhenxu94/chatgpt-cli\n```\n\n## Usage\n\n### Conversation (Interactive Mode)\n\n`chatgpt-cli` by default runs in interactive mode and the questions in one session is a conversation, so ChatGPT\nremembers\nyour previous questions inside a single conversation, you can use `ask` command to ask ChatGPT any question:\n\n```shell\nchatgpt\n\u003e ask --question 'What is your name?'\n```\n\nOr you can omit `--question` and simply:\n\n```shell\nchatgpt\n\u003e ask \"What is your name?\"\n\u003e ask \"What did I ask you?\"\n# should reply something like \"You asked for my name.\"\n```\n\nBut don't forget to quote the question if it contains spaces.\n\n### One-shot (Non-Interactive Mode)\n\nIf you want to ask ChatGPT a one-shot question, you can pass the `ask` command and the question directly, so ChatGPT\nwill\nexit after it replies your questions:\n\n```shell\nchatgpt ask \"What is your name?\"\n```\n\n# ChatGPT GitHub Action\n\n## Add OpenAI API Key Secret\n\nAdd your OpenAI API key as a secret to your repository.\nGo to `https://github.com/\u003cowner\u003e/\u003crepo\u003e/settings/secrets/actions`, create \"New repository secret\" with the\nname `OPENAI_KEY` and your API key as the value.\n\n## Usage\n\n```yaml\n- name: Setup ChatGPT\n  uses: kezhenxu94/chatgpt-java/chatgpt-cli@v0.11.0\n- name: Answer the question\n  env:\n    CHATGPT_API_KEY: ${{ secrets.OPENAI_KEY }}\n  run: |\n    chatgpt ask \"What is your name?\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkezhenxu94%2Fchatgpt-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkezhenxu94%2Fchatgpt-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkezhenxu94%2Fchatgpt-java/lists"}