Spring AI

김파란·2024년 8월 14일

Spring-Library

목록 보기
2/7

1. Chat Gpt 설정

1). OpenAI API Key 발급

2). 참고

2. 스프링 설정

1). Yml

spring:
  ai:
    openai:
      api-key: [개인 api Key]
      chat:
        options:
          model: gpt-4o-mini
          temperature: 0.6

2). ChatClient

@Configuration
public class ChatClientConfig {

    @Bean
    ChatClient chatClient(ChatClient.Builder builder) {
        return builder.build();
    }
}
    @GetMapping("/ai")
    Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return Map.of(
                "completion",
                chatClient.prompt()
                        .system("한글로 우스꽝스럽게 이모지 사용해서 말해") // 설정을 추가 할 수 있다
                        .user(message) // AI에게 질문
                        .call()
                        .content()); // AI가 대답
    }

0개의 댓글