Skip to content

Commit

Permalink
Spotless Apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 authored and github-actions[bot] committed Apr 18, 2024
1 parent 730782c commit 0d263ae
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -83,5 +83,4 @@ public Result<String> buildSuggestionsByOpenAi(@RequestBody SuggestionDTO sugges

return Result.succeed(suggestionService.buildSuggestionsByOpenAi(suggestionDTO), Status.SUCCESS);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +27,4 @@ public class OpenAISuggestionConfig {
private String apiKey;
private String model;
private final String baseUrl = "https://vendor-a-api.com/openai";


}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -14,5 +33,5 @@ public interface OpenAISuggestionService {
* @param suggestionDTO suggestionDTO
* @return suggestions list
*/
String getSuggestions(SuggestionDTO suggestionDTO) ;
String getSuggestions(SuggestionDTO suggestionDTO);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
*
Expand All @@ -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<String, String> 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<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);

RestTemplate restTemplate = new RestTemplate();
RestTemplate restTemplate = new RestTemplate();

try {
ResponseEntity<String> response = restTemplate.postForEntity(systemConfiguration.getOpenAIBaseUrl().getValue(), request, String.class);
ResponseEntity<String> response = restTemplate.postForEntity(
systemConfiguration.getOpenAIBaseUrl().getValue(), request, String.class);
if (response.getStatusCode().is2xxSuccessful()) {
return response.getBody();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
17 changes: 10 additions & 7 deletions dinky-common/src/main/java/org/dinky/data/model/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@

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;
import java.util.LinkedList;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -138,7 +137,6 @@ public static Configuration.OptionBuilder key(Status status) {
.defaultValue(false)
.note(Status.SYS_ENV_SETTINGS_OPENAI_ENABLE_NOTE);


private final Configuration<String> openAiKey = key(Status.SYS_ENV_SETTINGS_OPENAI_KEY)
.stringType()
.defaultValue("")
Expand All @@ -149,7 +147,6 @@ public static Configuration.OptionBuilder key(Status status) {
.defaultValue("")
.note(Status.SYS_ENV_SETTINGS_OPENAI_BASE_URL_NOTE);


private final Configuration<String> openaiModelType = key(Status.SYS_ENV_SETTINGS_OPENAI_MODEL_TYPE)
.stringType()
.defaultValue("gpt-3.5-turbo")
Expand All @@ -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<Boolean> dolphinschedulerEnable = key(Status.SYS_DOLPHINSCHEDULER_SETTINGS_ENABLE)
.booleanType()
.defaultValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion dinky-web/src/pages/DataStudio/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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[] = [
{
Expand Down

0 comments on commit 0d263ae

Please sign in to comment.