2

I'm trying to create the load_summarize_chain for Langchain using prompts that I created myself.

llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.7)
PROMPT = PromptTemplate(template=prompt_template, input_variables=["text"])
chain = load_summarize_chain(llm, chain_type="refine", verbose=True, prompt=PROMPT)

However, I'm only able to successfully create the chain when the chain_type is set as "stuff". When I try to specify it as "map_reduce" or "refine", I get an error message like the following:

ValidationError: 1 validation error for RefineDocumentsChain
prompt
  extra fields not permitted (type=value_error.extra)

What's wrong with it?

I think it might be because "map_reduce" or "refine" cannot directly specify custom prompts in the load_summarize_chain, or some other reason.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mick
  • 21
  • 1
  • 2
  • Change `prompt=PROMPT` to `refine_prompt=PROMPT`. See this [example](https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html#:~:text=refine_prompt%3Drefine_prompt) – Desmond Apr 14 '23 at 15:33

1 Answers1

2

When your chain_type='map_reduce', The parameter that you should be passing is map_prompt and combine_prompt where your final code will look like

chain = load_summarize_chain(llm, chain_type="map_reduce",verbose=True,map_prompt=PROMPT,combine_prompt=COMBINE_PROMPT)

where PROMPT and COMBINE_PROMPT are custom prompts generated using PromptTemplate

AND When your chain_type='refine', the parameter that you should be passing is refine_prompt and your final block of code looks like

chain = load_summarize_chain(llm, chain_type="refine",verbose=True,refine_prompt=PROMPT)
vishnu
  • 43
  • 7