zesla
zesla

Reputation: 11833

Validation errors for LLMChain when use langchain/openai for text generation

I just started learning langchain. I was trying to use langchain and openai for text generation. Codes below. (I use python 3.10):

#openai==1.3.5
#langchain==0.0.345

from transformers import pipeline
from langchain import PromptTemplate, LLMChain, OpenAI

import os
os.environ['OPENAI_API_KEY'] = '*****'

def generate_story (scenario):
  template = ''' 
          You are a story teller. Please make a story based on the context below:
          CONTEXT: {scenario}
          STORY: 
  '''

  prompt = PromptTemplate (template = template, input_variables = ['scenario'])
  story_llm = LLMChain(LLM = OpenAI(
       model_name = 'gpt-3.5-turbo',
       temperature = 1),
        prompt = prompt
  )
  story = story_llm.predict(scenario = scenario)
  print(story)
  return story


scenario = 'A person is skiing down a snowy slope.'
story = generate_story (scenario)
print(story)

However, I got errors like below:

/usr/local/lib/python3.10/dist-packages/pydantic/main.cpython-310-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()

ValidationError: 2 validation errors for LLMChain
llm
  field required (type=value_error.missing)
LLM
  extra fields not permitted (type=value_error.extra)

Spent hours trying to find out why but could not figure that out. Does anyone know what went wrong? Thanks in advance.

Upvotes: 0

Views: 3087

Answers (1)

Bryce Guinta
Bryce Guinta

Reputation: 3742

Python arguments are case sensitive (unless made otherwise). lower case the keyword to your keyword argument:

LLMChain(llm = OpenAI(
----------↑-----------

Your keyword to LLMChain is uppercase when it should be lower case

Upvotes: 1

Related Questions