Langchain predict function call parsing error

291 views Asked by At
if topic:
    llm = GooglePalm(google_api_key=google_api_key)
    llm.temperature = 0.1
    template = "Tell me reasons why I am having these symptoms {topic}.
    prompt = PromptTemplate.from_template(template)
    chain = LLMChain(llm=llm, prompt = prompt)
    try:
        chain.predict(topic=topic)
    except Exception as e:
        print(f"Error during chain running: {e}")
        return "An error occurred while processing the chain."

I am getting Error during chain running: list index out of range when it runs chain.predict(topic=topic)? It is coming from this output parser that langchain is using:

/langchain/schema/output_parser.py", line 226, in parse_result return self.parse(result[0].text) ~~~~~~^^^ IndexError: list index out of range

Why is this the case?

It should just output some text but it is unable to parse it using the predict function.

2

There are 2 answers

0
Vikasha Consultancy On

Try to recreate your vector db reducing the chunk size and overlap. That worked for me.

<Kindly ignore the above answer given - It is not correct answer to this problem>

As pointed out by other contributors - take a look at the safety settings in the Palm API

0
Ash Ishh On

Google Palm is blocking your query due to safety reason.

Google Palm's response:

{
  "filters": [
    {
      "reason": "SAFETY"
    }
  ],
  "safetyFeedback": [
    {
      "rating": {
        "category": "HARM_CATEGORY_MEDICAL",
        "probability": "HIGH"
      },
      "setting": {
        "category": "HARM_CATEGORY_MEDICAL",
        "threshold": "BLOCK_MEDIUM_AND_ABOVE"
      }
    }
  ]
}

I have raised the issue on langchain for relaying the correct error message of Google Palm.

Meanwhile you can test your basic prompts through curl like this to see what Google Palm is sending as response:

curl -H 'Content-Type: application/json' -d '{ "prompt": { "text": "Tell me reasons why I am having symptoms of cold"} }' "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key={PASTE_YOUR_KEY_HERE}