mirror of
https://github.com/hwchase17/langchain
synced 2024-11-16 06:13:16 +00:00
3474f39e21
make it so everything goes through generate, which removes the need for two types of caches
24 lines
749 B
Python
24 lines
749 B
Python
"""Utility functions for working with prompts."""
|
|
from typing import List
|
|
|
|
from langchain.chains.llm import LLMChain
|
|
from langchain.llms.base import BaseLLM
|
|
from langchain.prompts.few_shot import FewShotPromptTemplate
|
|
from langchain.prompts.prompt import PromptTemplate
|
|
|
|
TEST_GEN_TEMPLATE_SUFFIX = "Add another example."
|
|
|
|
|
|
def generate_example(
|
|
examples: List[dict], llm: BaseLLM, 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 = LLMChain(llm=llm, prompt=prompt)
|
|
return chain.predict()
|