-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seeking feedback #1
Comments
Regarding https://speakerdeck.com/michaelisvy/spring-ai-vs-langchain4j?slide=37: did you consider using high-level AI Services? They integrate nicely into Spring Boot application, here are few examples: |
hi @langchain4j , Hope that helps :) |
@michaelisvy thank you for taking the time to provide feedback, I really appreciate! Would you mind elaborating a bit further? I'd love to better understand which specific aspects you found complicated. There are currently 2 ways to implement this in LC4J: Using AI Serviceslangchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.chat-model.model-name=gpt-4o-mini @AiService
public interface ActorFilmsGenerator {
ActorFilms generate(String query);
} @RestController
public class ActorFilmsController {
private final ActorFilmsGenerator actorFilmsGenerator;
public ActorFilmsController(ActorFilmsGenerator actorFilmsGenerator) {
this.actorFilmsGenerator = actorFilmsGenerator;
}
@GetMapping("/generateActorFilms")
public ActorFilms generateActorFilms() {
return actorFilmsGenerator.generate("Generate the 10 most popular movies starring Bruce Willis");
}
} Using low-level APIlangchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.chat-model.model-name=gpt-4o-mini @RestController
public class ActorFilmsController {
private final ChatLanguageModel chatModel;
public ActorFilmsController(ChatLanguageModel chatModel) {
this.chatModel = chatModel;
}
@GetMapping("/generateActorFilms")
public String generateActorFilms() {
ChatRequest chatRequest = ChatRequest.builder()
.messages(UserMessage.from("Generate the 10 most popular movies starring Bruce Willis"))
.responseFormat(ResponseFormat.builder()
.type(JSON)
.jsonSchema(JsonSchemas.jsonSchemaFrom(ActorFilms.class).get())
.build())
.build();
ChatResponse chatResponse = chatModel.chat(chatRequest);
return chatResponse.aiMessage().text();
}
} |
understood thanks! I had missed it from the documentation, I'll add it to my sample application. By the way, one small other thing which I thought was missing: I didn't find a way to load an image from th classpath. See here: https://speakerdeck.com/michaelisvy/spring-ai-vs-langchain4j?slide=33 Cheers, |
@michaelisvy sure, this can be done as well: @Service
class ImageService {
@Value("classpath:images/scientist.jpg")
private Resource imageResourceScientist;
private final ChatLanguageModel chatModel;
public ImageService(ChatLanguageModel chatModel) {
this.chatModel = chatModel;
}
public String describeScientist() throws IOException {
UserMessage userMessage = UserMessage.from(
TextContent.from("can you describe this person? And what is written on top of his head?"),
ImageContent.from(encodeInBase64(imageResourceScientist), "image/jpg")
);
ChatResponse chatResponse = chatModel.chat(ChatRequest.builder().messages(userMessage).build());
return chatResponse.aiMessage().text();
}
private String encodeInBase64(Resource resource) throws IOException {
return Base64.getEncoder().encodeToString(resource.getContentAsByteArray());
}
} Thank you for pointing this out, I will add more examples to the documentation! |
thanks a lot for your help @langchain4j ! I implemented all the changes you suggested. Only thing I couldn't do is this:
It seems that returning a collection of objects is not yet supported? (I couldn't find any information on it). Regards, |
@michaelisvy great, thanks a lot! Yes, returning a record Books(List<Book> books) {}
interface BookExtractor {
Books generateAll(String query);
} |
Do you mind If I'll submit a PR to implement a |
I have opened #2, I hope you don't mind |
Hi @michaelisvy, sorry for pinging you here - I couldn’t find another way to reach out. I hope you don’t mind.
I came across https://speakerdeck.com/michaelisvy/spring-ai-vs-langchain4j?slide=20 and wanted to get some feedback, especially on the "Support for Entities" category. Could you please share what problems you encountered there?
Thank you!
The text was updated successfully, but these errors were encountered: