1515import ai .chat2db .server .web .api .controller .ai .azure .client .AzureOpenAIClient ;
1616import ai .chat2db .server .web .api .controller .ai .baichuan .client .BaichuanAIClient ;
1717import ai .chat2db .server .web .api .controller .ai .chat2db .client .Chat2dbAIClient ;
18+ import ai .chat2db .server .web .api .controller .ai .dify .client .DifyChatAIClient ;
1819import ai .chat2db .server .web .api .controller .ai .fastchat .client .FastChatAIClient ;
1920import ai .chat2db .server .web .api .controller .ai .rest .client .RestAIClient ;
2021import ai .chat2db .server .web .api .controller .ai .tongyi .client .TongyiChatAIClient ;
@@ -47,7 +48,7 @@ public class ConfigController {
4748 @ PostMapping ("/system_config" )
4849 public ActionResult systemConfig (@ RequestBody SystemConfigRequest request ) {
4950 SystemConfigParam param = SystemConfigParam .builder ().code (request .getCode ()).content (request .getContent ())
50- .build ();
51+ .build ();
5152 configService .createOrUpdate (param );
5253 if (OpenAIClient .OPENAI_KEY .equals (request .getCode ())) {
5354 OpenAIClient .refresh ();
@@ -72,7 +73,7 @@ public ActionResult addChatGptSystemConfig(@RequestBody AIConfigCreateRequest re
7273 aiSqlSourceEnum = AiSqlSourceEnum .CHAT2DBAI ;
7374 }
7475 SystemConfigParam param = SystemConfigParam .builder ().code (RestAIClient .AI_SQL_SOURCE ).content (sqlSource )
75- .build ();
76+ .build ();
7677 configService .createOrUpdate (param );
7778
7879 switch (Objects .requireNonNull (aiSqlSourceEnum )) {
@@ -103,21 +104,34 @@ public ActionResult addChatGptSystemConfig(@RequestBody AIConfigCreateRequest re
103104 case ZHIPUAI :
104105 saveZhipuChatAIConfig (request );
105106 break ;
107+ case DIFYCHAT :
108+ saveDifyChatAIConfig (request );
109+ break ;
106110 }
107111 return ActionResult .isSuccess ();
108112 }
109113
114+ private void saveDifyChatAIConfig (AIConfigCreateRequest request ) {
115+ SystemConfigParam param = SystemConfigParam .builder ().code (DifyChatAIClient .DIFYCHAT_API_KEY ).content (
116+ request .getApiKey ()).build ();
117+ configService .createOrUpdate (param );
118+ SystemConfigParam hostParam = SystemConfigParam .builder ().code (DifyChatAIClient .DIFYCHAT_HOST ).content (
119+ request .getApiHost ()).build ();
120+ configService .createOrUpdate (hostParam );
121+ DifyChatAIClient .refresh ();
122+ }
123+
110124 /**
111125 * save chat2db ai config
112126 *
113127 * @param request
114128 */
115129 private void saveChat2dbAIConfig (AIConfigCreateRequest request ) {
116130 SystemConfigParam param = SystemConfigParam .builder ().code (Chat2dbAIClient .CHAT2DB_OPENAI_KEY ).content (
117- request .getApiKey ()).build ();
131+ request .getApiKey ()).build ();
118132 configService .createOrUpdate (param );
119133 SystemConfigParam hostParam = SystemConfigParam .builder ().code (Chat2dbAIClient .CHAT2DB_OPENAI_HOST ).content (
120- request .getApiHost ()).build ();
134+ request .getApiHost ()).build ();
121135 configService .createOrUpdate (hostParam );
122136 SystemConfigParam modelParam = SystemConfigParam .builder ().code (Chat2dbAIClient .CHAT2DB_OPENAI_MODEL ).content (
123137 request .getModel ()).build ();
@@ -132,16 +146,16 @@ private void saveChat2dbAIConfig(AIConfigCreateRequest request) {
132146 */
133147 private void saveOpenAIConfig (AIConfigCreateRequest request ) {
134148 SystemConfigParam param = SystemConfigParam .builder ().code (OpenAIClient .OPENAI_KEY ).content (
135- request .getApiKey ()).build ();
149+ request .getApiKey ()).build ();
136150 configService .createOrUpdate (param );
137151 SystemConfigParam hostParam = SystemConfigParam .builder ().code (OpenAIClient .OPENAI_HOST ).content (
138- request .getApiHost ()).build ();
152+ request .getApiHost ()).build ();
139153 configService .createOrUpdate (hostParam );
140154 SystemConfigParam httpProxyHostParam = SystemConfigParam .builder ().code (OpenAIClient .PROXY_HOST ).content (
141- request .getHttpProxyHost ()).build ();
155+ request .getHttpProxyHost ()).build ();
142156 configService .createOrUpdate (httpProxyHostParam );
143157 SystemConfigParam httpProxyPortParam = SystemConfigParam .builder ().code (OpenAIClient .PROXY_PORT ).content (
144- request .getHttpProxyPort ()).build ();
158+ request .getHttpProxyPort ()).build ();
145159 configService .createOrUpdate (httpProxyPortParam );
146160 OpenAIClient .refresh ();
147161 }
@@ -153,10 +167,10 @@ private void saveOpenAIConfig(AIConfigCreateRequest request) {
153167 */
154168 private void saveRestAIConfig (AIConfigCreateRequest request ) {
155169 SystemConfigParam restParam = SystemConfigParam .builder ().code (RestAIClient .REST_AI_URL ).content (
156- request .getApiHost ()).build ();
170+ request .getApiHost ()).build ();
157171 configService .createOrUpdate (restParam );
158172 SystemConfigParam methodParam = SystemConfigParam .builder ().code (RestAIClient .REST_AI_STREAM_OUT ).content (
159- request .getStream ().toString ()).build ();
173+ request .getStream ().toString ()).build ();
160174 configService .createOrUpdate (methodParam );
161175 RestAIClient .refresh ();
162176 }
@@ -168,16 +182,16 @@ private void saveRestAIConfig(AIConfigCreateRequest request) {
168182 */
169183 private void saveAzureAIConfig (AIConfigCreateRequest request ) {
170184 SystemConfigParam apikeyParam = SystemConfigParam .builder ().code (AzureOpenAIClient .AZURE_CHATGPT_API_KEY )
171- .content (
172- request .getApiKey ()).build ();
185+ .content (
186+ request .getApiKey ()).build ();
173187 configService .createOrUpdate (apikeyParam );
174188 SystemConfigParam endpointParam = SystemConfigParam .builder ().code (AzureOpenAIClient .AZURE_CHATGPT_ENDPOINT )
175- .content (
176- request .getApiHost ()).build ();
189+ .content (
190+ request .getApiHost ()).build ();
177191 configService .createOrUpdate (endpointParam );
178192 SystemConfigParam modelParam = SystemConfigParam .builder ().code (AzureOpenAIClient .AZURE_CHATGPT_DEPLOYMENT_ID )
179- .content (
180- request .getModel ()).build ();
193+ .content (
194+ request .getModel ()).build ();
181195 configService .createOrUpdate (modelParam );
182196 AzureOpenAIClient .refresh ();
183197 }
@@ -308,17 +322,17 @@ public DataResult<AIConfig> getChatAiSystemConfig(String aiSqlSource) {
308322 config .setApiKey (Objects .nonNull (apiKey .getData ()) ? apiKey .getData ().getContent () : "" );
309323 config .setApiHost (Objects .nonNull (apiHost .getData ()) ? apiHost .getData ().getContent () : "" );
310324 config .setHttpProxyHost (
311- Objects .nonNull (httpProxyHost .getData ()) ? httpProxyHost .getData ().getContent () : "" );
325+ Objects .nonNull (httpProxyHost .getData ()) ? httpProxyHost .getData ().getContent () : "" );
312326 config .setHttpProxyPort (
313- Objects .nonNull (httpProxyPort .getData ()) ? httpProxyPort .getData ().getContent () : "" );
327+ Objects .nonNull (httpProxyPort .getData ()) ? httpProxyPort .getData ().getContent () : "" );
314328 break ;
315329 case CHAT2DBAI :
316330 DataResult <Config > chat2dbApiKey = configService .find (Chat2dbAIClient .CHAT2DB_OPENAI_KEY );
317331 DataResult <Config > chat2dbApiHost = configService .find (Chat2dbAIClient .CHAT2DB_OPENAI_HOST );
318332 DataResult <Config > chat2dbModel = configService .find (Chat2dbAIClient .CHAT2DB_OPENAI_MODEL );
319333 config .setApiKey (Objects .nonNull (chat2dbApiKey .getData ()) ? chat2dbApiKey .getData ().getContent () : "" );
320334 config .setApiHost (
321- Objects .nonNull (chat2dbApiHost .getData ()) ? chat2dbApiHost .getData ().getContent () : "" );
335+ Objects .nonNull (chat2dbApiHost .getData ()) ? chat2dbApiHost .getData ().getContent () : "" );
322336 config .setModel (Objects .nonNull (chat2dbModel .getData ()) ? chat2dbModel .getData ().getContent () : "" );
323337 break ;
324338 case AZUREAI :
@@ -334,7 +348,7 @@ public DataResult<AIConfig> getChatAiSystemConfig(String aiSqlSource) {
334348 DataResult <Config > restAiHttpMethod = configService .find (RestAIClient .REST_AI_STREAM_OUT );
335349 config .setApiHost (Objects .nonNull (restAiUrl .getData ()) ? restAiUrl .getData ().getContent () : "" );
336350 config .setStream (Objects .nonNull (restAiHttpMethod .getData ()) ? Boolean .valueOf (
337- restAiHttpMethod .getData ().getContent ()) : Boolean .TRUE );
351+ restAiHttpMethod .getData ().getContent ()) : Boolean .TRUE );
338352 break ;
339353 case FASTCHATAI :
340354 DataResult <Config > fastChatApiKey = configService .find (FastChatAIClient .FASTCHAT_API_KEY );
@@ -376,6 +390,12 @@ public DataResult<AIConfig> getChatAiSystemConfig(String aiSqlSource) {
376390 config .setApiHost (Objects .nonNull (zhipuApiHost .getData ()) ? zhipuApiHost .getData ().getContent () : "" );
377391 config .setModel (Objects .nonNull (zhipuModel .getData ()) ? zhipuModel .getData ().getContent () : "" );
378392 break ;
393+ case DIFYCHAT :
394+ DataResult <Config > difyChatApiKey = configService .find (DifyChatAIClient .DIFYCHAT_API_KEY );
395+ DataResult <Config > difyChatApiHost = configService .find (DifyChatAIClient .DIFYCHAT_HOST );
396+ config .setApiKey (Objects .nonNull (difyChatApiKey .getData ()) ? difyChatApiKey .getData ().getContent () : "" );
397+ config .setApiHost (Objects .nonNull (difyChatApiHost .getData ()) ? difyChatApiHost .getData ().getContent () : "" );
398+ break ;
379399 default :
380400 break ;
381401 }
0 commit comments