Skip to content

Commit

Permalink
modified: libs/core/langchain_core/output_parsers/base.py
Browse files Browse the repository at this point in the history
	modified:   libs/core/langchain_core/prompts/prompt.py
  • Loading branch information
Ahonanhin committed Dec 3, 2024
1 parent 4eed603 commit b4a4983
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 2 additions & 4 deletions libs/core/langchain_core/output_parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Check failure on line 288 in libs/core/langchain_core/output_parsers/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (B904)

langchain_core/output_parsers/base.py:288:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

Check failure on line 288 in libs/core/langchain_core/output_parsers/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (B904)

langchain_core/output_parsers/base.py:288:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

Check failure on line 288 in libs/core/langchain_core/output_parsers/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (B904)

langchain_core/output_parsers/base.py:288:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

Check failure on line 288 in libs/core/langchain_core/output_parsers/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (B904)

langchain_core/output_parsers/base.py:288:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

Check failure on line 288 in libs/core/langchain_core/output_parsers/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (B904)

langchain_core/output_parsers/base.py:288:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

@abstractmethod
def parse(self, text: str) -> T:
Expand Down
16 changes: 10 additions & 6 deletions libs/core/langchain_core/prompts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 94 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (W291)

langchain_core/prompts/prompt.py:94:64: W291 Trailing whitespace

Check failure on line 94 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (W291)

langchain_core/prompts/prompt.py:94:64: W291 Trailing whitespace

Check failure on line 94 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (W291)

langchain_core/prompts/prompt.py:94:64: W291 Trailing whitespace

Check failure on line 94 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (W291)

langchain_core/prompts/prompt.py:94:64: W291 Trailing whitespace

Check failure on line 94 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (W291)

langchain_core/prompts/prompt.py:94:64: W291 Trailing whitespace
# avoiding additional user input generation."
# )
# if "avoid infinite loops" not in values["template"].lower():
# raise ValueError(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Check failure on line 320 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (W291)

langchain_core/prompts/prompt.py:320:70: W291 Trailing whitespace

Check failure on line 320 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (W291)

langchain_core/prompts/prompt.py:320:70: W291 Trailing whitespace

Check failure on line 320 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (W291)

langchain_core/prompts/prompt.py:320:70: W291 Trailing whitespace

Check failure on line 320 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (W291)

langchain_core/prompts/prompt.py:320:70: W291 Trailing whitespace

Check failure on line 320 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (W291)

langchain_core/prompts/prompt.py:320:70: W291 Trailing whitespace
information, respond:

Check failure on line 321 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (W291)

langchain_core/prompts/prompt.py:321:34: W291 Trailing whitespace

Check failure on line 321 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (W291)

langchain_core/prompts/prompt.py:321:34: W291 Trailing whitespace

Check failure on line 321 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (W291)

langchain_core/prompts/prompt.py:321:34: W291 Trailing whitespace

Check failure on line 321 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (W291)

langchain_core/prompts/prompt.py:321:34: W291 Trailing whitespace

Check failure on line 321 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (W291)

langchain_core/prompts/prompt.py:321:34: W291 Trailing whitespace
"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

Check failure on line 323 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (W291)

langchain_core/prompts/prompt.py:323:71: W291 Trailing whitespace

Check failure on line 323 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (W291)

langchain_core/prompts/prompt.py:323:71: W291 Trailing whitespace

Check failure on line 323 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (W291)

langchain_core/prompts/prompt.py:323:71: W291 Trailing whitespace

Check failure on line 323 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (W291)

langchain_core/prompts/prompt.py:323:71: W291 Trailing whitespace

Check failure on line 323 in libs/core/langchain_core/prompts/prompt.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (W291)

langchain_core/prompts/prompt.py:323:71: W291 Trailing whitespace
appropriate message if progress cannot be made.
"""
updated_template = template + (constraints or default_constraints)

input_variables = get_template_variables(updated_template, template_format)
Expand Down

0 comments on commit b4a4983

Please sign in to comment.