From b4a49835acf584fb1025f7e41574b2f8892cd0ad Mon Sep 17 00:00:00 2001 From: Ahonanhin Date: Tue, 3 Dec 2024 17:08:46 -0500 Subject: [PATCH] modified: libs/core/langchain_core/output_parsers/base.py modified: libs/core/langchain_core/prompts/prompt.py --- libs/core/langchain_core/output_parsers/base.py | 6 ++---- libs/core/langchain_core/prompts/prompt.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libs/core/langchain_core/output_parsers/base.py b/libs/core/langchain_core/output_parsers/base.py index 7d35246738425..8d6a4d2130e34 100644 --- a/libs/core/langchain_core/output_parsers/base.py +++ b/libs/core/langchain_core/output_parsers/base.py @@ -13,9 +13,6 @@ from typing_extensions import override -import logging -logger = logging.getLogger(__name__) - from langchain_core.language_models import LanguageModelOutput from langchain_core.messages import AnyMessage, BaseMessage from langchain_core.outputs import ChatGeneration, Generation @@ -287,7 +284,8 @@ def parse_result(self, result: list[Generation], *, partial: bool = False) -> T: try: return output_text.strip() except Exception as e: - raise ValueError(f"Failed to parse output: {e}") + error_message = f"Failed to parse output: {e}" + raise ValueError(error_message) @abstractmethod def parse(self, text: str) -> T: diff --git a/libs/core/langchain_core/prompts/prompt.py b/libs/core/langchain_core/prompts/prompt.py index 3c8f90a29a4ab..476a0770668fc 100644 --- a/libs/core/langchain_core/prompts/prompt.py +++ b/libs/core/langchain_core/prompts/prompt.py @@ -91,7 +91,8 @@ def pre_init_validation(cls, values: dict) -> Any: # if "do not generate additional user input" not in values["template"].lower(): # raise ValueError( - # "Prompt template must include constraints for avoiding additional user input generation." + # "Prompt template must include constraints for + # avoiding additional user input generation." # ) # if "avoid infinite loops" not in values["template"].lower(): # raise ValueError( @@ -189,7 +190,8 @@ def format(self, **kwargs: Any) -> str: A formatted string. """ kwargs = self._merge_partial_and_user_variables(**kwargs) - formatted_string = DEFAULT_FORMATTER_MAPPING[self.template_format](self.template, **kwargs) + formatted_string = DEFAULT_FORMATTER_MAPPING\ + [self.template_format](self.template, **kwargs) reasoning_history = kwargs.get("reasoning_history", []) if len(reasoning_history) > 3 and len(set(reasoning_history[-3:])) == 1: @@ -312,13 +314,15 @@ def from_template( var for var in input_variables if var not in _partial_variables ] - default_constraints = """ Note: + default_constraints = """ Note: 1. Do not generate additional user input requests during task execution. 2. Use only the available tools to perform actions. - 3. If a solution cannot be determined with the given tools or information, respond: + 3. If a solution cannot be determined with the given tools or + information, respond: "I'm unable to complete this task with the current resources." - 4. Avoid infinite loops by stopping reasoning and returning an appropriate message if progress cannot be made. - """ + 4. Avoid infinite loops by stopping reasoning and returning an + appropriate message if progress cannot be made. + """ updated_template = template + (constraints or default_constraints) input_variables = get_template_variables(updated_template, template_format)