{"id":28255533,"url":"https://github.com/vicjun22/openai-chat-integration_spring-boot","last_synced_at":"2026-04-11T02:04:08.468Z","repository":{"id":293866809,"uuid":"984973579","full_name":"Vicjun22/openai-chat-integration_spring-boot","owner":"Vicjun22","description":"OpenAI: Chat integration with Spring Boot","archived":false,"fork":false,"pushed_at":"2025-05-19T18:02:07.000Z","size":107,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-27T08:54:39.558Z","etag":null,"topics":["java","maven","openai","springboot","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vicjun22.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-16T20:43:15.000Z","updated_at":"2025-05-19T18:03:58.000Z","dependencies_parsed_at":"2025-05-19T19:23:57.508Z","dependency_job_id":null,"html_url":"https://github.com/Vicjun22/openai-chat-integration_spring-boot","commit_stats":null,"previous_names":["vicjun22/openai-chat_spring-boot","vicjun22/openai-chat-integration_spring-boot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Vicjun22/openai-chat-integration_spring-boot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vicjun22%2Fopenai-chat-integration_spring-boot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vicjun22%2Fopenai-chat-integration_spring-boot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vicjun22%2Fopenai-chat-integration_spring-boot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vicjun22%2Fopenai-chat-integration_spring-boot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vicjun22","download_url":"https://codeload.github.com/Vicjun22/openai-chat-integration_spring-boot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vicjun22%2Fopenai-chat-integration_spring-boot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007167,"owners_count":26084247,"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-10-11T02:00:06.511Z","response_time":55,"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":["java","maven","openai","springboot","tutorial"],"created_at":"2025-05-19T22:13:55.790Z","updated_at":"2025-10-11T12:32:27.526Z","avatar_url":"https://github.com/Vicjun22.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAI: Chat integration with Spring Boot\n\n![Build](https://img.shields.io/badge/build-passing-brightgreen)\n![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.4.5-blue)\n\nThis repository demonstrates how to integrate OpenAI chat functionality into a Spring Boot project.\n\n### 1. Create a Spring Boot Project\n\nFirst, create a new Spring Boot project using your preferred method (e.g., [Spring Initializr](https://start.spring.io/) or an IDE like IntelliJ IDEA or Eclipse). Make sure your project is set up with Maven.\n\n### 2. Add dependencies to the `pom.xml` file:\n\n```xml\n\u003c!--\tSpring Web\t--\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-starter-web\u003c/artifactId\u003e\n\u003c/dependency\u003e\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-starter-test\u003c/artifactId\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n\n\u003c!--\tLombok\t--\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.projectlombok\u003c/groupId\u003e\n    \u003cartifactId\u003elombok\u003c/artifactId\u003e\n    \u003coptional\u003etrue\u003c/optional\u003e\n\u003c/dependency\u003e\n\n\u003c!--\tWebFlux\t--\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-starter-webflux\u003c/artifactId\u003e\n\u003c/dependency\u003e\n\n\u003c!--\tJSON parsing\t--\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.fasterxml.jackson.core\u003c/groupId\u003e\n    \u003cartifactId\u003ejackson-databind\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n\n### 3. Define your secrets in `application.yml`\n\n```yaml\nopenai:\n  api-key: ${OPENAI_TOKEN}\n  assistant:\n    name: ${ASSISTANT_NAME}\n    model: ${ASSISTANT_MODEL}\n    instructions: ${ASSISTANT_INSTRUCTIONS}\n```\n\n### 4. Create an OpenAI configuration class:\n\n```java\n@Configuration\npublic class OpenAiConfig {\n\n    private final String apiKey;\n\n    public OpenAiConfig(@Value(\"${openai.api-key}\") String apiKey) {\n        this.apiKey = apiKey;\n    }\n\n    @Bean\n    public WebClient openAiWebClient() {\n        return WebClient.builder()\n                .baseUrl(\"https://api.openai.com/v1\")\n                .defaultHeader(HttpHeaders.AUTHORIZATION, \"Bearer \" + apiKey)\n                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)\n                .defaultHeader(\"OpenAI-Beta\", \"assistants=v2\")\n                .build();\n    }\n}\n```\n\n\u003chr\u003e\n\nNow that we’ve completed the configuration, we can move on to explaining the available endpoints.\n\n## ⚙️ Assistant Controller\n\n`POST /assistant/new`\n\nSends a request to create a new assistant using the configuration defined in `application.yml`.\n```curl\ncurl --location --request POST 'http://localhost:8080/assistant/new'\n```\n\n**Response:**\n```text\nID: asst_123abc456def...\n```\n\n\u003cbr\u003e\n\n`GET /assistant/{assistantId}`\n\nReturns the details of an existing assistant by ID.\n```curl\ncurl --location 'http://localhost:8080/assistant/asst_js0TkCNlOgIxqt6ir3gGmt2O'\n```\n\n\u003cbr\u003e\n\n`POST /assistant/{assistantId}/upload`\n\nUploads a file and attaches it to the specified assistant.\u003cbr\u003e\nThe file is also stored in a vector store and linked to the assistant for retrieval and search purposes.\n```curl\ncurl --location 'http://localhost:8080/assistant/asst_js0TkCNlOgIxqt6ir3gGmt2O/upload' \\\n--form 'file=@\"C:/Users/Documents/data.json\"'\n```\n\n**Response:**\n```json\n{\n  \"fileId\": \"file_abc123...\",\n  \"vectorStoreId\": \"vs_xyz456...\"\n}\n```\n\n\u003cbr\u003e\n\n`GET /assistant/{assistantId}/files`\n\nLists all files attached to the assistant.\n```curl\ncurl --location 'http://localhost:8080/assistant/asst_js0TkCNlOgIxqt6ir3gGmt2O/files' \\\n--header 'OpenAI-Beta: assistants=v2'\n```\n\n## ⚙️ Thread Controller\n\n`POST /threads/chat`\n\nStarts or continues a conversation thread between the user and an assistant.\u003cbr\u003e\n**If a `threadId` is not provided, a new thread is created.**\u003cbr\u003e\nThe message is added to the thread, the assistant processes it, and the response is returned after execution is complete.\n```curl\ncurl --location 'http://localhost:8080/threads/chat' \\\n--data '{\n    \"assistantId\": \"asst_js0TkCNlOgIxqt6ir3gGmt2O\",\n    \"threadId\": \"thread_rzSQwwxikoALUUlSQ35OIfcM\",\n    \"message\": \"What are the contents of the uploaded file?\"\n}'\n```\n\n**Request:**\n```json\n{\n  \"assistantId\": \"asst_js0TkCNlOgIxqt6ir3gGmt2O\",\n  \"threadId\": \"\",  // Optional: leave empty to create a new thread\n  \"message\": \"What are the contents of the uploaded file?\"\n}\n```\n\n**Response:**\n```json\n{\n  \"threadId\": \"thread_xyz789...\",\n  \"runId\": \"run_abc456...\",\n  \"answer\": \"The file contains a list of user transactions from January 2024...\"\n}\n```\n\n**Behavior:**\n- If `threadId` is omitted or blank, a new thread is automatically created.\n- The message is sent to the assistant, which processes it.\n- The system waits for the assistant’s response before replying to the client.\n\n\u003chr\u003e\n\n## 📁 Project Resources\nThe `resources/assets` directory contains the following files:\n\n- `data.json`:\u003cbr\u003e\nAn example input file containing structured data (in Brazilian Portuguese).\n\n- `PROJECT_OPENAI.postman_collection.json`:\u003cbr\u003e\nA Postman collection with predefined requests to test the API endpoints.\n\n- `instructions.txt`:\u003cbr\u003e\nA file with prompt instructions for the Assistant (written in Brazilian Portuguese).\n\n---\n\n## 🔗 Useful Links\n\n- [Spring Initializr](https://start.spring.io/) - Quickly bootstrap a Spring Boot project.\n- [OpenAI Platform](https://platform.openai.com/docs/overview) - Learn more about OpenAI and its developer platform.\n\n---\n\nFeel free to contribute by submitting pull requests or reporting issues.  \nContributions are welcome! 🚀\n\nCheers,  \nVictor","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicjun22%2Fopenai-chat-integration_spring-boot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicjun22%2Fopenai-chat-integration_spring-boot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicjun22%2Fopenai-chat-integration_spring-boot/lists"}