Class Introduction
Function
This is a QA generation class. After you input a title and body content, an LLM is accessed to generate a QA pair based on the body content.
Prototype
from mx_rag.cache import QAGenerate QAGenerate(config: QAGenerationConfig)
Parameters
Parameter |
Data Type |
Required/Optional |
Description |
|---|---|---|---|
config |
QAGenerationConfig |
Required |
QAGenerationConfig object, which is used to generate QA parameters. For details about the QAGenerationConfig prototype, see QAGenerationConfig. |
Example
from paddle.base import libpaddle
from transformers import AutoTokenizer
from mx_rag.cache import QAGenerationConfig, QAGenerate
from mx_rag.llm import Text2TextLLM
from mx_rag.utils import ClientParam
llm = Text2TextLLM(base_url="https://ip:port/v1/chat/completions", model_name="llama3-chinese-8b-chat",
client_param=ClientParam(ca_file="/path/to/ca.crt"))
# Use a model tokenizer and pass the model saving path.
tokenizer = AutoTokenizer.from_pretrained("/home/model/Llama3-8B-Chinese-Chat/", local_files_only=True)
# Call MarkDownParser to generate titles and contents.
titles = ["Composition test of the 2024 National College Entrance Examination"]
contents = ['composition test of the 2024 National College Entrance Examination\nNew Course Standard (I)\nRead the following materials and write a composition. (60 points)\n'
'With the popularization of the Internet and artificial intelligence, more and more questions can be quickly answered. So, will we have fewer problems?\n'
'How do you think about the above materials? Please write a composition no fewer than 800 words.'
'Requirements: Select a proper angle and style to describe your opinions. Prepare your own title. Do not copy other articles, and do not disclose personal information.']
config = QAGenerationConfig(titles, contents, tokenizer, llm, qas_num=1)
qa_generate = QAGenerate(config)
qas = qa_generate.generate_qa()
print(qas)
Parent topic: QAGenerate