@@ -0,0 +1,39 @@
|
||||
package com.jambotronGroup.jambotron.ZhiPuAi;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
import org.springframework.ai.image.Image;
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:4200, https://pony-sincere-chimp.ngrok-free.app/", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/zhipuai")
|
||||
public class ImageController {
|
||||
|
||||
@Autowired
|
||||
ZhiPuAiImageService _zhiPuAiImageService;
|
||||
|
||||
@GetMapping("/image/{query}")
|
||||
public ResponseEntity<Image> getImage(@PathVariable("query") String query) {
|
||||
try {
|
||||
Image returnValue = _zhiPuAiImageService.generateImage(query).getResult().getOutput();
|
||||
//userRepository.findAll().forEach(users::add);
|
||||
|
||||
|
||||
if (returnValue == null) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(returnValue, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,45 @@
|
||||
package com.jambotronGroup.jambotron.ZhiPuAi;
|
||||
|
||||
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
//import org.springframework.web.reactive.function.client.WebClient;
|
||||
//
|
||||
//@Service
|
||||
//public class ZhiPuAiImageService {
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.base-url}")
|
||||
// private String baseUrl;
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.api-key}")
|
||||
// private String apiKey;
|
||||
//
|
||||
// private final WebClient webClient;
|
||||
//
|
||||
// public ZhiPuAiImageService(WebClient.Builder webClientBuilder) {
|
||||
// this.webClient = webClientBuilder.baseUrl(baseUrl).build();
|
||||
// }
|
||||
//
|
||||
// public String generateImage(String prompt) {
|
||||
// return webClient.post()
|
||||
// .uri("/image/generate")
|
||||
// .header("Authorization", "Bearer " + apiKey)
|
||||
// .bodyValue(new ImageRequest(prompt))
|
||||
// .retrieve()
|
||||
// .bodyToMono(String.class)
|
||||
// .block();
|
||||
// }
|
||||
//
|
||||
// private static class ImageRequest {
|
||||
// private final String prompt;
|
||||
//
|
||||
// public ImageRequest(String prompt) {
|
||||
// this.prompt = prompt;
|
||||
// }
|
||||
//
|
||||
// public String getPrompt() {
|
||||
// return prompt;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@Service
|
||||
public class ZhiPuAiImageService {
|
||||
|
||||
@Value("${spring.ai.zhipuai.base-url}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${spring.ai.zhipuai.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
|
||||
private ZhiPuAiImageApi _zhiPuAiImageApi;
|
||||
|
||||
private ZhiPuAiImageModel _zhiPuAiImageModel;
|
||||
|
||||
public ZhiPuAiImageService() {
|
||||
|
||||
_zhiPuAiImageApi = new ZhiPuAiImageApi("628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI");
|
||||
|
||||
_zhiPuAiImageModel = new ZhiPuAiImageModel(_zhiPuAiImageApi);
|
||||
}
|
||||
|
||||
public ImageResponse generateImage(String prompt) {
|
||||
// Create an ImagePrompt object with the desired prompt
|
||||
ImagePrompt imagePrompt = new ImagePrompt(prompt);
|
||||
|
||||
// Call the generate method to get the image response
|
||||
ImageResponse imageResponse = _zhiPuAiImageModel.call(imagePrompt);
|
||||
|
||||
// Return the image response
|
||||
return imageResponse;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,10 +2,13 @@ package com.jambotronGroup.jambotron.configuretions;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/*
|
||||
@Configuration
|
||||
|
||||
@EnableWebMvc
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
@Value("${spring.resources.static-locations}")
|
||||
String resourceLocations;
|
||||
@@ -13,7 +16,10 @@ public class MvcConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
//registry.addResourceHandler("/public/**").addResourceLocations(resourceLocations);
|
||||
// registry.addResourceHandler("/media/**").addResourceLocations("resources/main/public/media/");
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/resources/");
|
||||
|
||||
//registry.
|
||||
registry.addResourceHandler("/media/**").addResourceLocations("resources/main/public/media/");
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
/*
|
||||
|
||||
@ControllerAdvice
|
||||
public class NotFoundHandler {
|
||||
@Value("${spa.default-file}")
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
//@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600, allowCredentials="true")
|
||||
@CrossOrigin(origins = "http://localhost:4200,https://a576-5-248-149-207.ngrok-free.app, https://pony-sincere-chimp.ngrok-free.app", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
public class AuthController {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/*@Controller
|
||||
public class RedirectController {
|
||||
@RequestMapping(value = "/{path:[^\\.]*}")
|
||||
public String redirect() {
|
||||
return "forward:/index.html";
|
||||
}
|
||||
}*/
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
import com.jambotronGroup.jambotron.model.Setting;
|
||||
import com.jambotronGroup.jambotron.system.SystemService;
|
||||
import org.springframework.beans.factory.NamedBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -20,6 +23,26 @@ public class SystemController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/data-source-properties")
|
||||
public ResponseEntity<List<NameValueItem>> getDataSourceProperties(@RequestParam(required = false) String title) {
|
||||
try {
|
||||
List<NameValueItem> properties = systemService.getDataSourceProperties();
|
||||
//userRepository.findAll().forEach(users::add);
|
||||
|
||||
|
||||
if (properties.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(properties, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/beans")
|
||||
public ResponseEntity<List<Bean>> getLoadedBeans(@RequestParam(required = false) String title) {
|
||||
try {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
public class ZhiPuAiController {
|
||||
|
||||
// This class is a placeholder for the ZhiPuAiController.
|
||||
// You can implement methods to handle requests related to ZhiPuAi functionality.
|
||||
// For example, you might want to add methods for generating images or processing text.
|
||||
|
||||
// Example method (to be implemented):
|
||||
// @GetMapping("/generate-image")
|
||||
// public ResponseEntity<String> generateImage(@RequestParam String prompt) {
|
||||
// String imageUrl = zhiPuAiService.generateImage(prompt);
|
||||
// return new ResponseEntity<>(imageUrl, HttpStatus.OK);
|
||||
// }
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class Bean {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return String.format("name = %s type= %s", this.shortName, this.typeShortName);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.jambotronGroup.jambotron.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class NameValueItem {
|
||||
|
||||
public NameValueItem(String name, String value){
|
||||
_name = name;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
@Id
|
||||
private String _name;
|
||||
|
||||
private String _value;
|
||||
|
||||
public String getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public void setValue(String _value) {
|
||||
this._value = _value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
this._name = _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return String.format("name = %s value= %s", this._name, this._value);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableMethodSecurity
|
||||
@@ -24,7 +26,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
// securedEnabled = true,
|
||||
// jsr250Enabled = true,
|
||||
//prePostEnabled = true)
|
||||
public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecurityConfigurerAdapter {
|
||||
@Autowired
|
||||
UserDetailsServiceImpl userDetailsService;
|
||||
|
||||
@@ -41,6 +43,11 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
// authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
// Do not add any mappings to enable complete disabling of CORS.
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaoAuthenticationProvider authenticationProvider() {
|
||||
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
|
||||
@@ -106,10 +113,15 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
auth.requestMatchers("/api/auth/**").permitAll()
|
||||
.requestMatchers("/*", "/home", "/resources/**").permitAll()
|
||||
.requestMatchers("/resources/public/media/**").permitAll()
|
||||
.requestMatchers("/resources/public/browser/**").permitAll()
|
||||
.requestMatchers("/media/**").permitAll()
|
||||
|
||||
.requestMatchers("/main/**").permitAll()
|
||||
.requestMatchers("/api/test/**").permitAll()
|
||||
.requestMatchers("/api/tutorials").permitAll()
|
||||
|
||||
.requestMatchers("/api/zhipuai/image/**").permitAll()
|
||||
|
||||
.requestMatchers("/api/users").permitAll()
|
||||
.requestMatchers("/api/users/**").permitAll()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jambotronGroup.jambotron.system;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,4 +10,8 @@ public interface SystemService {
|
||||
|
||||
List<Bean> getLodedCustomBeans();
|
||||
|
||||
List<NameValueItem> getDataSourceProperties();
|
||||
|
||||
List<NameValueItem> getImage();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
package com.jambotronGroup.jambotron.system;
|
||||
|
||||
import com.jambotronGroup.jambotron.JambotronApplication;
|
||||
import com.jambotronGroup.jambotron.controllers.SystemController;
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
import com.jambotronGroup.jambotron.utils.EntityLoggingConsumer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.web.config.SpringDataWebSettings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -23,9 +30,50 @@ public class SystemServiceImpl implements SystemService {
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
DataSourceProperties _dataSourceProperties;
|
||||
|
||||
@Autowired
|
||||
ZhiPuAiImageModel imageClient;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<NameValueItem> getDataSourceProperties(){
|
||||
List<NameValueItem> returnValue = new ArrayList<NameValueItem>();
|
||||
|
||||
returnValue.add(new NameValueItem("Username", _dataSourceProperties.getUsername()));
|
||||
returnValue.add(new NameValueItem("Password", _dataSourceProperties.getPassword()));
|
||||
returnValue.add(new NameValueItem("Url", _dataSourceProperties.getUrl()));
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NameValueItem> getImage(){
|
||||
List<NameValueItem> returnValue = new ArrayList<NameValueItem>();
|
||||
|
||||
ZhiPuAiImageApi api = new ZhiPuAiImageApi("628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI");
|
||||
|
||||
ZhiPuAiImageModel imageClient = new ZhiPuAiImageModel(api);
|
||||
|
||||
//imageClient.
|
||||
|
||||
|
||||
//imageClient.getDefaultOptions().setUser("44621746535994937");
|
||||
|
||||
ImageResponse imageResponse = imageClient.call(new ImagePrompt("Ukr zaliznicya station in the style cubisme"));
|
||||
|
||||
|
||||
|
||||
returnValue.add(new NameValueItem("response", "imageResponse."));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Bean> getLodedBeans() {
|
||||
// Get all bean names from the application context and map them to Bean objects
|
||||
|
||||
@@ -29,10 +29,12 @@ spring.mvc.throw-exception-if-no-handler-found=true
|
||||
# Disable the default mappings
|
||||
#spring.resources.add-mappings=false
|
||||
|
||||
spring.resources.static-locations=classpath:/public
|
||||
spring.resources.cache.period=31557600s # 1 year if you want
|
||||
spa.default-file=classpath:/public/browser/index.html
|
||||
|
||||
# UI(index.html) location
|
||||
#spring.resources.static-locations=classpath:/public/browser/
|
||||
#
|
||||
#spring.resources.cache.period=31557600s # 1 year if you want
|
||||
#spa.default-file=classpath:/public/browser/index.html
|
||||
#
|
||||
|
||||
spring.docker.compose.file=../Docker/docker-compose.yml
|
||||
|
||||
@@ -44,5 +46,7 @@ spring.flyway.password=postgrespw
|
||||
spring.flyway.url=jdbc:postgresql://localhost:5432/jambotronDB
|
||||
|
||||
|
||||
spring.ai.zhipuai.base-url=https://open.bigmodel.cn/api/paas/v3
|
||||
spring.ai.zhipuai.api-key = 628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI
|
||||
|
||||
|
||||
spring.ai.zhipuai.base-url=https://open.bigmodel.cn/api/paas/v4/images/generations
|
||||
spring.ai.zhipuai.api-key = 628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Column: public.tutorials.
|
||||
|
||||
ALTER TABLE IF EXISTS public.tutorials DROP COLUMN IF EXISTS id;
|
||||
|
||||
ALTER TABLE IF EXISTS public.tutorials
|
||||
ADD COLUMN id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 );
|
||||
Reference in New Issue
Block a user