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

Implement contextScope, and remove undefined #211

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
16 changes: 12 additions & 4 deletions java/src/main/java/com/xebia/functional/xef/java/auto/AIScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ public AIScope() {
this(new ObjectMapper(), new OpenAIConfig(), Executors.newCachedThreadPool(new AIScopeThreadFactory()));
}

private <T> T undefined() {
throw new RuntimeException("Method is undefined");
private AIScope(CoreAIScope nested, AIScope outer) {
this.om = outer.om;
this.executorService = outer.executorService;
this.coroutineScope = outer.coroutineScope;
this.schemaGen = outer.schemaGen;
this.client = outer.client;
this.scope = nested;
}

public <A> CompletableFuture<A> prompt(String prompt, Class<A> cls) {
Expand Down Expand Up @@ -107,8 +112,11 @@ public CompletableFuture<List<String>> promptMessage(String prompt, LLMModel llm
return future(continuation -> scope.promptMessage(prompt, llmModel, functions, user, echo, n, temperature, bringFromContext, minResponseTokens, continuation));
}

public <T> CompletableFuture<T> contextScope(List<String> docs) {
return future(continuation -> scope.contextScopeWithDocs(docs, undefined(), continuation));
public <A> CompletableFuture<A> contextScope(List<String> docs, Function1<AIScope, CompletableFuture<A>> f) {
return future(continuation -> scope.contextScopeWithDocs(docs, (coreAIScope, continuation1) -> {
AIScope nestedScope = new AIScope(coreAIScope, AIScope.this);
return FutureKt.await(f.invoke(nestedScope), continuation);
}, continuation));
}

public CompletableFuture<List<String>> pdf(String url, TextSplitter splitter) {
Expand Down