Source code for langchain.chains.example_generator
fromtypingimportListfromlangchain_core.language_modelsimportBaseLanguageModelfromlangchain_core.output_parsersimportStrOutputParserfromlangchain_core.prompts.few_shotimportFewShotPromptTemplatefromlangchain_core.prompts.promptimportPromptTemplateTEST_GEN_TEMPLATE_SUFFIX="Add another example."
[docs]defgenerate_example(examples:List[dict],llm:BaseLanguageModel,prompt_template:PromptTemplate)->str:"""Return another example given a list of examples for a prompt."""prompt=FewShotPromptTemplate(examples=examples,suffix=TEST_GEN_TEMPLATE_SUFFIX,input_variables=[],example_prompt=prompt_template,)chain=prompt|llm|StrOutputParser()returnchain.invoke({})