Error: This model's maximum context length is 4097 tokens. However, your messages resulted in 4318 tokens (2877 in the messages, 1441 in the functions). Please reduce the length of the messages or functions.
_memory = ChatMemoryBuffer.from_defaults(
token_limit=2000, chat_history=chat_history
)
self._user_id = user_id
self.project_id = index_dir
self._tools = {tool.metadata.name: tool for tool in tools}
_vector_store = FaissVectorStore.from_persist_dir(
f"./llama_index/{index_dir}"
)
_storage_context = StorageContext.from_defaults(
vector_store=_vector_store,
persist_dir=f"./llama_index/{index_dir}",
)
_index = load_index_from_storage(storage_context=_storage_context)
_memory = ChatMemoryBuffer.from_defaults(
token_limit=1000, chat_history=chat_history
)
similarity_top_k = 7
_retriever = VectorIndexRetriever(
index=_index, similarity_top_k=similarity_top_k
)
_query_engine = RetrieverQueryEngine(retriever=_retriever)
query_engine_tool = QueryEngineTool.from_defaults(
query_engine=_query_engine,
)
_all_tools = [query_engine_tool]
for tool in tools:
_all_tools.append(tool)
self.token_counter = TokenCountingHandler(
tokenizer=tiktoken.encoding_for_model("gpt-3.5-turbo").encode,
)
callback_manager = CallbackManager([self.token_counter])
self._agent = OpenAIAgent.from_tools(
_all_tools,
llm=llm,
callback_manager=callback_manager,
memory=_memory,
system_prompt=TEXT_QA_SYSTEM_PROMPT.content,
)
self._chat_history = chat_history
Error: This model's maximum context length is 4097 tokens. However, your messages resulted in 4115 tokens (1949 in the messages, 2166 in the functions). Please reduce the length of the messages or functions.