My ERROR
`run` not supported when there is not exactly one output key. Got ['quiz', 'review'].
MY CODE
Libraries
import os
import json
import pandas as pd
import traceback
from langchain import PromptTemplate , HuggingFaceHub ,LLMChain
from langchain.chains import SequentialChain
from dotenv import load_dotenv
Loading my env and key
load_dotenv()
key = os.getenv("hugging_face_key")
os.environ['HUGGINGFACEHUB_API_TOKEN'] = key
Initializing My LLM model from HuggingFace
llm=HuggingFaceHub(repo_id='google/flan-t5-base',model_kwargs={'temperature':0.5})
My Prompt Template and Response : - made a two chain 1.Quiz 2.review
RESPONSE_JSON = {
"1": {
"mcq": "multiple choice question",
"options": {
"a": "choice here",
"b": "choice here",
"c": "choice here",
"d": "choice here",
},
"correct": "correct answer",
},
"2": {
"mcq": "multiple choice question",
"options": {
"a": "choice here",
"b": "choice here",
"c": "choice here",
"d": "choice here",
},
"correct": "correct answer",
},
"3": {
"mcq": "multiple choice question",
"options": {
"a": "choice here",
"b": "choice here",
"c": "choice here",
"d": "choice here",
},
"correct": "correct answer",
},
}
TEMPLATE="""
Text:{text}
You are an expert MCQ maker. Given the above text, it is your job to \
create a quiz of {number} multiple choice questions for {subject} students in {tone} tone,
Make sure the question are not repeated and check all the questions to be conforming the text as well.
Make sure to format your response like RESPONSE_JSON below and use it as a guide. \
Ensure to make {number} MCQs
### RESPONSE_JSON
{response_json}
"""
quiz_generation_prompt = PromptTemplate(
input_variables=["text","number","subject","tone","response_json"],
template = TEMPLATE
)
quiz_chain=LLMChain(llm=llm,prompt=quiz_generation_prompt,output_key="quiz",verbose=True)
TEMPLATE2 = """
You are an expert english grammarian and writer . Given a Multiple Choice Quiz for {subject} students.\
You need to evaluate the complexity of the question and give a complete analysis of the quiz.Only use at max 50 words for complexity
if the quiz is not at per with the cognitive and analytical abilities of the students,\
update the quiz questions which needs to be changed and change the tone such that it perfectly fits the student abilities
Quiz_MCQs:
{quiz}
Check from an expert English Writer of the above quiz:
quiz_evaluation_prompt = PromptTemplate(input_variables=["subject","quiz"],template=TEMPLATE2)
review_chain =LLMChain(llm=llm,prompt=quiz_evaluation_prompt,output_key="review",verbose=True)
Making a Sequential Chain : - For Executing both chain in sequence
generate_evaluate_chain=SequentialChain(chains=[quiz_chain,review_chain],input_variables=["text","number","subject","tone","response_json"],
output_variables=["quiz","review"],verbose=True)
Adding Data File:- Which contain Text of my Quiz
path = "C:\Hardik\Ai_tools\MCQ_Generator\data.txt"
with open(path,'r') as file:
TEXT = file.read()
Searialize the python dictionary into a json-formated string
json.dumps(RESPONSE_JSON)
NUMBER = 5
SUBJECT = "machine learning"
TONE = "simple"
Response :- it runs the model and give the output
response = generate_evaluate_chain.run(text=TEXT, number=NUMBER, subject=SUBJECT, tone=TONE, response_json=json.dumps(RESPONSE_JSON))
ERROR: While Executing Response Cell it is giving me ValueError
ValueError
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[39], line 1
----> 1 response = generate_evaluate_chain.run(text=TEXT, number=NUMBER, subject=SUBJECT, tone=TONE, response_json=json.dumps(RESPONSE_JSON), output_key='quiz')
File c:\Hardik\Ai_tools\MCQ_Generator\Mcq\lib\site-packages\langchain_core\_api\deprecation.py:145, in deprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper(*args, **kwargs)
143 warned = True
144 emit_warning()
--> 145 return wrapped(*args, **kwargs)
File c:\Hardik\Ai_tools\MCQ_Generator\Mcq\lib\site-packages\langchain\chains\base.py:540, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
503 """Convenience method for executing chain.
504
505 The main difference between this method and `Chain.__call__` is that this
(...)
537 # -> "The temperature in Boise is..."
538 """
539 # Run at start to make sure this is possible/defined
--> 540 _output_key = self._run_output_key
542 if args and not kwargs:
543 if len(args) != 1:
File c:\Hardik\Ai_tools\MCQ_Generator\Mcq\lib\site-packages\langchain\chains\base.py:488, in Chain._run_output_key(self)
485 @property
486 def _run_output_key(self) -> str:
...
490 f"one output key. Got {self.output_keys}."
491 )
492 return self.output_keys[0]
ValueError: `run` not supported when there is not exactly one output key. Got ['quiz', 'review'].
I have go through the documentation as well and look for some solution stating to use predict in place of run but there is no function named predict in SequentialChain model