@@ -32,22 +32,48 @@ public class OpenAiTestConfiguration {
3232
3333 @ Bean
3434 public OpenAiApi openAiApi () {
35- return OpenAiApi .builder ().apiKey (getApiKey ()).build ();
35+ var builder = OpenAiApi .builder ().apiKey (getApiKey ());
36+
37+ String baseUrl = getBaseUrl ();
38+ if (StringUtils .hasText (baseUrl )) {
39+ builder .baseUrl (baseUrl );
40+ }
41+ String completionsPath = getCompletionsPath ();
42+ if (StringUtils .hasText (completionsPath )) {
43+ builder .completionsPath (completionsPath );
44+ }
45+
46+ return builder .build ();
3647 }
3748
3849 @ Bean
3950 public OpenAiImageApi openAiImageApi () {
40- return OpenAiImageApi .builder ().apiKey (getApiKey ()).build ();
51+ var builder = OpenAiImageApi .builder ().apiKey (getApiKey ());
52+ String baseUrl = getBaseUrl ();
53+ if (StringUtils .hasText (baseUrl )) {
54+ builder .baseUrl (baseUrl );
55+ }
56+ return builder .build ();
4157 }
4258
4359 @ Bean
4460 public OpenAiAudioApi openAiAudioApi () {
45- return OpenAiAudioApi .builder ().apiKey (getApiKey ()).build ();
61+ var builder = OpenAiAudioApi .builder ().apiKey (getApiKey ());
62+ String baseUrl = getBaseUrl ();
63+ if (StringUtils .hasText (baseUrl )) {
64+ builder .baseUrl (baseUrl );
65+ }
66+ return builder .build ();
4667 }
4768
4869 @ Bean
4970 public OpenAiModerationApi openAiModerationApi () {
50- return OpenAiModerationApi .builder ().apiKey (getApiKey ()).build ();
71+ var builder = OpenAiModerationApi .builder ().apiKey (getApiKey ());
72+ String baseUrl = getBaseUrl ();
73+ if (StringUtils .hasText (baseUrl )) {
74+ builder .baseUrl (baseUrl );
75+ }
76+ return builder .build ();
5177 }
5278
5379 private ApiKey getApiKey () {
@@ -59,6 +85,22 @@ private ApiKey getApiKey() {
5985 return new SimpleApiKey (apiKey );
6086 }
6187
88+ private String getBaseUrl () {
89+ String baseUrl = System .getenv ("OPENAI_BASE_URL" );
90+ if (StringUtils .hasText (baseUrl )) {
91+ return baseUrl ;
92+ }
93+ return null ;
94+ }
95+
96+ private String getCompletionsPath () {
97+ String path = System .getenv ("OPENAI_COMPLETIONS_PATH" );
98+ if (StringUtils .hasText (path )) {
99+ return path ;
100+ }
101+ return null ;
102+ }
103+
62104 @ Bean
63105 public OpenAiChatModel openAiChatModel (OpenAiApi api ) {
64106 return OpenAiChatModel .builder ()
0 commit comments