Skip to content

Commit

Permalink
feat: update example
Browse files Browse the repository at this point in the history
work on #6
  • Loading branch information
bsorrentino committed Jun 19, 2024
1 parent 19b55d7 commit dd746af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import org.bsc.langgraph4j.StateGraph;
import org.bsc.langgraph4j.state.AgentState;

import java.io.FileInputStream;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.LogManager;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -57,6 +59,8 @@ public List<String> documents() {
private final ChromaStore chroma;

public AdaptiveRag( String openApiKey, String tavilyApiKey ) {
Objects.requireNonNull(openApiKey, "no OPENAI APIKEY provided!");
Objects.requireNonNull(tavilyApiKey, "no TAVILY APIKEY provided!");
this.openApiKey = openApiKey;
this.tavilyApiKey = tavilyApiKey;
this.chroma = ChromaStore.of(openApiKey);
Expand Down Expand Up @@ -275,4 +279,29 @@ public CompiledGraph<State> buildGraph() throws Exception {

return workflow.compile();
}

public static void main( String[] args ) throws Exception {
try(FileInputStream configFile = new FileInputStream("logging.properties")) {
LogManager.getLogManager().readConfiguration(configFile);
};

AdaptiveRag adaptiveRagTest = new AdaptiveRag( System.getenv("OPENAI_API_KEY"), System.getenv("TAVILY_API_KEY"));

var graph = adaptiveRagTest.buildGraph();

var result = graph.stream( mapOf( "question", "What player at the Bears expected to draft first in the 2024 NFL draft?" ) );

String generation = "";
for( var r : result ) {
System.out.printf( "Node: '%s':\n", r.node() );

generation = r.state().generation().orElse( "")
;
}

System.out.println( generation );

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,4 @@ public void generationTest() {
System.out.println( result );
}

@Test
public void execute() throws Exception {
AdaptiveRag adaptiveRagTest = new AdaptiveRag(getOpenAiKey(), getTavilyApiKey());

var graph = adaptiveRagTest.buildGraph();

var result = graph.stream( mapOf( "question", "What player at the Bears expected to draft first in the 2024 NFL draft?" ) );

String generation = "";
for( var r : result ) {
System.out.printf( "Node: '%s':\n", r.node() );

generation = r.state().generation().orElse( "")
;
}

System.out.println( generation );

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dev.langchain4j.store.embedding.EmbeddingSearchRequest;
import dev.langchain4j.store.embedding.EmbeddingSearchResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import dev.langchain4j.store.embedding.chroma.ChromaEmbeddingStore;

import java.io.FileInputStream;
Expand Down

0 comments on commit dd746af

Please sign in to comment.