From 062a18226cef28d89895e7d708d4f13ccef9bca8 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Thu, 11 Apr 2024 16:20:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8llm=20override=20for=20chain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/funcchain/syntax/executable.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/funcchain/syntax/executable.py b/src/funcchain/syntax/executable.py index 250fb25..dae60ae 100644 --- a/src/funcchain/syntax/executable.py +++ b/src/funcchain/syntax/executable.py @@ -27,6 +27,7 @@ def chain( context: list[BaseMessage] = [], memory: BaseChatMessageHistory | None = None, settings_override: SettingsOverride = {}, + llm: UniversalChatModel | None = None, **input_kwargs: Any, ) -> Any: """ @@ -40,6 +41,9 @@ def chain( memory = memory or ChatMessageHistory() input_kwargs.update(kwargs_from_parent()) + if llm: + settings_override["llm"] = llm + # todo maybe this should be done in the prompt processor? system = system or settings.system_prompt if system: @@ -77,6 +81,7 @@ async def achain( context: list[BaseMessage] = [], memory: BaseChatMessageHistory | None = None, settings_override: SettingsOverride = {}, + llm: UniversalChatModel | None = None, **input_kwargs: Any, ) -> Any: """ @@ -90,6 +95,9 @@ async def achain( memory = memory or ChatMessageHistory() input_kwargs.update(kwargs_from_parent()) + if llm: + settings_override["llm"] = llm + # todo maybe this should be done in the prompt processor? system = system or settings.system_prompt if system: @@ -136,7 +144,7 @@ def compile_runnable( """ On the fly compilation of the funcchain syntax. """ - if settings_override and llm: + if llm: settings_override["llm"] = llm instruction = "\n" + instruction settings = create_local_settings(settings_override)