Skip to content

Commit

Permalink
Private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
javipacheco committed Aug 18, 2023
1 parent 9c23a76 commit 4befcc0
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ internal object PromptCalculator {
return prompt.copy(messages = contextAllowed + historyAllowed + prompt.messages)
}

fun messagesFromMemory(memories: List<Memory>): List<Message> = memories.map { it.content }

fun calculateMessagesFromHistory(chat: Chat, memories: List<Memory>, maxHistoryTokens: Int) =
private fun messagesFromMemory(memories: List<Memory>): List<Message> =
memories.map { it.content }

private fun calculateMessagesFromHistory(
chat: Chat,
memories: List<Memory>,
maxHistoryTokens: Int
) =
if (memories.isNotEmpty()) {
val history = messagesFromMemory(memories)

Expand All @@ -77,19 +82,19 @@ internal object PromptCalculator {
}
} else emptyList()

fun calculateMaxContextTokens(prompt: Prompt, remainingTokensForContexts: Int): Int {
private fun calculateMaxContextTokens(prompt: Prompt, remainingTokensForContexts: Int): Int {
val contextPercent = prompt.configuration.messagePolicy.contextPercent
val maxContextTokens = (remainingTokensForContexts * contextPercent) / 100
return maxContextTokens
}

fun calculateMaxHistoryTokens(prompt: Prompt, remainingTokensForContexts: Int): Int {
private fun calculateMaxHistoryTokens(prompt: Prompt, remainingTokensForContexts: Int): Int {
val historyPercent = prompt.configuration.messagePolicy.historyPercent
val maxHistoryTokens = (remainingTokensForContexts * historyPercent) / 100
return maxHistoryTokens
}

fun calculateRemainingTokensForContext(chat: Chat, prompt: Prompt): Int {
private fun calculateRemainingTokensForContext(chat: Chat, prompt: Prompt): Int {
val maxContextLength: Int = chat.modelType.maxContextLength
val remainingTokens: Int = maxContextLength - prompt.configuration.minResponseTokens

Expand Down

0 comments on commit 4befcc0

Please sign in to comment.