tools
This commit is contained in:
@@ -6,8 +6,12 @@ import org.springframework.ai.chat.messages.Message;
|
|||||||
import org.springframework.ai.chat.prompt.Prompt;
|
import org.springframework.ai.chat.prompt.Prompt;
|
||||||
import org.springframework.ai.openai.OpenAiChatModel;
|
import org.springframework.ai.openai.OpenAiChatModel;
|
||||||
import org.springframework.ai.openai.OpenAiChatOptions;
|
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||||
|
import org.springframework.ai.openai.api.OpenAiApi;
|
||||||
import org.springframework.ai.openai.api.ResponseFormat;
|
import org.springframework.ai.openai.api.ResponseFormat;
|
||||||
|
import org.springframework.ai.support.ToolCallbacks;
|
||||||
|
import org.springframework.ai.tool.ToolCallback;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ldeloff.aitools.telegrambot.tool.DateTimeTool;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -18,12 +22,16 @@ public class LlmService {
|
|||||||
private final OpenAiChatModel model;
|
private final OpenAiChatModel model;
|
||||||
|
|
||||||
public List<String> sendMessages(List<Message> messages) {
|
public List<String> sendMessages(List<Message> messages) {
|
||||||
return model.call(
|
return model
|
||||||
|
.call(
|
||||||
new Prompt(
|
new Prompt(
|
||||||
messages,
|
messages,
|
||||||
OpenAiChatOptions.builder()
|
OpenAiChatOptions.builder()
|
||||||
.temperature(0.1)
|
.temperature(0.1)
|
||||||
.responseFormat(ResponseFormat.builder().type(ResponseFormat.Type.TEXT).build())
|
.toolCallbacks(ToolCallbacks.from(new DateTimeTool()))
|
||||||
|
.responseFormat(
|
||||||
|
ResponseFormat.builder().type(ResponseFormat.Type.TEXT).build()
|
||||||
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.ldeloff.aitools.telegrambot.tool;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.ai.tool.annotation.Tool;
|
||||||
|
import org.springframework.ai.tool.annotation.ToolParam;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class DateTimeTool {
|
||||||
|
|
||||||
|
@Tool(description = "Returns current date and time in the given timezone. Default: Europe/Moscow. Use IANA timezone IDs (e.g., America/New_York, Asia/Tokyo).")
|
||||||
|
String getCurrentDateTime(@ToolParam(description = "IANA timezone ID (e.g., Europe/Moscow, America/New_York). Default: Europe/Moscow") String timezone) {
|
||||||
|
log.info("getTime called for timezone: {}", timezone);
|
||||||
|
ZoneId zoneId = ZoneId.of(timezone==null ? "Europe/Moscow" : timezone);
|
||||||
|
LocalDateTime now = LocalDateTime.now(zoneId);
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return now.format(formatter);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user