from llama_index.llms import Replicate
llama2_7b_chat = "meta/llama-2-7b-chat:8e6975e5ed6174911a6ff3d60540dfd4844201974602551e10e9e87ab143d81e"
llm = Replicate(
model=llama2_7b_chat,
temperature=0.01,
additional_kwargs={"top_p": 1, "max_new_tokens": 300},
)
# set tokenizer to match LLM
from llama_index import set_global_tokenizer
from transformers import AutoTokenizer
set_global_tokenizer(AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf").encode)
from llama_index.embeddings import HuggingFaceEmbedding
from llama_index import ServiceContext
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
from llama_index import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
repair_job_engine = index.as_query_engine(similarity_top_k=3)
from llama_index.tools import QueryEngineTool
from llama_index.tools import ToolMetadata
query_engine_tools = [
QueryEngineTool(
query_engine=repair_job_engine,
metadata=ToolMetadata(
name="query_specified_repair_jobs",
description="Provides information about repair jobs in detail "
)
)
]
from llama_index.agent import ReActAgent
agent = ReActAgent.from_tools(
query_engine_tools,
llm=llm,
verbose=True,
# context=context
response = agent.chat("What are the main failure modes in the file? ")
print(str(response))
)
I get:
Thought: I need to use a tool to help me answer the question.
Action: tool
Action Input: {'input': 'hello world', 'num_beams': 5}
KeyError: 'tool'
I think I strictly follow the guide, and try to use agent to answer some questions in the file loaded. I also specify the tool for the ReActAgent, but it seems the chat function doesn't recognize the tool I specified. Can someone help?