From 005eda8b9b1283b9baea2dc8ca40a4fb948ee677 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 29 Jun 2023 08:36:40 +0200 Subject: [PATCH] Fix contextScope, and remove undefined (#211) --- .../xebia/functional/xef/java/auto/AIScope.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/java/src/main/java/com/xebia/functional/xef/java/auto/AIScope.java b/java/src/main/java/com/xebia/functional/xef/java/auto/AIScope.java index 0819f41fa..674cbce27 100644 --- a/java/src/main/java/com/xebia/functional/xef/java/auto/AIScope.java +++ b/java/src/main/java/com/xebia/functional/xef/java/auto/AIScope.java @@ -68,8 +68,13 @@ public AIScope() { this(new ObjectMapper(), new OpenAIConfig(), Executors.newCachedThreadPool(new AIScopeThreadFactory())); } - private 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 CompletableFuture prompt(String prompt, Class cls) { @@ -107,8 +112,11 @@ public CompletableFuture> promptMessage(String prompt, LLMModel llm return future(continuation -> scope.promptMessage(prompt, llmModel, functions, user, echo, n, temperature, bringFromContext, minResponseTokens, continuation)); } - public CompletableFuture contextScope(List docs) { - return future(continuation -> scope.contextScopeWithDocs(docs, undefined(), continuation)); + public CompletableFuture contextScope(List docs, Function1> 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> pdf(String url, TextSplitter splitter) {