move spec into chatclient
This commit is contained in:
@@ -5,7 +5,6 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.chat.ChatClient;
|
||||
import org.springframework.ai.chat.FluentChatClient;
|
||||
import org.springframework.ai.chat.messages.Media;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.openai.OpenAiTestConfiguration;
|
||||
@@ -26,11 +25,12 @@ public class OpenAiChatClientFluentIT {
|
||||
|
||||
@Test
|
||||
void simpleTest() {
|
||||
var liquidChatClient = new FluentChatClient.LiquidChatClient(this.chatClient);
|
||||
var actors = liquidChatClient
|
||||
.chat(s -> s.system(sys -> sys.text("""
|
||||
You're a non user hostile chatbot from cyberdyne systems.
|
||||
your primary objective is {primaryObjective}""").params(Map.of("primaryObjective", "No PHP")))
|
||||
|
||||
var systemText = """
|
||||
You're a non user hostile chatbot from cyberdyne systems.
|
||||
your primary objective is {primaryObjective}""";
|
||||
var actors = this.chatClient
|
||||
.chat(s -> s.system(sys -> sys.text(systemText).params(Map.of("primaryObjective", "No PHP")))
|
||||
.functions(fn -> fn.functions((FunctionCallback) null)
|
||||
.functions("createReservation", "cancelReservations"))
|
||||
.user(user -> user.text("tell me a joke about {topic}")
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
*/
|
||||
package org.springframework.ai.chat;
|
||||
|
||||
import org.springframework.ai.chat.messages.Media;
|
||||
import org.springframework.ai.chat.dsl.ChatClientDsl;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
import org.springframework.ai.chat.messages.UserMessage;
|
||||
import org.springframework.ai.model.ModelClient;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
public interface ChatClient extends ModelClient<Prompt, ChatResponse> {
|
||||
|
||||
@@ -35,6 +33,18 @@ public interface ChatClient extends ModelClient<Prompt, ChatResponse> {
|
||||
return (generation != null) ? generation.getOutput().getContent() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the chat API with a variable number of messages.
|
||||
*
|
||||
* <p>
|
||||
* This method is deprecated since version 1.0.0 M1 and is intended to be removed in
|
||||
* future versions. Use the {@link #chat(Consumer< ChatClientDsl.ChatBuilderSpec>
|
||||
* chatSpec)} method instead.
|
||||
* @param messages The messages to send to the chat API. Each message should implement
|
||||
* the {@link Message} interface.
|
||||
* @return The content of the output message generated by the AI.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0 M1", forRemoval = true)
|
||||
default String call(Message... messages) {
|
||||
Prompt prompt = new Prompt(Arrays.asList(messages));
|
||||
Generation generation = call(prompt).getResult();
|
||||
@@ -44,4 +54,8 @@ public interface ChatClient extends ModelClient<Prompt, ChatResponse> {
|
||||
@Override
|
||||
ChatResponse call(Prompt prompt);
|
||||
|
||||
default ChatClientDsl.ChatCallSpec chat(Consumer<ChatClientDsl.ChatBuilderSpec> chatSpec) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.springframework.ai.chat;
|
||||
package org.springframework.ai.chat.dsl;
|
||||
|
||||
import org.springframework.ai.chat.ChatResponse;
|
||||
import org.springframework.ai.chat.messages.Media;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
@@ -12,13 +12,7 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class FluentChatClient {
|
||||
|
||||
private final ChatClient chatClient;
|
||||
|
||||
public FluentChatClient(ChatClient chatClient) {
|
||||
this.chatClient = chatClient;
|
||||
}
|
||||
public abstract class ChatClientDsl {
|
||||
|
||||
public static class AbstractSystemMessageBuilder {
|
||||
|
||||
@@ -29,6 +23,11 @@ public class FluentChatClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AbstractSystemMessageBuilder param(String key, Object value) {
|
||||
this.paramsMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class AbstractUserMessageBuilder {
|
||||
@@ -141,7 +140,7 @@ public class FluentChatClient {
|
||||
|
||||
}
|
||||
|
||||
public static class LiquidChatCallSpec {
|
||||
public static class ChatCallSpec {
|
||||
|
||||
public <T> T call(Class<T> tClass) {
|
||||
return null;
|
||||
@@ -157,19 +156,4 @@ public class FluentChatClient {
|
||||
|
||||
}
|
||||
|
||||
public static class LiquidChatClient {
|
||||
|
||||
private final ChatClient chatClient;
|
||||
|
||||
public LiquidChatClient(ChatClient chatClient) {
|
||||
this.chatClient = chatClient;
|
||||
}
|
||||
|
||||
// put this in ChatClient
|
||||
public LiquidChatCallSpec chat(Consumer<ChatBuilderSpec> chatSpec) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user