Skip to content

Commit

Permalink
Merge pull request #45 from johnoliver/format
Browse files Browse the repository at this point in the history
Apply code formatting rules defined in spotless
  • Loading branch information
dantelmomsft authored Oct 27, 2023
2 parents 8d1af37 + ef534b5 commit 840d57a
Show file tree
Hide file tree
Showing 50 changed files with 2,793 additions and 2,552 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag;

import org.slf4j.Logger;
Expand All @@ -11,7 +12,9 @@ public class Application {
private static final Logger LOG = LoggerFactory.getLogger(Application.class);

public static void main(String[] args) {
LOG.info("Application profile from system property is [{}]", System.getProperty("spring.profiles.active"));
LOG.info(
"Application profile from system property is [{}]",
System.getProperty("spring.profiles.active"));
new SpringApplication(Application.class).run(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package com.microsoft.openai.samples.rag.approaches;

public class ContentSource {

private String sourceName;
private String sourceContent;
private final boolean noNewLine;

public ContentSource(String sourceName, String sourceContent, Boolean noNewLine) {
this.noNewLine = noNewLine;
this.sourceName = sourceName;
buildContent(sourceContent);
}

public ContentSource(String sourceName, String sourceContent) {
this(sourceName, sourceContent, true);
}

public String getSourceName() {
return sourceName;
}

public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}

public String getSourceContent() {
return sourceContent;
}

public void setSourceContent(String sourceContent) {
this.sourceContent = sourceContent;
}

public boolean isNoNewLine() {
return noNewLine;
}

private void buildContent(String sourceContent) {
if (this.noNewLine) {
this.sourceContent = sourceContent.replace("\n", "");
}
}

}
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag.approaches;

public class ContentSource {

private String sourceName;
private String sourceContent;
private final boolean noNewLine;

public ContentSource(String sourceName, String sourceContent, Boolean noNewLine) {
this.noNewLine = noNewLine;
this.sourceName = sourceName;
buildContent(sourceContent);
}

public ContentSource(String sourceName, String sourceContent) {
this(sourceName, sourceContent, true);
}

public String getSourceName() {
return sourceName;
}

public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}

public String getSourceContent() {
return sourceContent;
}

public void setSourceContent(String sourceContent) {
this.sourceContent = sourceContent;
}

public boolean isNoNewLine() {
return noNewLine;
}

private void buildContent(String sourceContent) {
if (this.noNewLine) {
this.sourceContent = sourceContent.replace("\n", "");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.microsoft.openai.samples.rag.approaches;

public interface PromptTemplate {

String getPrompt();

void setVariables();

}
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag.approaches;

public interface PromptTemplate {

String getPrompt();

void setVariables();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.microsoft.openai.samples.rag.approaches;

import com.microsoft.openai.samples.rag.common.ChatGPTConversation;
import reactor.core.publisher.Flux;

import java.io.OutputStream;

public interface RAGApproach<I, O> {

O run(I questionOrConversation, RAGOptions options);
void runStreaming(I questionOrConversation, RAGOptions options, OutputStream outputStream);
}
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag.approaches;

import java.io.OutputStream;

public interface RAGApproach<I, O> {

O run(I questionOrConversation, RAGOptions options);

void runStreaming(I questionOrConversation, RAGOptions options, OutputStream outputStream);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag.approaches;

public interface RAGApproachFactory<I, O> {

RAGApproach<I, O> createApproach(String approachName, RAGType ragType, RAGOptions options);

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.openai.samples.rag.approaches;

import com.microsoft.openai.samples.rag.ask.approaches.PlainJavaAskApproach;
import com.microsoft.openai.samples.rag.ask.approaches.semantickernel.JavaSemanticKernelChainsApproach;
import com.microsoft.openai.samples.rag.ask.approaches.semantickernel.JavaSemanticKernelWithMemoryApproach;
import com.microsoft.openai.samples.rag.ask.approaches.semantickernel.JavaSemanticKernelPlannerApproach;
import com.microsoft.openai.samples.rag.ask.approaches.semantickernel.JavaSemanticKernelWithMemoryApproach;
import com.microsoft.openai.samples.rag.chat.approaches.PlainJavaChatApproach;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class RAGApproachFactorySpringBootImpl implements RAGApproachFactory, ApplicationContextAware {
public class RAGApproachFactorySpringBootImpl
implements RAGApproachFactory, ApplicationContextAware {

private static final String JAVA_OPENAI_SDK = "jos";
private static final String JAVA_SEMANTIC_KERNEL = "jsk";
Expand All @@ -35,18 +37,23 @@ public RAGApproach createApproach(String approachName, RAGType ragType, RAGOptio
return applicationContext.getBean(PlainJavaAskApproach.class);
else if (JAVA_SEMANTIC_KERNEL.equals(approachName))
return applicationContext.getBean(JavaSemanticKernelWithMemoryApproach.class);
else if (JAVA_SEMANTIC_KERNEL_PLANNER.equals(approachName) && ragOptions.getSemantickKernelMode() != null && ragOptions.getSemantickKernelMode() == SemanticKernelMode.planner)
return applicationContext.getBean(JavaSemanticKernelPlannerApproach.class);
else if(JAVA_SEMANTIC_KERNEL_PLANNER.equals(approachName) && ragOptions != null && ragOptions.getSemantickKernelMode() != null && ragOptions.getSemantickKernelMode() == SemanticKernelMode.chains)
return applicationContext.getBean(JavaSemanticKernelChainsApproach.class);

else if (JAVA_SEMANTIC_KERNEL_PLANNER.equals(approachName)
&& ragOptions.getSemantickKernelMode() != null
&& ragOptions.getSemantickKernelMode() == SemanticKernelMode.planner)
return applicationContext.getBean(JavaSemanticKernelPlannerApproach.class);
else if (JAVA_SEMANTIC_KERNEL_PLANNER.equals(approachName)
&& ragOptions != null
&& ragOptions.getSemantickKernelMode() != null
&& ragOptions.getSemantickKernelMode() == SemanticKernelMode.chains)
return applicationContext.getBean(JavaSemanticKernelChainsApproach.class);
}
//if this point is reached then the combination of approach and rag type is not supported
throw new IllegalArgumentException("Invalid combination for approach[%s] and rag type[%s]: ".formatted(approachName, ragType));
// if this point is reached then the combination of approach and rag type is not supported
throw new IllegalArgumentException(
"Invalid combination for approach[%s] and rag type[%s]: "
.formatted(approachName, ragType));
}

public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

}
Loading

0 comments on commit 840d57a

Please sign in to comment.