add get prompts method (#15425)

This commit is contained in:
Harrison Chase 2024-01-02 12:44:14 -08:00 committed by GitHub
parent 6810b4b0bc
commit a33d92306c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,6 +79,7 @@ if TYPE_CHECKING:
AsyncCallbackManagerForChainRun,
CallbackManagerForChainRun,
)
from langchain_core.prompts.base import BasePromptTemplate
from langchain_core.runnables.fallbacks import (
RunnableWithFallbacks as RunnableWithFallbacksT,
)
@ -394,6 +395,17 @@ class Runnable(Generic[Input, Output], ABC):
graph.add_edge(runnable_node, output_node)
return graph
def get_prompts(
self, config: Optional[RunnableConfig] = None
) -> List[BasePromptTemplate]:
from langchain_core.prompts.base import BasePromptTemplate
prompts = []
for _, node in self.get_graph(config=config).nodes.items():
if isinstance(node.data, BasePromptTemplate):
prompts.append(node.data)
return prompts
def __or__(
self,
other: Union[