doesn't magically know how to create our data; we need to guide it. We do this by creating a prompt template. This template helps instruct the underlying language model on how to produce synthetic data in the desired format.OPENAI_TEMPLATE = PromptTemplate(input_variables=["example"], template="{example}")prompt_template = FewShotPromptTemplate(    prefix=SYNTHETIC_FEW_SHOT_PREFIX,    examples=examples,    suffix=SYNTHETIC_FEW_SHOT_SUFFIX,    input_variables=["subject", "extra"],    example_prompt=OPENAI_TEMPLATE,)The FewShotPromptTemplate includes:prefix and suffix: These likely contain guiding context or instructions.examples: The sample data we defined earlier.input_variables: These variables ("subject", "extra") are placeholders you can dynamically fill later. For instance, "subject" might be filled with "medical_billing" to guide the model further.example_prompt: This prompt template is the format we want each example row to take in our prompt.4. Creating the Data Generator‚ÄãWith the schema and the prompt ready, the next step is to create the data generator. This object knows how to communicate with the underlying language model to get synthetic data.synthetic_data_generator = create_openai_data_generator(    output_schema=MedicalBilling,    llm=ChatOpenAI(temperature=1),  # You'll need to replace with your actual Language Model instance    prompt=prompt_template,)5. Generate Synthetic Data‚ÄãFinally, let's get our synthetic data!synthetic_results = synthetic_data_generator.generate(    subject="medical_billing",    extra="the name must be chosen at random. Make it something you wouldn't normally choose.",    runs=10,)This command asks the generator to produce 10 synthetic medical billing records. The results are stored in synthetic_results. The output will be a list of the MedicalBilling pydantic models.Other implementations‚Äãfrom langchain.chat_models import ChatOpenAIfrom langchain_experimental.synthetic_data import create_data_generation_chain,
Open In Colab
Open In Colab ->: doesn't magically know how to create our data; we need to guide it. We do this by creating a prompt template. This template helps instruct the underlying language model on how to produce synthetic data in the desired format.OPENAI_TEMPLATE = PromptTemplate(input_variables=["example"], template="{example}")prompt_template = FewShotPromptTemplate(    prefix=SYNTHETIC_FEW_SHOT_PREFIX,    examples=examples,    suffix=SYNTHETIC_FEW_SHOT_SUFFIX,    input_variables=["subject", "extra"],    example_prompt=OPENAI_TEMPLATE,)The FewShotPromptTemplate includes:prefix and suffix: These likely contain guiding context or instructions.examples: The sample data we defined earlier.input_variables: These variables ("subject", "extra") are placeholders you can dynamically fill later. For instance, "subject" might be filled with "medical_billing" to guide the model further.example_prompt: This prompt template is the format we want each example row to take in our prompt.4. Creating the Data Generator‚ÄãWith the schema and the prompt ready, the next step is to create the data generator. This object knows how to communicate with the underlying language model to get synthetic data.synthetic_data_generator = create_openai_data_generator(    output_schema=MedicalBilling,    llm=ChatOpenAI(temperature=1),  # You'll need to replace with your actual Language Model instance    prompt=prompt_template,)5. Generate Synthetic Data‚ÄãFinally, let's get our synthetic data!synthetic_results = synthetic_data_generator.generate(    subject="medical_billing",    extra="the name must be chosen at random. Make it something you wouldn't normally choose.",    runs=10,)This command asks the generator to produce 10 synthetic medical billing records. The results are stored in synthetic_results. The output will be a list of the MedicalBilling pydantic models.Other implementations‚Äãfrom langchain.chat_models import ChatOpenAIfrom langchain_experimental.synthetic_data import create_data_generation_chain,