Commit e8f83315 authored by jiangyz's avatar jiangyz

init

parent 22cc9b2f
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.8</version>
<version>3.5.8</version>
<relativePath/>
</parent>
<groupId>com.infoepoch.pms</groupId>
......@@ -16,7 +16,7 @@
<properties>
<java.version>21</java.version>
<spring-ai.version>1.1.0</spring-ai.version>
<spring-ai.version>1.1.2</spring-ai.version>
</properties>
<dependencyManagement>
<dependencies>
......@@ -38,14 +38,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
......@@ -90,8 +82,44 @@
<scope>system</scope>
<systemPath>${pom.basedir}/src/main/resources/jar/oceanbase-client-2.2.11.jar</systemPath>
</dependency>
<!--jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-sse</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......
package com.infoepoch.pms.agent;
import org.springframework.ai.model.openai.autoconfigure.OpenAiChatAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
......@@ -8,7 +9,7 @@ import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@SpringBootApplication(exclude = OpenAiChatAutoConfiguration.class)
@ConfigurationPropertiesScan
@ServletComponentScan
@EnableScheduling
......@@ -19,4 +20,4 @@ public class PmsAgentApplication {
public static void main(String[] args) {
SpringApplication.run(PmsAgentApplication.class, args);
}
}
\ No newline at end of file
}
package com.infoepoch.pms.agent.aiMode;
import com.infoepoch.pms.agent.properties.AiLocalProperties;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestClient;
@Configuration
public class AiLocalConfiguration {
@Bean("localOpenAiApi")
OpenAiApi localOpenAiApi(AiLocalProperties properties) {
return OpenAiApi.builder()
.baseUrl(properties.getBaseUrl())
.apiKey(resolveApiKey(properties))
.restClientBuilder(buildCompatibleRestClient())
.build();
}
@Bean("localChatModel")
ChatModel localChatModel(@Qualifier("localOpenAiApi") OpenAiApi localOpenAiApi,
AiLocalProperties properties) {
return OpenAiChatModel.builder()
.openAiApi(localOpenAiApi)
.defaultOptions(OpenAiChatOptions.builder()
.model(properties.getModel())
.temperature(properties.getTemperature())
.maxTokens(properties.getMaxTokens())
.build())
.build();
}
private RestClient.Builder buildCompatibleRestClient() {
ClientHttpRequestFactory requestFactory =
new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
return RestClient.builder().requestFactory(requestFactory);
}
private String resolveApiKey(AiLocalProperties properties) {
return StringUtils.hasText(properties.getApiKey()) ? properties.getApiKey() : "EMPTY";
}
}
package com.infoepoch.pms.agent.aiMode;
import com.infoepoch.pms.agent.properties.AiZhiYuProperties;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestClient;
@Configuration
public class AiZhiYuConfiguration {
@Bean("ZhiYuOpenAiApi")
OpenAiApi ZhiYuOpenAiApi(AiZhiYuProperties properties) {
return OpenAiApi.builder()
.baseUrl(properties.getBaseUrl())
.apiKey(resolveApiKey(properties))
.restClientBuilder(buildCompatibleRestClient())
.build();
}
@Primary
@Bean("ZhiYuChatModel")
ChatModel ZhiYuChatModel(@Qualifier("ZhiYuOpenAiApi") OpenAiApi zhiYuOpenAiApi,
AiZhiYuProperties properties) {
return OpenAiChatModel.builder()
.openAiApi(zhiYuOpenAiApi)
.defaultOptions(OpenAiChatOptions.builder()
.model(properties.getModel())
.temperature(properties.getTemperature())
.maxTokens(properties.getMaxTokens())
.build())
.build();
}
private RestClient.Builder buildCompatibleRestClient() {
ClientHttpRequestFactory requestFactory =
new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
return RestClient.builder().requestFactory(requestFactory);
}
private String resolveApiKey(AiZhiYuProperties properties) {
return StringUtils.hasText(properties.getApiKey()) ? properties.getApiKey() : "EMPTY";
}
}
package com.infoepoch.pms.agent.config;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
//@Configuration
public class AiDemoConfiguration {
// @Bean
// OpenAiApi pmsOpenAiApi(PmsAgentProperties properties) {
// return OpenAiApi.builder()
// .baseUrl(properties.getBaseUrl())
// .apiKey(resolveApiKey(properties))
// .build();
// }
//
// @Bean
// ChatModel pmsChatModel(OpenAiApi pmsOpenAiApi, PmsAgentProperties properties) {
// return OpenAiChatModel.builder()
// .openAiApi(pmsOpenAiApi)
// .defaultOptions(OpenAiChatOptions.builder()
// .model(properties.getModel())
// .temperature(properties.getTemperature())
// .maxTokens(properties.getMaxTokens())
// .build())
// .build();
// }
//
// private String resolveApiKey(PmsAgentProperties properties) {
// return StringUtils.hasText(properties.getApiKey()) ? properties.getApiKey() : "EMPTY";
// }
}
\ No newline at end of file
package com.infoepoch.pms.agent.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 本地模型配置 本地测试
*/
@Getter
@Setter
@ConfigurationProperties(prefix = "pms.ai.local")
public class AiLocalProperties {
private String baseUrl;
private String apiKey;
private String model;
private double temperature;
private int maxTokens;
private int maxIterations;
private String systemPrompt;
}
\ No newline at end of file
package com.infoepoch.pms.agent.config;
package com.infoepoch.pms.agent.properties;
import lombok.Getter;
import lombok.Setter;
......@@ -6,8 +6,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ConfigurationProperties(prefix = "pms.agent")
public class PmsAgentProperties {
@ConfigurationProperties(prefix = "pms.ai.zhiyu")
public class AiZhiYuProperties {
private String baseUrl;
private String apiKey;
......@@ -16,4 +16,4 @@ public class PmsAgentProperties {
private int maxTokens;
private int maxIterations;
private String systemPrompt;
}
\ No newline at end of file
}
package com.infoepoch.pms.agent.service;
import com.infoepoch.pms.agent.config.JsonUtils;
import com.infoepoch.pms.agent.config.PmsAgentProperties;
import com.infoepoch.pms.agent.properties.AiZhiYuProperties;
import com.infoepoch.pms.agent.web.dto.AgentChatRequest;
import com.infoepoch.pms.agent.web.dto.AgentChatResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
......@@ -11,9 +10,8 @@ import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
......@@ -22,96 +20,15 @@ import java.util.ArrayList;
import java.util.List;
@Service
@RequiredArgsConstructor
public class PmsAgentService {
private final ChatModel pmsChatModel;
private static final long SSE_TIMEOUT = 0L;
// private final ChatModel pmsChatModel;
private final PmsAgentProperties properties;
public void chatTest() {
OpenAiApi openAiApi = OpenAiApi.builder().baseUrl("https://api.siliconflow.cn").apiKey(
"sk-necxquynovkphnulbbfbsopeosgogrsuqgxxctzhbcbpntyh").build();
ChatModel chatModel = OpenAiChatModel.builder().openAiApi(openAiApi).build();
Prompt prompt = new Prompt("你好!",
OpenAiChatOptions.builder()
.model("Qwen/Qwen3.5-27B")
.temperature(0.7)
.build());
final ChatResponse chatResponse = chatModel.call(prompt);
System.out.println(JsonUtils.objectToJson(chatResponse));
}
public void chatTest1() {
OpenAiApi openAiApi = OpenAiApi.builder().baseUrl("http://172.28.30.253:8001").apiKey(
"115e68c85d91d40dd3df42a06f08cbed").build();
ChatModel chatModel = OpenAiChatModel.builder().openAiApi(openAiApi).build();
Prompt prompt = new Prompt("你好!",
OpenAiChatOptions.builder()
.model("Qwen3.5-27B")
.temperature(0.7)
.build());
final ChatResponse chatResponse = chatModel.call(prompt);
System.out.println(JsonUtils.objectToJson(chatResponse));
public PmsAgentService(@Qualifier("localChatModel") ChatModel pmsChatModel){
this.pmsChatModel = pmsChatModel;
}
// public AgentChatResponse chat(AgentChatRequest request) {
// ChatResponse response = pmsChatModel.call(buildPrompt(request.message()));
// return new AgentChatResponse(extractText(response));
// }
public SseEmitter streamChat(AgentChatRequest request) {
SseEmitter emitter = new SseEmitter(SSE_TIMEOUT);
Prompt prompt = buildPrompt("你好");
// ChatResponse s = pmsChatModel.call(prompt);
// System.out.println(s);
// pmsChatModel.stream(buildPrompt(request.message()))
// .map(this::extractText)
// .filter(StringUtils::hasText)
// .doOnNext(token -> sendToken(emitter, token))
// .doOnComplete(() -> completeStream(emitter))
// .doOnError(emitter::completeWithError)
// .subscribe();
return emitter;
}
private Prompt buildPrompt(String message) {
List<Message> messages = new ArrayList<>();
if (StringUtils.hasText(properties.getSystemPrompt())) {
messages.add(new SystemMessage(properties.getSystemPrompt()));
}
messages.add(new UserMessage(message));
OpenAiChatOptions options = OpenAiChatOptions.builder()
.model(properties.getModel())
.temperature(properties.getTemperature())
.build();
return new Prompt(messages, options);
}
private String extractText(ChatResponse response) {
if (response == null || response.getResult() == null || response.getResult().getOutput() == null) {
return "";
}
return response.getResult().getOutput().getText();
}
private void sendToken(SseEmitter emitter, String token) {
try {
emitter.send(SseEmitter.event().name("token").data(token));
} catch (Exception exception) {
emitter.completeWithError(exception);
}
}
private void completeStream(SseEmitter emitter) {
try {
emitter.send(SseEmitter.event().name("done").data("[DONE]"));
emitter.complete();
} catch (Exception exception) {
emitter.completeWithError(exception);
}
public void chatTest() {
ChatResponse chatResponse = pmsChatModel.call(new Prompt("你好"));
System.out.println(chatResponse.getResult().getOutput().getText());
}
}
\ No newline at end of file
}
package com.infoepoch.pms.agent.web;
import com.infoepoch.pms.agent.service.PmsAgentService;
import com.infoepoch.pms.agent.web.dto.AgentChatRequest;
import com.infoepoch.pms.agent.web.dto.AgentChatResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@RestController
@RequiredArgsConstructor
......@@ -45,51 +28,4 @@ public class AgentChatController {
public void chatTest() {
pmsAgentService.chatTest();
}
@PostMapping("/chatTest2")
public void chatTest2() {
pmsAgentService.chatTest1();
}
@PostMapping("/testChat3")
public void testChat3() throws URISyntaxException {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
String url = "http://172.28.30.253:8001/v1/chat/completions";
try {
URI uri = new URI(url);
ClientHttpRequest request = factory.createRequest(uri, HttpMethod.POST);
// 4. 设置请求头
request.getHeaders().set("Content-Type", "application/json");
request.getHeaders().set("Accept", "application/json");
request.getHeaders().set("Authorization", "Bearer 115e68c85d91d40dd3df42a06f08cbed");
// 5. 准备请求体(例如 JSON 字符串)
String requestBody = "{\n" +
" \"model\": \"Qwen3.5-27B\",\n" +
" \"messages\": [\n" +
" {\"role\": \"user\", \"content\": \"你好\"}\n" +
" ]\n" +
"}";
// 6. 写入请求体
try (OutputStream os = request.getBody()) {
os.write(requestBody.getBytes(StandardCharsets.UTF_8));
os.flush();
}
// 7. 执行请求并获取响应
try (ClientHttpResponse response = request.execute()) {
// 8. 处理响应
HttpStatusCode statusCode = response.getStatusCode();
System.out.println("Status Code: " + statusCode);
// 读取响应体
String responseBody = new String(response.getBody().readAllBytes(), StandardCharsets.UTF_8);
System.out.println("Response Body: " + responseBody);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.infoepoch.pms.agent.web.dto;
import jakarta.validation.constraints.NotBlank;
public record AgentChatRequest(
@NotBlank(message = "message must not be blank")
String message
) {
}
\ No newline at end of file
......@@ -33,4 +33,21 @@ spring:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@172.28.30.71:1521:DEVEPMS
username: dbunionjs
password: ENC(0SNhMqnAZf/8CCmyXOIjcA==)
\ No newline at end of file
password: ENC(0SNhMqnAZf/8CCmyXOIjcA==)
pms:
ai:
zhiyu:
base-url: http://10.32.41.228:39080
api-key:
model: qwen3.5
temperature: 0.5
max-tokens: 50000
max-iterations: 5
local:
base-url: http://172.28.30.253:8001
api-key: 115e68c85d91d40dd3df42a06f08cbed
model: Qwen3.5-27B
temperature: 0.5
max-tokens: 50000
max-iterations: 5
......@@ -36,4 +36,20 @@ spring:
url: jdbc:oceanbase://10.32.166.11:2883,10.32.166.12:2883,10.32.166.13:2883,10.32.166.14:2883,10.32.166.15:2883,10.32.166.16:2883/JSXJY12?continueBatchOnError=false&allowMultiQueries=true&rewriteBatchedStatements=true&loadBalanceStrategy=RANDOM
#格式: 用户名@租户名#集群名
username: JSXJY12@epmsdb#OAFCDB1
password: ENC(Yj7c5E7DUeoC2U3nXdqxpbm97z40p662)
\ No newline at end of file
password: ENC(Yj7c5E7DUeoC2U3nXdqxpbm97z40p662)
pms:
ai:
zhiyu:
base-url: http://10.32.41.228:39080
api-key:
model: qwen3.5
temperature: 0.5
max-tokens: 50000
max-iterations: 5
local:
base-url: http://172.28.30.253:8001
api-key: 115e68c85d91d40dd3df42a06f08cbed
model: Qwen3.5-27B
temperature: 0.5
max-tokens: 50000
max-iterations: 5
\ No newline at end of file
......@@ -27,4 +27,20 @@ spring:
url: jdbc:oceanbase://10.33.240.207:2881?rewriteBatchedStatements=TRUE
#格式: 用户名@租户名#集群名
username: unionjs@gxxjycsdb
password: ENC(0SNhMqnAZf/8CCmyXOIjcA==)
\ No newline at end of file
password: ENC(0SNhMqnAZf/8CCmyXOIjcA==)
pms:
ai:
zhiyu:
base-url: http://10.32.41.228:39080
api-key:
model: qwen3.5
temperature: 0.5
max-tokens: 50000
max-iterations: 5
local:
base-url: http://172.28.30.253:8001
api-key: 115e68c85d91d40dd3df42a06f08cbed
model: Qwen3.5-27B
temperature: 0.5
max-tokens: 50000
max-iterations: 5
\ No newline at end of file
......@@ -30,16 +30,6 @@ logging:
level:
com.infoepoch.pms.agent: info
pms:
agent:
base-url: http://172.28.30.253:8001
api-key: 115e68c85d91d40dd3df42a06f08cbed
model: Qwen3.5-27B
temperature: 0.5
max-tokens: 1000
max-iterations: 5
system-prompt: 你是一个简洁的中文助手,请直接回答用户问题。
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
......
package com.infoepoch.pms.agent;
import com.infoepoch.pms.agent.properties.AiZhiYuProperties;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@SpringBootTest
public class LLMChatTest {
private static final Logger log = LoggerFactory.getLogger(LLMChatTest.class);
private static final String PROMPT_TEXT = "Say this is a test!";
private static final Duration HTTP_TIMEOUT = Duration.ofSeconds(60);
private final ChatModel pmsChatModel;
private final AiZhiYuProperties properties;
@Autowired
public LLMChatTest(ChatModel pmsChatModel, AiZhiYuProperties properties) {
this.pmsChatModel = pmsChatModel;
this.properties = properties;
}
@Test
public void chatTest() {
logRuntimeContext();
runSpringAiCall();
runRawHttpComparison();
}
private void runSpringAiCall() {
log.info("[spring-ai] starting request");
try {
Prompt prompt = new Prompt(PROMPT_TEXT,
OpenAiChatOptions.builder()
.model(properties.getModel())
.temperature(properties.getTemperature())
.maxTokens(properties.getMaxTokens())
.build());
ChatResponse chatResponse = pmsChatModel.call(prompt);
String output = chatResponse == null || chatResponse.getResult() == null
|| chatResponse.getResult().getOutput() == null
? null
: chatResponse.getResult().getOutput().getText();
log.info("[spring-ai] response_text={}", output);
} catch (Exception exception) {
log.error("[spring-ai] request failed", exception);
}
}
private void runRawHttpComparison() {
String requestBody = buildRawRequestBody();
String requestUrl = buildChatCompletionsUrl();
log.info("[raw-http] starting request url={}", requestUrl);
log.info("[raw-http] request_headers={{Authorization=Bearer ****, Content-Type=application/json}}");
log.info("[raw-http] request_body_bytes={}", requestBody.getBytes(StandardCharsets.UTF_8).length);
log.info("[raw-http] request_body={}", requestBody);
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(requestUrl))
.timeout(HTTP_TIMEOUT)
.header("Authorization", "Bearer " + resolveApiKey())
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody, StandardCharsets.UTF_8))
.build();
HttpResponse<String> response = HttpClient.newBuilder()
.connectTimeout(HTTP_TIMEOUT)
.build()
.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
log.info("[raw-http] response_status={}", response.statusCode());
log.info("[raw-http] response_headers={}", response.headers().map());
log.info("[raw-http] response_body={}", response.body());
} catch (Exception exception) {
log.error("[raw-http] request failed", exception);
}
}
private void logRuntimeContext() {
log.info("[diagnostic] java_version={}", System.getProperty("java.version"));
log.info("[diagnostic] java_vendor={}", System.getProperty("java.vendor"));
log.info("[diagnostic] os_name={}", System.getProperty("os.name"));
log.info("[diagnostic] base_url={}", properties.getBaseUrl());
log.info("[diagnostic] model={}", properties.getModel());
log.info("[diagnostic] prompt={}", PROMPT_TEXT);
}
private String buildRawRequestBody() {
return """
{
\"model\": \"%s\",
\"messages\": [
{
\"role\": \"user\",
\"content\": \"%s\"
}
],
\"temperature\": %s
}
""".formatted(properties.getModel(), escapeJson(PROMPT_TEXT), properties.getTemperature());
}
private String buildChatCompletionsUrl() {
String baseUrl = properties.getBaseUrl();
if (baseUrl.endsWith("/")) {
return baseUrl + "v1/chat/completions";
}
return baseUrl + "/v1/chat/completions";
}
private String resolveApiKey() {
return properties.getApiKey() == null ? "EMPTY" : properties.getApiKey();
}
private String escapeJson(String value) {
return value
.replace("\\", "\\\\")
.replace("\"", "\\\"");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment