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

Refactoring LangChain4j #11342

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package tech.jhipster.lite.generator.server.springboot.langchain4j.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.server.springboot.langchain4j.domain.LangChain4JModuleFactory;
import tech.jhipster.lite.generator.server.springboot.langchain4j.domain.LangChain4jModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class LangChain4JApplicationService {
public class LangChain4jApplicationService {

private final LangChain4JModuleFactory factory;
private final LangChain4jModuleFactory factory;

public LangChain4JApplicationService() {
factory = new LangChain4JModuleFactory();
public LangChain4jApplicationService() {
factory = new LangChain4jModuleFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

public class LangChain4JModuleFactory {
public class LangChain4jModuleFactory {

private static final String API_KEY_DEMO_COMMENT =
"You can temporarily use 'demo' key, which is provided for free for demonstration purposes";
Expand All @@ -30,13 +30,13 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {

//@formatter:off
return moduleBuilder(properties)
.documentation(documentationTitle("Dev tools"), SOURCE.template("langchain4j.md"))
.documentation(documentationTitle("LangChain4j"), SOURCE.template("langchain4j.md"))
.javaDependencies()
.addDependency(GROUP_ID, ARTIFACT_ID, VERSION_SLUG)
.addDependency(GROUP_ID, OPEN_AI_ARTIFACT_ID, VERSION_SLUG)
.and()
.springMainProperties()
.set(LANGCHAIN4J_PROPERTY_API_KEY, propertyValue("${OPENAI_API_KEY}"))
.set(LANGCHAIN4J_PROPERTY_API_KEY, propertyValue("demo"))
.comment(LANGCHAIN4J_PROPERTY_API_KEY, comment(API_KEY_DEMO_COMMENT))
.set(propertyKey("langchain4j.open-ai.chat-model.model-name"), propertyValue("gpt-4o-mini"))
.set(propertyKey("langchain4j.open-ai.chat-model.log-requests"), propertyValue("true"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.server.springboot.langchain4j.application.LangChain4JApplicationService;
import tech.jhipster.lite.generator.server.springboot.langchain4j.application.LangChain4jApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;

@Configuration
class LangChain4JModuleConfiguration {
class LangChain4jModuleConfiguration {

@Bean
JHipsterModuleResource langChain4JModule(LangChain4JApplicationService langChain4J) {
JHipsterModuleResource langChain4jModule(LangChain4jApplicationService langChain4j) {
return JHipsterModuleResource.builder()
.slug(LANGCHAIN4J)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addProjectBaseName().addIndentation().build())
.apiDoc("LangChain4J", "Add LangChain4j")
.apiDoc("LangChain4j", "Add LangChain4j")
.organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT).build())
.tags("server", "spring", "spring-boot", "langchain4j")
.factory(langChain4J::buildModule);
.factory(langChain4j::buildModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

@UnitTest
@ExtendWith(MockitoExtension.class)
class LangChain4JModuleFactoryTest {
class LangChain4jModuleFactoryTest {

@InjectMocks
private LangChain4JModuleFactory factory;
private LangChain4jModuleFactory factory;

@Test
void shouldCreateModule() {
Expand All @@ -29,6 +29,7 @@ void shouldCreateModule() {
JHipsterModule module = factory.buildModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFiles("documentation/langchain4j.md")
.hasFile("pom.xml")
.containing("<langchain4j.version>")
.containing(
Expand Down Expand Up @@ -57,7 +58,7 @@ void shouldCreateModule() {
open-ai:
chat-model:
# You can temporarily use 'demo' key, which is provided for free for demonstration purposes
api-key: ${OPENAI_API_KEY}
api-key: demo
log-requests: 'true'
log-responses: 'true'
model-name: gpt-4o-mini
Expand Down