From 8a54217e7b8e0da43c885ff0677dfa898e0e1a05 Mon Sep 17 00:00:00 2001 From: Piotr Mardziel Date: Thu, 27 Apr 2023 11:17:31 -0700 Subject: [PATCH] update example of ConstitutionalChain.from_llm (#3630) Example code was missing an argument and import. Fixed. --- langchain/chains/constitutional_ai/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/langchain/chains/constitutional_ai/base.py b/langchain/chains/constitutional_ai/base.py index b3ff12f5..7845da22 100644 --- a/langchain/chains/constitutional_ai/base.py +++ b/langchain/chains/constitutional_ai/base.py @@ -18,14 +18,19 @@ class ConstitutionalChain(Chain): from langchain.llms import OpenAI from langchain.chains import LLMChain, ConstitutionalChain + from langchain.chains.constitutional_ai.models \ + import ConstitutionalPrinciple + + llm = OpenAI() qa_prompt = PromptTemplate( template="Q: {question} A:", input_variables=["question"], ) - qa_chain = LLMChain(llm=OpenAI(), prompt=qa_prompt) + qa_chain = LLMChain(llm=llm, prompt=qa_prompt) constitutional_chain = ConstitutionalChain.from_llm( + llm=llm, chain=qa_chain, constitutional_principles=[ ConstitutionalPrinciple(