Skip to content
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

Allow using langchain4j module #11273

Merged
merged 12 commits into from
Nov 7, 2024
Merged

Conversation

anunnakian
Copy link
Member

@anunnakian anunnakian commented Nov 1, 2024

I add langchain4j support by using langchain4j-spring-starter dependency (version: 0.35.0)

It fixes #9298

@CLAassistant
Copy link

CLAassistant commented Nov 1, 2024

CLA assistant check
All committers have signed the CLA.

@anunnakian
Copy link
Member Author

anunnakian commented Nov 1, 2024

@pascalgrimaud @jdubois what do you think about these changes

@anunnakian anunnakian changed the title Add langchain4j support Allow using langchain4j module Nov 2, 2024
@anunnakian anunnakian marked this pull request as ready for review November 2, 2024 16:54
@@ -0,0 +1,5 @@
# LangChain4J
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# LangChain4J
# LangChain4j

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I do that mistake all the time!!!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CamelCase syndrome 😄

@pascalgrimaud
Copy link
Member

In another PR, I would add a new module sample-langchain4j-controller, with something like:

import dev.langchain4j.model.chat.ChatLanguageModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
class ChatController {

  private final ChatLanguageModel chatLanguageModel;

  public ChatController(ChatLanguageModel chatLanguageModel) {
    this.chatLanguageModel = chatLanguageModel;
  }

  @GetMapping("/chat")
  public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
    return chatLanguageModel.generate(message);
  }
}

So it will help the user to test it (similar to the documentation):

image

@jdubois
Copy link
Member

jdubois commented Nov 5, 2024

Super happy to see this! As I'm mostly using Azure OpenAI and GitHub Models, I'll need to have a look at adding those on top of this PR.

@anunnakian
Copy link
Member Author

anunnakian commented Nov 6, 2024

In another PR, I would add a new module sample-langchain4j-controller, with something like:

import dev.langchain4j.model.chat.ChatLanguageModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
class ChatController {

  private final ChatLanguageModel chatLanguageModel;

  public ChatController(ChatLanguageModel chatLanguageModel) {
    this.chatLanguageModel = chatLanguageModel;
  }

  @GetMapping("/chat")
  public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
    return chatLanguageModel.generate(message);
  }
}

So you'll have to make langChain4j module dependent on spring-boot-mvc-empty because you'll need rest dependency

@pascalgrimaud
Copy link
Member

In another PR, I would add a new module sample-langchain4j-controller, with something like:

import dev.langchain4j.model.chat.ChatLanguageModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
class ChatController {

  private final ChatLanguageModel chatLanguageModel;

  public ChatController(ChatLanguageModel chatLanguageModel) {
    this.chatLanguageModel = chatLanguageModel;
  }

  @GetMapping("/chat")
  public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
    return chatLanguageModel.generate(message);
  }
}

So you'll have to make langChain4j module dependent on spring-boot-mvc-empty because you'll need rest dependency

exactly @anunnakian :-)

@pascalgrimaud pascalgrimaud merged commit 10966ba into jhipster:main Nov 7, 2024
35 checks passed
@pascalgrimaud
Copy link
Member

Thanks a lot for your contribution @anunnakian !

@anunnakian anunnakian deleted the langchain4j branch November 7, 2024 08:53
@anunnakian
Copy link
Member Author

@pascalgrimaud
Copy link
Member

@anunnakian : approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Module: LangChain4j
5 participants