From 0920656dfe4555eedd7d8e04d66a6a9171a549a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Raja=20Mart=C3=ADnez?= Date: Thu, 6 Jun 2024 09:34:52 +0200 Subject: [PATCH] Remove automatic context RAG lookup (#755) --- .../functional/xef/llm/PromptCalculator.kt | 33 +------------------ .../configuration/PromptConfiguration.kt | 1 - 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/PromptCalculator.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/PromptCalculator.kt index b50051eee..f8053056f 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/PromptCalculator.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/PromptCalculator.kt @@ -1,14 +1,11 @@ package com.xebia.functional.xef.llm import com.xebia.functional.openai.generated.model.ChatCompletionRequestMessage -import com.xebia.functional.tokenizer.truncateText import com.xebia.functional.xef.AIError import com.xebia.functional.xef.conversation.Conversation import com.xebia.functional.xef.conversation.MessagesFromHistory import com.xebia.functional.xef.llm.models.modelType import com.xebia.functional.xef.prompt.Prompt -import com.xebia.functional.xef.prompt.PromptBuilder.Companion.assistant -import com.xebia.functional.xef.prompt.contentAsString import com.xebia.functional.xef.store.Memory internal object PromptCalculator { @@ -26,8 +23,6 @@ internal object PromptCalculator { val maxHistoryTokens = calculateMaxHistoryTokens(prompt, remainingTokensForContexts) - val maxContextTokens = calculateMaxContextTokens(prompt, remainingTokensForContexts) - // calculate messages for history based on tokens val memories: List = @@ -38,33 +33,7 @@ internal object PromptCalculator { val historyAllowed = calculateMessagesFromHistory(prompt, memories, maxHistoryTokens) - // calculate messages for context based on tokens - val ctxInfo: List = - scope.store.similaritySearch( - prompt.messages.joinToString("\n") { it.contentAsString() ?: "" }, - prompt.configuration.docsInContext, - ) - - val contextAllowed: List = - if (ctxInfo.isNotEmpty()) { - val ctx: String = ctxInfo.joinToString("\n") - - val ctxTruncated: String = - prompt.model.modelType().encodingType.encoding.truncateText(ctx, maxContextTokens) - - Prompt( - model = prompt.model, - functions = prompt.functions, - configuration = prompt.configuration - ) { - +assistant(ctxTruncated) - } - .messages - } else { - emptyList() - } - - return prompt.copy(messages = contextAllowed + historyAllowed + prompt.messages) + return prompt.copy(messages = historyAllowed + prompt.messages) } private fun messagesFromMemory(memories: List): List = diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/configuration/PromptConfiguration.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/configuration/PromptConfiguration.kt index b8d42db2b..3a8f05e53 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/configuration/PromptConfiguration.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/configuration/PromptConfiguration.kt @@ -14,7 +14,6 @@ constructor( var user: String = ChatCompletionRole.user.value, var temperature: Double = 0.4, var numberOfPredictions: Int = 1, - var docsInContext: Int = 5, var maxTokens: Int = 500, var messagePolicy: MessagePolicy = MessagePolicy(), var seed: Int? = null,