Spaces:
Sleeping
Sleeping
| package com.example.p1.config; | |
| import org.springframework.boot.context.properties.ConfigurationProperties; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.web.reactive.function.client.WebClient; | |
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | |
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
| public class AiConfiguration implements WebMvcConfigurer { | |
| private String key; | |
| private String baseUrl; | |
| private String model; | |
| private int timeout = 30000; | |
| public WebClient geminiWebClient() { | |
| return WebClient.builder() | |
| .baseUrl(baseUrl) | |
| .defaultHeader("Content-Type", "application/json") | |
| .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024)) | |
| .build(); | |
| } | |
| public void addCorsMappings(CorsRegistry registry) { | |
| registry.addMapping("/api/**") | |
| .allowedOrigins("http://localhost:3000", "http://localhost:8080","http://localhost:63342") | |
| .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") | |
| .allowedHeaders("*") | |
| .allowCredentials(true); | |
| } | |
| // Getters and setters | |
| public String getKey() { return key; } | |
| public void setKey(String key) { this.key = key; } | |
| public String getBaseUrl() { return baseUrl; } | |
| public void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; } | |
| public String getModel() { return model; } | |
| public void setModel(String model) { this.model = model; } | |
| public int getTimeout() { return timeout; } | |
| public void setTimeout(int timeout) { this.timeout = timeout; } | |
| } |