{"id":13700435,"url":"https://github.com/flashvayne/chatgpt-spring-boot-starter","last_synced_at":"2025-04-05T12:09:11.132Z","repository":{"id":65508986,"uuid":"580823782","full_name":"flashvayne/chatgpt-spring-boot-starter","owner":"flashvayne","description":"a chatgpt starter based on Openai Official Apis.","archived":false,"fork":false,"pushed_at":"2024-03-02T07:15:25.000Z","size":38,"stargazers_count":225,"open_issues_count":1,"forks_count":55,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T11:11:39.641Z","etag":null,"topics":["chatgpt","image-generation","java","openai","spring-boot","starter"],"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/flashvayne.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":"2022-12-21T14:41:16.000Z","updated_at":"2025-03-08T05:02:21.000Z","dependencies_parsed_at":"2024-03-02T08:24:51.510Z","dependency_job_id":"26a681b2-b9b6-4242-80ee-d1021c96561b","html_url":"https://github.com/flashvayne/chatgpt-spring-boot-starter","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashvayne%2Fchatgpt-spring-boot-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashvayne%2Fchatgpt-spring-boot-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashvayne%2Fchatgpt-spring-boot-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashvayne%2Fchatgpt-spring-boot-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flashvayne","download_url":"https://codeload.github.com/flashvayne/chatgpt-spring-boot-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332612,"owners_count":20921853,"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","image-generation","java","openai","spring-boot","starter"],"created_at":"2024-08-02T20:00:56.196Z","updated_at":"2025-04-05T12:09:11.107Z","avatar_url":"https://github.com/flashvayne.png","language":"Java","funding_links":[],"categories":["动手实践","人工智能"],"sub_categories":[],"readme":"[![Maven central](https://maven-badges.herokuapp.com/maven-central/io.github.flashvayne/chatgpt-spring-boot-starter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.flashvayne/chatgpt-spring-boot-starter)\n\n# chatgpt-spring-boot-starter\nThis starter is based on OpenAi Official Apis. You can use chatgpt in springboot project easily.  \n## Functions:\n+ Chat\n\n  You can chat with ChatGPT using many models. Also, multi message is supported, so you can take a series of messages (including the conversation history) as input , and get a response message.\n\n+ Image generation\n\n  Give a prompt and get generated image(s).\n\n## Usage\n### 1.Add maven dependency.\n```pom\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.flashvayne\u003c/groupId\u003e\n    \u003cartifactId\u003echatgpt-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.5\u003c/version\u003e\n\u003c/dependency\u003e\n```\n### 2.Set chatgpt properties in your application.yml\n\n```yml\nchatgpt:\n  api-key: xxxxxxxxxxx   #api-key. It can be generated here https://platform.openai.com/account/api-keys\n# some more properties(model,max-tokens...etc.) have default values. Also you can config them here. \n```\n### 3.Inject bean ChatgptService anywhere you require it, and invoke its methods.\n#### 3.1 Chat\n\n##### 3.1.1 Single message\n\n```java\n@Autowired\nprivate ChatgptService chatgptService;\n\npublic void test(){\n    String responseMessage = chatgptService.multiChat(Arrays.asList(new MultiChatMessage(\"user\",\"how are you?\")));\n    System.out.print(responseMessage); //\\n\\nAs an AI language model, I don't have feelings, but I'm functioning well. Thank you for asking. How can I assist you today?\n}\n\npublic void test2(){\n    String responseMessage = chatgptService.sendMessage(\"how are you\");\n    System.out.print(responseMessage); //I'm doing well, thank you. How about you?\n}\n```\n##### 3.1.2 Multi message. You can take a series of messages (including the conversation history) as input , and return a response message as output.\n```java\n@Autowired\nprivate ChatgptService chatgptService;\n\npublic void testMultiChat(){\n    List\u003cMultiChatMessage\u003e messages = Arrays.asList(\n            new MultiChatMessage(\"system\",\"You are a helpful assistant.\"),\n            new MultiChatMessage(\"user\",\"Who won the world series in 2020?\"),\n            new MultiChatMessage(\"assistant\",\"The Los Angeles Dodgers won the World Series in 2020.\"),\n            new MultiChatMessage(\"user\",\"Where was it played?\"));\n    String responseMessage = chatgptService.multiChat(messages);\n    System.out.print(responseMessage); //The 2020 World Series was played at Globe Life Field in Arlington, Texas.\n}\n```\n+ Tips:\n\t+ Messages must be an array of message objects, where each object has a role (either \"system\", \"user\", or \"assistant\") and content (the content of the message). Conversations can be as short as 1 message or fill many pages.\n\t+ The system message helps set the behavior of the assistant. In the example above, the assistant was instructed with \"You are a helpful assistant.\" \n\t+ The user messages help instruct the assistant. They can be generated by the end users of an application, or set by a developer as an instruction.\n\t+ The assistant messages help store prior responses. They can also be written by a developer to help give examples of desired behavior.\n\t  For more details, please refer to [chat format](https://platform.openai.com/docs/guides/chat/introduction)\n\t\n\n#### 3.2 Image generation\n```java\n@Autowired\nprivate ChatgptService chatgptService;\n\npublic void testImage(){\n    String imageUrl = chatgptService.imageGenerate(\"A cute baby sea otter\");\n    System.out.print(imageUrl); //https://oaidalleapip.......\n}\n\npublic void testImageList(){\n    List\u003cString\u003e images = chatgptService.imageGenerate(\"A cute baby sea otter\", 2, ImageSize.SMALL, ImageFormat.URL);\n    System.out.print(images.toString());//[\"https://oaidalleapipr.....ZwA%3D\",\"https://oaidalleapipr....RE0%3D\"]\n}\n```\n\n## Demo project：\n[demo-chatgpt-spring-boot-starter](https://github.com/flashvayne/demo-chatgpt-spring-boot-starter)\n\n# Author Info\nEmail: flashvayne@gmail.com\n\nBlog: https://vayne.cc\n\n# Acknowledgments\n\nThanks to JetBrains for their support of this project. They provided JetBrains Development Tool lisences for us.\n\n![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashvayne%2Fchatgpt-spring-boot-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflashvayne%2Fchatgpt-spring-boot-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashvayne%2Fchatgpt-spring-boot-starter/lists"}