Skip to content

Commit

Permalink
feat : api 호출을 수행할 클라이언트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaehee committed May 14, 2023
1 parent d109e85 commit 406d468
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.taehee.bot.global.config;

import feign.RequestInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
Expand All @@ -10,4 +12,15 @@ public class OpenFeignClientConfig {

@Value("${openai.api-key}")
private String apiKey;

@Value("${openai.model}")
private String model;

@Value("${openai.role}")
private String role;

@Bean
public RequestInterceptor apiKeyInterceptor() {
return requestTemplate -> requestTemplate.header("Authorization", apiKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.taehee.bot.global.feign.openai;

import com.taehee.bot.global.config.OpenFeignClientConfig;
import com.taehee.bot.global.feign.openai.dto.request.OpenAiRequest;
import com.taehee.bot.global.feign.openai.dto.response.OpenAiResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "OpenAiChatClient", url = "${openai.url}", configuration = OpenFeignClientConfig.class)
public interface OpenAiChatClient {
@PostMapping
OpenAiResponse call(@RequestBody OpenAiRequest openAiRequest);
}

0 comments on commit 406d468

Please sign in to comment.