Replies: 3 comments
-
🤖 Hello, The error you're encountering is due to the fact that the input you're providing exceeds the maximum token limit of the model. In your case, you're supplying 5441 tokens, while the maximum limit is 4096 tokens. To resolve this issue, you can use the from llama_index.text_splitter import TokenTextSplitter
# Your input text
text = "Your very long text..."
# Create a text splitter
text_splitter = TokenTextSplitter(chunk_size=100, chunk_overlap=0)
# Split the text into chunks
chunks = text_splitter.split_text(text)
# Now you can process each chunk separately
for chunk in chunks:
# Your processing code here
pass Please replace In the context shared, there are also examples of how to use the You can find more details about this in the LlamaIndex repository: I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
how can i set the limit when doing inquiry query_engine = index.as_query_engine() ModelError: Your input is too long. Max input length is 4096 tokens, but you supplied 5086 tokens. |
Beta Was this translation helpful? Give feedback.
-
🤖 Hello, Based on the error message you're encountering, it seems like the input you're trying to process exceeds the maximum token limit. You're correct in considering the use of Here's an example of how you can use from llama_index.text_splitter.token_splitter import TokenTextSplitter
from tiktoken import get_encoding
# Create an instance of the TokenTextSplitter class
splitter = TokenTextSplitter(chunk_size=4096, chunk_overlap=20, tokenizer=get_encoding("gpt2").encode)
# Your text
text = "Your long text goes here..."
# Split the text into smaller chunks
chunks = splitter.split_text(text)
# Now you can process each chunk separately
for chunk in chunks:
# Perform your inquiry here...
pass In this example, the text is split into chunks of 4096 tokens each, with an overlap of 20 tokens between each chunk. You can adjust these parameters according to your needs. The If you're dealing with large documents, you might also consider splitting your documents into smaller chunks before passing them to the from llama_index.schema import Document
def split_document(document: Document, chunk_size: int):
text = document.text
chunks = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
return [Document(text=chunk, metadata=document.metadata) for chunk in chunks]
# Assume `documents` is your list of large documents
smaller_documents = []
for document in documents:
smaller_documents.extend(split_document(document, chunk_size=1000))
index = VectorStoreIndex.from_documents(smaller_documents) In this example, I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Question Validation
Question
ModelError: Your input is too long. Max input length is 4096 tokens, but you supplied 5441 tokens.]
how to fix this,,
Beta Was this translation helpful? Give feedback.
All reactions