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

Remove automatic context RAG lookup #755

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
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
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
Loading