Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Small bug in questiongenerator code (pool should be list) #27

Open
sujitpal opened this issue Mar 28, 2024 · 0 comments
Open

Small bug in questiongenerator code (pool should be list) #27

sujitpal opened this issue Mar 28, 2024 · 0 comments

Comments

@sujitpal
Copy link

My environment:

  • MacOS Monterey 12.6.5
  • Python 3.11.4

Running the following code (as shown in README):

qg = QuestionGenerator()
text = "..."
response = qg.generate(text, num_questions=5)
print(response)

returns the following error:

...
  File "/Users/palsujit/Projects/hgraph-sujitpal/llamaindex-apollo-preprocessing/src/../external/question_generator/questiongenerator.py", line 250, in _get_MC_answers
    choices.extend(random.sample(pool, num_choices - len(choices)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/random.py", line 439, in sample
    raise TypeError("Population must be a sequence.  "
TypeError: Population must be a sequence.  For dicts or sets, use sorted(d).

It seems to be because pool is a set and random.sample expects a list, so I updated line 249 of questiongenerator.py to read:

pool = list(pool.difference(set(choices)))

and this seems to have fixed it.

@sujitpal sujitpal changed the title Small but in questiongenerator code (pool should be list) Small bug in questiongenerator code (pool should be list) Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant