본문 바로가기
OpenSource/Spring Boot

1) ENS Project - Spring Boot + LLM(Open ai 적용 해보기)

by 태하팍 2024. 8. 17.
반응형

2024.05.20 - [A.I/RAG] - ai? 맨땅에 헤딩 -6(langChain) : 간단 daum news로 RAG 실습

 

2024.05.13 - [A.I/RAG] - ai? 맨땅에 헤딩 -5(langChain) : langsmith 셋팅 및 tracing해보기!!

2024.04.29 - [A.I/RAG] - ai? 맨땅에 헤딩 -4(langChain): vector DB 간단 사용!

2024.04.26 - [A.I/RAG] - ai? 맨땅에 헤딩 -3(langChain) : 주요 컴포넌트 체크!

2024.04.24 - [A.I/RAG] - ai? 맨땅에 헤딩 -2(langChain) : 튜토리얼 따라해보기!

2024.04.19 - [A.I/RAG] - ai? 맨땅에 헤딩 -1(langChain) : ai와 공생하기!

기존에 python으로 langChain을 따라해보았는데 Spring Boot 진영에도 진작에 나왔었는데
해볼까 말까 하다가 이번 주말에는 해보기로 마음 먹었습니다. ㅋㅋ 
또한 Spring Boot를 사용하는데 파이썬쪽 호출하기가 귀찮기도하고 Java에서 함께 코딩하면 더 좋을것 같습니다.
단, 파이썬과 비교했을 때 코딩은 쉬운지 관련 라이브러리는 쉬운지 등등 안해봐도 알것 같지만 일단 해보겠습니다ㅋㅋㅋ

implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'

일단 위의 lib를 추가하면 오류가 빵빵 터지는군요;;
오류를 보니 Open AI 관련 셋팅을 해줘야하나봅니다. 
    ㄴ application.yml에 open ai api-key를 세팅해주면 오류가 나지 않습니다 ㅎㅎ

spring:
  application:
    name: taehaPark
  ai:
    openai:
      api-key: sk-proj-블라블라
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-08-17T20:11:59.476+09:00 ERROR 12608 --- [EasyNaverStore] [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openAiChatModel' defined in class path resource [org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.class]: Failed to instantiate [org.springframework.ai.openai.OpenAiChatModel]: Factory method 'openAiChatModel' threw exception with message: OpenAI API key must be set
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.11.jar:6.1.11]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.11.jar:6.1.11]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.2.jar:3.3.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.2.jar:3.3.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.2.jar:3.3.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.2.jar:3.3.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.2.jar:3.3.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.2.jar:3.3.2]
	at com.easy.nstore.easynaverstore.EasyNaverStoreApplication.main(EasyNaverStoreApplication.java:10) ~[main/:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.2.jar:3.3.2]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ai.openai.OpenAiChatModel]: Factory method 'openAiChatModel' threw exception with message: OpenAI API key must be set
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178) ~[spring-beans-6.1.11.jar:6.1.11]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.11.jar:6.1.11]
	... 22 common frames omitted
Caused by: java.lang.IllegalArgumentException: OpenAI API key must be set
	at org.springframework.util.Assert.hasText(Assert.java:240) ~[spring-core-6.1.11.jar:6.1.11]
	at org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration.openAiApi(OpenAiAutoConfiguration.java:105) ~[spring-ai-spring-boot-autoconfigure-1.0.0-M1.jar:1.0.0-M1]
	at org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration.openAiChatModel(OpenAiAutoConfiguration.java:69) ~[spring-ai-spring-boot-autoconfigure-1.0.0-M1.jar:1.0.0-M1]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146) ~[spring-beans-6.1.11.jar:6.1.11]
	... 23 common frames omitted

우선 아래를 읽어보고~ 다음 포스팅에서 뵙겠습니다:)

https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html

재밌겠다 ㅋㅋ 

반응형