formatting

This commit is contained in:
Mark Pollack
2024-05-16 18:25:55 +02:00
parent 583d2c7989
commit 1fd32e3e01
7 changed files with 223 additions and 569 deletions

View File

@@ -0,0 +1,44 @@
package org.springframework.ai.openai.chat;
import org.junit.jupiter.api.Test;
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.FluentChatClientLambda;
import org.springframework.ai.openai.OpenAiTestConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest(classes = OpenAiTestConfiguration.class)
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class OpenAiChatClientSpecLambdaIT {
@Autowired
private ChatClient chatClient;
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientSpecLambdaIT.class);
@Test
void simpleTest() {
var liquidChatClient = new FluentChatClientLambda.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")))
.functions(fn -> fn.functions((FunctionCallback) null)
.functions("createReservation", "cancelReservations"))
.user(user -> user.text("tell me a joke about {topic}")
.params(Map.of("topic", "PHP"))
.media(new Media[0])))
.call(ActorsFilmsRecord2.class);
}
record ActorsFilmsRecord2(String actor, List<String> movies) {
}
}

View File

@@ -1,90 +0,0 @@
package org.springframework.ai.openai.chat;
import org.junit.jupiter.api.Test;
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.FluentChatClientLambda;
import org.springframework.ai.openai.OpenAiTestConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = OpenAiTestConfiguration.class)
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class OpenAiChatClientSpecIT {
@Autowired
private ChatClient chatClient;
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientSpecIT.class);
@Test
void simpleTest() {
FluentChatClient fluentChatClient = new FluentChatClient(chatClient);
ActorsFilmsRecord actorsFilms = fluentChatClient.chat()
.user()
.text("Generate the filmography of 5 movies for {actor}.")
.param("actor", "Tom Hanks")
.and()
.and()
.execute();
ActorsFilmsRecord actorsFilms = new FluentChatClientLambda(chatClient).chat(
chatSpec -> chatSpec
.user(userSpec -> {
userSpec.text("Generate the filmography of 5 movies for {actor}.",
textSpec -> textSpec.param("actor", "Tom Hanks") );
userSpec.media()
}
)
.execute());
// ActorsFilmsRecord actorsFilms = new FluentChatClient().chat(chatSpec ->
// chatSpec.user(userSpec ->
// userSpec.text("Generate the filmography of 5 movies for {actor}.",
// textSpec -> textSpec.param("actor", "Tom Hanks")
// )
// )
// ).execute();
// ActorsFilmsRecord actorsFilms = fluentChatClient.chat()
// .user()
// .text("Generate the filmography of 5 movies for {actor}.")
// .param("actor", "Tom Hanks")
// .and()
// .and()
// .execute();
//
//
//
// ActorsFilmsRecord actorsFilms = new FluentChatClient().chat()
// .user(userSpec -> userSpec
// .text("Generate the filmography of 5 movies for {actor}.",
// textSpec -> textSpec.param("actor", "Tom Hanks").params(Map.of()) ) })
// .media(mediaSpec -> {
// mediaSpec.param(myImage, MimeTypeUtils.IMAGE_PNG);
// })
// )
// .execute();
//
// System.out.println(actorsFilms);
}
record ActorsFilmsRecord(String actor, List<String> movies) {
}
}

View File

@@ -1,86 +0,0 @@
package org.springframework.ai.openai.chat;
import org.junit.jupiter.api.Test;
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.FluentChatClientLambda;
import org.springframework.ai.openai.OpenAiTestConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest(classes = OpenAiTestConfiguration.class)
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class OpenAiChatClientSpecLambdaIT {
@Autowired
private ChatClient chatClient;
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientSpecLambdaIT.class);
@Test
void simpleTest() {
FluentChatClientLambda fluentChatClient = new FluentChatClientLambda(chatClient);
ActorsFilmsRecord2 actorsFilms =
fluentChatClient.chat(chatSpec ->
chatSpec.user(chatUserSpec ->
chatUserSpec.text("Generate the filmograph of 5 movies for {actor}",
chatParamSpec -> chatParamSpec.param("actor", "Tom")))
// .user()
// .text("Generate the filmography of 5 movies for {actor}.")
// .param("actor", "Tom Hanks")
// .and()
// .and()
// .execute();
// ActorsFilmsRecord actorsFilms = new FluentChatClient().chat(
// chatSpec -> chatSpec
// .user(userSpec -> userSpec.text("Generate the filmography of 5 movies for {actor}.",
// textSpec -> textSpec.param("actor", "Tom Hanks"))
// )
// .execute());
// ActorsFilmsRecord actorsFilms = new FluentChatClient().chat(chatSpec ->
// chatSpec.user(userSpec ->
// userSpec.text("Generate the filmography of 5 movies for {actor}.",
// textSpec -> textSpec.param("actor", "Tom Hanks")
// )
// )
// ).execute();
// ActorsFilmsRecord actorsFilms = fluentChatClient.chat()
// .user()
// .text("Generate the filmography of 5 movies for {actor}.")
// .param("actor", "Tom Hanks")
// .and()
// .and()
// .execute();
//
//
//
// ActorsFilmsRecord actorsFilms = new FluentChatClient().chat()
// .user(userSpec -> userSpec
// .text("Generate the filmography of 5 movies for {actor}.",
// textSpec -> textSpec.param("actor", "Tom Hanks").params(Map.of()) ) })
// .media(mediaSpec -> {
// mediaSpec.param(myImage, MimeTypeUtils.IMAGE_PNG);
// })
// )
// .execute();
//
// System.out.println(actorsFilms);
// }
record ActorsFilmsRecord2(String actor, List<String> movies) {
}
}