Skip to content

Commit

Permalink
Remove automatic context RAG lookup (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulraja authored Jun 6, 2024
1 parent f7eccf1 commit 0920656
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<Memory> =
Expand All @@ -38,33 +33,7 @@ internal object PromptCalculator {

val historyAllowed = calculateMessagesFromHistory(prompt, memories, maxHistoryTokens)

// calculate messages for context based on tokens
val ctxInfo: List<String> =
scope.store.similaritySearch(
prompt.messages.joinToString("\n") { it.contentAsString() ?: "" },
prompt.configuration.docsInContext,
)

val contextAllowed: List<ChatCompletionRequestMessage> =
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<Memory>): List<ChatCompletionRequestMessage> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0920656

Please sign in to comment.