diff --git a/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java b/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java index fe2acbb6a2..72f84da4c5 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java @@ -19,7 +19,6 @@ package org.dinky.controller; -import cn.dev33.satoken.annotation.SaIgnore; import org.dinky.data.dto.SuggestionDTO; import org.dinky.data.enums.Status; import org.dinky.data.result.Result; @@ -34,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController; import cn.dev33.satoken.annotation.SaCheckLogin; +import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -83,5 +83,4 @@ public Result buildSuggestionsByOpenAi(@RequestBody SuggestionDTO sugges return Result.succeed(suggestionService.buildSuggestionsByOpenAi(suggestionDTO), Status.SUCCESS); } - } diff --git a/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionConfig.java b/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionConfig.java index d6743ade9a..50ea363d21 100644 --- a/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionConfig.java +++ b/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionConfig.java @@ -1,3 +1,22 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package org.dinky.service.openai; import lombok.Data; @@ -8,6 +27,4 @@ public class OpenAISuggestionConfig { private String apiKey; private String model; private final String baseUrl = "https://vendor-a-api.com/openai"; - - } diff --git a/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionService.java b/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionService.java index e0429128a2..04ca1c43f7 100644 --- a/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionService.java +++ b/dinky-admin/src/main/java/org/dinky/service/openai/OpenAISuggestionService.java @@ -1,10 +1,29 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package org.dinky.service.openai; import org.dinky.data.dto.SuggestionDTO; /** * OpenAI suggestion service - Manufacturer + * Manufacturer */ public interface OpenAISuggestionService { @@ -14,5 +33,5 @@ public interface OpenAISuggestionService { * @param suggestionDTO suggestionDTO * @return suggestions list */ - String getSuggestions(SuggestionDTO suggestionDTO) ; + String getSuggestions(SuggestionDTO suggestionDTO); } diff --git a/dinky-admin/src/main/java/org/dinky/service/openai/VendorAAdapter.java b/dinky-admin/src/main/java/org/dinky/service/openai/VendorAAdapter.java index b0b5a30a0b..4c8104c443 100644 --- a/dinky-admin/src/main/java/org/dinky/service/openai/VendorAAdapter.java +++ b/dinky-admin/src/main/java/org/dinky/service/openai/VendorAAdapter.java @@ -1,9 +1,28 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package org.dinky.service.openai; -import lombok.RequiredArgsConstructor; import org.dinky.data.dto.SuggestionDTO; import org.dinky.data.exception.BusException; import org.dinky.data.model.SystemConfiguration; + import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; @@ -14,11 +33,12 @@ import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestTemplate; +import lombok.RequiredArgsConstructor; + @RequiredArgsConstructor @Service public class VendorAAdapter implements OpenAISuggestionService { - /** * get suggestions for editor * @@ -29,22 +49,26 @@ public class VendorAAdapter implements OpenAISuggestionService { public String getSuggestions(SuggestionDTO suggestionDTO) { SystemConfiguration systemConfiguration = SystemConfiguration.getInstances(); if (!systemConfiguration.getEnableOpenAI().getValue()) { - return "OpenAI is not enabled,if you want to use OpenAI,please enable it in the system configuration."; + return "OpenAI is not enabled,if you want to use OpenAI,please enable it in the system configuration."; } HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", "Bearer " + systemConfiguration.getOpenAiKey().getValue()); + headers.set( + "Authorization", "Bearer " + systemConfiguration.getOpenAiKey().getValue()); MultiValueMap params = new LinkedMultiValueMap<>(); params.add("prompt", suggestionDTO.getSqlStatement()); params.add("model", systemConfiguration.getOpenaiModelType().getValue()); - params.add("max_tokens", String.valueOf(systemConfiguration.getOpenaiMaxTokens().getValue())); + params.add( + "max_tokens", + String.valueOf(systemConfiguration.getOpenaiMaxTokens().getValue())); HttpEntity> request = new HttpEntity<>(params, headers); - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate = new RestTemplate(); try { - ResponseEntity response = restTemplate.postForEntity(systemConfiguration.getOpenAIBaseUrl().getValue(), request, String.class); + ResponseEntity response = restTemplate.postForEntity( + systemConfiguration.getOpenAIBaseUrl().getValue(), request, String.class); if (response.getStatusCode().is2xxSuccessful()) { return response.getBody(); } else { diff --git a/dinky-common/src/main/java/org/dinky/data/enums/OpenaiManufacturer.java b/dinky-common/src/main/java/org/dinky/data/enums/OpenaiManufacturer.java index 5b314a2274..cdb91acf36 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/OpenaiManufacturer.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/OpenaiManufacturer.java @@ -1,3 +1,22 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package org.dinky.data.enums; import lombok.Getter; diff --git a/dinky-common/src/main/java/org/dinky/data/enums/Status.java b/dinky-common/src/main/java/org/dinky/data/enums/Status.java index 125aa2c897..118445d485 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/Status.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/Status.java @@ -368,7 +368,6 @@ public enum Status { SYS_ENV_SETTINGS_OPENAI_MAX_TOKENS(1183, "sys.env.settings.openAI.maxTokens"), SYS_ENV_SETTINGS_OPENAI_MAX_TOKENS_NOTE(1184, "sys.env.settings.openAI.maxTokens.note"), - SYS_DOLPHINSCHEDULER_SETTINGS_ENABLE(118, "sys.dolphinscheduler.settings.enable"), SYS_DOLPHINSCHEDULER_SETTINGS_ENABLE_NOTE(119, "sys.dolphinscheduler.settings.enable.note"), SYS_DOLPHINSCHEDULER_SETTINGS_URL(120, "sys.dolphinscheduler.settings.url"), diff --git a/dinky-common/src/main/java/org/dinky/data/model/Configuration.java b/dinky-common/src/main/java/org/dinky/data/model/Configuration.java index 94703a1ba1..2216c83129 100644 --- a/dinky-common/src/main/java/org/dinky/data/model/Configuration.java +++ b/dinky-common/src/main/java/org/dinky/data/model/Configuration.java @@ -19,12 +19,8 @@ package org.dinky.data.model; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.EnumUtil; -import cn.hutool.core.util.ObjectUtil; -import com.fasterxml.jackson.annotation.JsonIgnore; +import org.dinky.data.enums.Status; + import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -32,10 +28,17 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Function; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.EnumUtil; +import cn.hutool.core.util.ObjectUtil; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import org.dinky.data.enums.Status; @Getter @Setter diff --git a/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java b/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java index befcdc33e8..1370aae6c5 100644 --- a/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java +++ b/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java @@ -21,7 +21,6 @@ import org.dinky.context.EngineContextHolder; import org.dinky.data.constant.CommonConstant; -import org.dinky.data.enums.OpenaiManufacturer; import org.dinky.data.enums.Status; import org.dinky.data.properties.OssProperties; @@ -138,7 +137,6 @@ public static Configuration.OptionBuilder key(Status status) { .defaultValue(false) .note(Status.SYS_ENV_SETTINGS_OPENAI_ENABLE_NOTE); - private final Configuration openAiKey = key(Status.SYS_ENV_SETTINGS_OPENAI_KEY) .stringType() .defaultValue("") @@ -149,7 +147,6 @@ public static Configuration.OptionBuilder key(Status status) { .defaultValue("") .note(Status.SYS_ENV_SETTINGS_OPENAI_BASE_URL_NOTE); - private final Configuration openaiModelType = key(Status.SYS_ENV_SETTINGS_OPENAI_MODEL_TYPE) .stringType() .defaultValue("gpt-3.5-turbo") @@ -160,7 +157,6 @@ public static Configuration.OptionBuilder key(Status status) { .defaultValue(10000) .note(Status.SYS_ENV_SETTINGS_OPENAI_MAX_TOKENS_NOTE); - private final Configuration dolphinschedulerEnable = key(Status.SYS_DOLPHINSCHEDULER_SETTINGS_ENABLE) .booleanType() .defaultValue(false) diff --git a/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/index.tsx b/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/index.tsx index 90b51dcc71..c55baf3595 100644 --- a/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/index.tsx +++ b/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/index.tsx @@ -20,12 +20,11 @@ import CodeEdit from '@/components/CustomEditor/CodeEdit'; import CodeShow from '@/components/CustomEditor/CodeShow'; import useThemeValue from '@/hooks/useThemeValue'; -import { jsonToSql } from '@/pages/DataStudio/BottomContainer/Tools/JsonToSql/service'; +import { getSupportLanguages } from '@/pages/DataStudio/BottomContainer/Tools/OpenAI/service'; import { StateType } from '@/pages/DataStudio/model'; import { connect } from '@@/exports'; import { Button, Space } from 'antd'; import React, { useState } from 'react'; -import {getSupportLanguages} from "@/pages/DataStudio/BottomContainer/Tools/OpenAI/service"; const padding = 10; diff --git a/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/service.tsx b/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/service.tsx index 63fc3764d6..03f4eb4c03 100644 --- a/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/service.tsx +++ b/dinky-web/src/pages/DataStudio/BottomContainer/Tools/OpenAI/service.tsx @@ -17,13 +17,14 @@ * */ -import {postAll, postDataArray} from '@/services/api'; -import { API_CONSTANTS } from '@/services/endpoints'; +import { postAll } from '@/services/api'; export async function getSupportLanguages(params: any) { - await postAll('api/suggestion/buildSuggestionsByOpenAi', params).then((res) => { - return res.data; - }).catch((err) => { - console.log(err); - }); + await postAll('api/suggestion/buildSuggestionsByOpenAi', params) + .then((res) => { + return res.data; + }) + .catch((err) => { + console.log(err); + }); } diff --git a/dinky-web/src/pages/DataStudio/route.tsx b/dinky-web/src/pages/DataStudio/route.tsx index 1399f69c96..47bacef677 100644 --- a/dinky-web/src/pages/DataStudio/route.tsx +++ b/dinky-web/src/pages/DataStudio/route.tsx @@ -23,6 +23,7 @@ import JobExecHistory from '@/pages/DataStudio/BottomContainer/JobExecHistory'; import Lineage from '@/pages/DataStudio/BottomContainer/Lineage'; import Result from '@/pages/DataStudio/BottomContainer/Result'; import JsonToSql from '@/pages/DataStudio/BottomContainer/Tools/JsonToSql'; +import OpenAI from '@/pages/DataStudio/BottomContainer/Tools/OpenAI'; import TextComparison from '@/pages/DataStudio/BottomContainer/Tools/TextComparison'; import { LeftBottomKey, LeftMenuKey, RightMenuKey } from '@/pages/DataStudio/data.d'; import { isSql } from '@/pages/DataStudio/HeaderContainer/function'; @@ -57,7 +58,6 @@ import { } from '@ant-design/icons'; import { TabPaneProps } from 'antd'; import React, { ReactNode } from 'react'; -import OpenAI from "@/pages/DataStudio/BottomContainer/Tools/OpenAI"; export const LeftSide: TabProp[] = [ {