Closed khacsinhcs closed 6 months ago
🤖
Hello @khacsinhcs! I'm Dosu, a friendly bot here to assist you with your issues and questions related to LangChain. While we wait for a human maintainer to arrive, I'm here to help you with your issue. Don't worry, we'll work through this together!
Based on the information provided, it seems like the k
attribute is not being utilized in the _call
method of the QAGenerationChain
class. This is likely why you're only seeing one question generated, regardless of the text length.
Here's the relevant part of the _call
method:
def _call(
self,
inputs: Dict[str, Any],
run_manager: Optional[CallbackManagerForChainRun] = None,
) -> Dict[str, List]:
docs = self.text_splitter.create_documents([inputs[self.input_key]])
results = self.llm_chain.generate(
[{"text": d.page_content} for d in docs], run_manager=run_manager
)
qa = [json.loads(res[0].text) for res in results.generations]
return {self.output_key: qa}
As you can see, the k
attribute is not passed to the generate
method of the llm_chain
object. This means that the generate
method doesn't know how many questions to generate.
To fix this issue, you would need to modify the _call
method to pass the k
attribute to the generate
method of the llm_chain
object. However, without seeing the implementation of the generate
method, it's hard to provide a concrete solution.
The generate
method in the llm_chain
object is implemented as follows:
def generate(
self,
input_list: List[Dict[str, Any]],
run_manager: Optional[CallbackManagerForChainRun] = None,
) -> LLMResult:
"""Generate LLM result from inputs."""
prompts, stop = self.prep_prompts(input_list, run_manager=run_manager)
callbacks = run_manager.get_child() if run_manager else None
if isinstance(self.llm, BaseLanguageModel):
return self.llm.generate_prompt(
prompts,
stop,
callbacks=callbacks,
**self.llm_kwargs,
)
else:
results = self.llm.bind(stop=stop, **self.llm_kwargs).batch(
cast(List, prompts), {"callbacks": callbacks}
)
generations: List[List[Generation]] = []
for res in results:
if isinstance(res, BaseMessage):
generations.append([ChatGeneration(message=res)])
else:
generations.append([Generation(text=res)])
return LLMResult(generations=generations)
This method takes a list of inputs and an optional run manager. It prepares the prompts using the prep_prompts
method and gets the child of the run manager if it exists. If the language model is an instance of BaseLanguageModel
, it generates a prompt using the generate_prompt
method of the language model. If not, it binds the stop and other keyword arguments to the language model and processes the prompts in batches. The results are then processed and returned as an LLMResult
object.
I hope this helps! If you have any other questions or need further clarification, feel free to ask.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
System Info
Regardless of the text length, the QAGenerationChain consistently generates only one question.
Who can help?
No response
Information
Related Components
Reproduction
output
Expected behavior
I expect to specify the number of responses by setting the 'k' value.