์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- OS
- dfs
- ๊ตฌํ
- thymeleaf
- ๋ฌธ์์ด
- ์๋ฎฌ๋ ์ด์
- dynamic debugging
- web
- ๋ถํ ์ ๋ณต
- Spring
- ์ฌ๊ท
- DP
- ์ฐ์ ์์ ํ
- ๋ฐ์ดํฌ์คํธ๋ผ
- Reversing
- ๋งต
- ๋ฐฑํธ๋ํน
- ์ต๋จ ๊ฒฝ๋ก
- CVE
- ๊ทธ๋ฆฌ๋
- error
- ์์ ์ ๋ ฌ
- ์ด๋ถ ํ์
- JPA
- ์คํ
- java
- GCP
- ๋์ ํฉ
- c++
- BFS
- Today
- Total
hades
[Spring] ์คํ๋ง AI ๋ณธ๋ฌธ
๋ณธ ๊ธ์ ํ๋ก์ ํธ๋ฅผ ์งํํ๋ฉด์, AI์ ์ง๋ฌธ์ ํ๊ณ ์๋ต์ ๋ฐ์์ผ ํ๋ ์๋น์ค๋ฅผ ๊ตฌํํ๊ธฐ ์ํด AI api๋ฅผ ํ์ตํ๋ฉด์ ์์ฑํ๋ ๊ธ์ด๋ค. Spring์์๋ AI๋ฅผ ๋งค์ฐ ์ฝ๊ฒ ์ง์ํด์ฃผ๋ dependency๊ฐ ์๋ค. ์ ํ๋ธ์ ๋งํฌ๋ ํ์ํ๊ธฐ ๋๋ฌธ์ ๊ฐ์ ๊ตฌ๊ธ ์๋น์ค์ธ Gemini AI๋ฅผ ์ฌ์ฉํ๊ธฐ๋ก ํ๋ค.
์ฒ์, build.gradle์์ Edit Starters๋ก ์๋์ ๊ฐ์ด Gemini AI๋ฅผ ์ถ๊ฐํ๊ณ ํ๋ค.
ํ์ง๋ง, dependency๊ฐ ์ธ์๋์ง ์๊ณ , ๋นจ๊ฐ์ค ์ฒ์ง๊ฐ ๋์๋ค. ์บ์ ์ญ์ , ์ฌ๋น๋ ๋ฑ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ ์๋ํด๋ณด์์ง๋ง ํด๊ฒฐํ ์ ์์๋ค. (๊น์ ๋นก์นจ)
ํน์๋ ํด์ Spring Initilizr๋ฅผ ์ด์ฉํ์ฌ Gemini๋ฅผ ์ถ๊ฐํ ์๋ก์ด ํ๋ก์ ํธ๋ฅผ ๋ง๋ค๊ณ , build.gradle์ ํ์ธํด๋ณด์๋ค.
์๋กญ๊ฒ ๋ง๋ ํ๋ก์ ํธ์๋ ์ด์ ์ ์์๋ ๋ถ๋ถ๊ณผ ๋ค๋ฅธ ๋ถ๋ถ์ด ์์๋ค. ๊ทธ ๋ถ๋ถ๋ค์ ๋ค์๊ณผ ๊ฐ๋ค.
ext {
set('springAiVersion', "1.0.0-M1")
}
dependencyManagement {
imports {
mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}" // edit starters๋ก ์ถ๊ฐํ์ ๋๋ mavenBom "org.springframework.ai:spring-ai-bom:$springAiVersion" ์์
}
}
${springAiVersion}์ ์ ๋ฌํด์ฃผ์ด์ผ ํ๋๋ฐ, ์ ๋ฌํด์ฃผ์ง ๋ชปํด์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ ๊ฒ์ด์๋ค. ์ ์ฝ๋๋ฅผ ์ ๋๋ก ๋ฃ์ด์ฃผ๋ฉด, ๋นจ๊ฐ์ค์ด ๋ง๋ํ๊ฒ ์ฌ๋ผ์ง๋ค. (ํธ์)
build๊ฐ ์ฑ๊ณต์ ์ผ๋ก ๋์์ผ๋ฉด, application.yml์ ์๋ ๋ถ๋ถ์ ์ถ๊ฐํด์ผ ํ๋ค.
Spring:
ai:
vertex:
ai:
gemini:
project-id: YOUR_PROJECT_ID
location: asia-northeast3
์ถ๊ฐ๊ฐ ์๋ฃ๋์์ผ๋ฉด, ์๋์ ๊ฐ์ด ๋งค์ฐ ๊ฐ๋จํ๊ฒ ์ง๋ฌธ์ ์ฃผ๊ณ ์๋ต์ ๋ฐ์ ์ ์๋ค.
@RequestMapping("/api")
@RestController
@RequiredArgsConstructor
public class ChatController {
private final VertexAiGeminiChatModel vertexAiGeminiChatModel;
@GetMapping("/chat")
public String chat(@RequestBody String message) {
String vertexAiGeminiResponse = vertexAiGeminiChatModel.call(message);
System.out.println("vertexAiGeminiResponse = " + vertexAiGeminiResponse);
return vertexAiGeminiResponse;
}
}
์ด์ http๋ฅผ ์ด์ฉํ์ฌ ์๋ต์ ๋ณด๋ด๋ฉด ๋์ด ๋ ๊ฒ ๊ฐ์๋ค.
###
GET http://localhost:8080/api/chat
{
"message" : "๊ธฐ๋ถ์ด ์ฐ์ธํ ๋ ์ฌ๋๋ค์ด ๋ง์ด ๋จน์ ๋ฐฐ๋ฌ ์์์ ๊ตฌ์ฒด์ ์ผ๋ก 5๊ฐ๋ง ๋งํด์ค. ์ด๋ฆ ์ธ์๋ ์๋ฌด ๊ฒ๋ ๋งํ์ง๋ง."
}
###
์ค๋ฅ๊ฐ ๋ฐ์ํ์๊ณ , ์๋ ๋งํฌ์ ์ ๋ฆฌํด๋์๋ค.
https://hades1.tistory.com/138
[Google Cloud] Your default credentials were not found
๐ ์๋ฌCaused by: java.io.IOException: Your default credentials were not found. To set up Application Default Credentials for your environment, see https://cloud.google.com/docs/authentication/external/set-up-adc ๐ ๋ถ์Google
hades1.tistory.com
์ ์ด์ , ๊ณ์ ๋ฑ๋ก๋ ์ ๋๋ก ํ์ผ๋ ์ด์ ๋์๋~ ๊ธฐ๋ํ์ง๋ง, ์ด๋ฆผ๋ ์๋ค.
https://hades1.tistory.com/139
[Google Cloud] has not been used in project before or it is disabled.
๐ ์๋ฌCaused by: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Vertex AI API has not been used in project before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/aiplatform.googleapis.com/overview?project
hades1.tistory.com
๊ณ์ ๋ฑ๋ก, ๊ฒฐ์ ์๋จ ๋ฑ๋ก์ผ๋ก API ํ์ฑํ๋ฅผ ๋ชจ๋ ์ํค๊ณ , http ์์ฒญ์ ๋ณด๋ด๋ฉด, ์๋์ ๊ฐ์ด ๊ฒฐ๊ณผ๊ฐ ๋งค์ฐ ์ ๋์ค๋ ๊ฒ์ ์ ์ ์๋ค.
'๐๐ปโโ๏ธ ๊ธฐ๋ณธํ๋ จ > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Thymeleaf] ๋ฐ๋ณต๋ฌธ ์ฌ์ฉ ์ ๋ณ์ ์ฌ์ฉ ์ฃผ์ (0) | 2024.08.20 |
---|---|
[Spring] ๊ฒฝ๋ก ์ค์ ์ ๋์๋ฌธ์ ๊ตฌ๋ถ์ ์ค์์ฑ (0) | 2024.08.19 |
[Spring] ํ์ผ ์ ๋ก๋ (0) | 2024.08.13 |
[Spring] redirect ๊ฒฝ๋ก ์ค์ ์ ๋ฌธ์ ์ฌ์ฉ ์ฃผ์ (0) | 2024.08.12 |
[Thymeleaf] ํ ์คํธ ๋ฆฌํฐ๋ด (0) | 2024.08.05 |