fix bug for truncation ensuring no valid inputs are sent to openai

This commit is contained in:
KCaverly 2023-08-30 17:42:16 -04:00
parent 5abad58b0d
commit 7d4d6c871b
2 changed files with 9 additions and 9 deletions

View file

@ -78,15 +78,13 @@ impl EmbeddingProvider for DummyEmbeddings {
let token_count = tokens.len();
let output = if token_count > OPENAI_INPUT_LIMIT {
tokens.truncate(OPENAI_INPUT_LIMIT);
OPENAI_BPE_TOKENIZER
.decode(tokens)
.ok()
.unwrap_or_else(|| span.to_string())
let new_input = OPENAI_BPE_TOKENIZER.decode(tokens.clone());
new_input.ok().unwrap_or_else(|| span.to_string())
} else {
span.to_string()
};
(output, token_count)
(output, tokens.len())
}
}
@ -120,7 +118,7 @@ impl OpenAIEmbeddings {
#[async_trait]
impl EmbeddingProvider for OpenAIEmbeddings {
fn max_tokens_per_batch(&self) -> usize {
OPENAI_INPUT_LIMIT
50000
}
fn truncate(&self, span: &str) -> (String, usize) {