run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.21k stars 5.16k forks source link

Agent enters infinite loop , even max_iteration=3 wont work #14071

Closed nikhitaKanoj closed 4 months ago

nikhitaKanoj commented 4 months ago

Question Validation

Question

from langchain_experimental.agents.agent_toolkits import create_csv_agent import streamlit as st import os import tempfile

from langchain_community.llms import CTranslate2 model_id = 'NHL2-13b-chat-Llama2-ct2' tokenizer_id = 'Nous-Hermes-Llama2-13b' llm=CTranslate2(model_path=model_id,tokenizer_name=tokenizer_id,device="auto",compute_type="int8

def main():

Configure Streamlit page

st.set_page_config(page_title="Ask your CSV")
st.header("Ask your CSV")

# Allow the user to upload a CSV file
file = st.file_uploader("upload file", type="csv")

if file is not None:
    # Create a temporary file to store the uploaded CSV data
    with tempfile.NamedTemporaryFile(mode='w+', suffix=".csv", delete=False) as f:
        # Convert bytes to a string before writing to the file
        data_str = file.getvalue().decode('utf-8')
        f.write(data_str)
        f.flush()
        llm =llm

        # Ask the user to input a question
        user_input = st.text_input("Question here:")

        # Create a CSV agent using the OpenAI language model and the temporary file
        agent = create_csv_agent(llm, f.name, verbose=True,agent_executor_kwargs={"handle_parsing_error":True} )

        if user_input:
            # Run the agent on the user's question and get the response
            response = agent.run(user_input)
            st.write(response)

if name == "main": main()

When I execute this code , I can upload the file and ask a question , it outputs the result in terminal and then continues to loop back , I have tried max_iteration=2 -- this runs 2 times giving output 2 times in terminal and ends with error like Agent terminated because it reached max iterations

logan-markewich commented 4 months ago

@nikhitaKanoj this is a question about langchain, but this is the llamaindex repo. Better to ask in a langchain location :)