mirror of
https://github.com/hwchase17/langchain
synced 2024-11-02 09:40:22 +00:00
rename to str output parser (#8373)
This commit is contained in:
parent
0e9e5b5202
commit
f5bf893035
@ -20,8 +20,8 @@ from langchain.schema import (
|
||||
BaseLLMOutputParser,
|
||||
BasePromptTemplate,
|
||||
LLMResult,
|
||||
NoOpOutputParser,
|
||||
PromptValue,
|
||||
StrOutputParser,
|
||||
)
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
from langchain.utils.input import get_colored_text
|
||||
@ -50,7 +50,7 @@ class LLMChain(Chain):
|
||||
llm: BaseLanguageModel
|
||||
"""Language model to call."""
|
||||
output_key: str = "text" #: :meta private:
|
||||
output_parser: BaseLLMOutputParser = Field(default_factory=NoOpOutputParser)
|
||||
output_parser: BaseLLMOutputParser = Field(default_factory=StrOutputParser)
|
||||
"""Output parser to use.
|
||||
Defaults to one that takes the most likely string but does not change it
|
||||
otherwise."""
|
||||
|
@ -10,7 +10,7 @@ import yaml
|
||||
from langchain.output_parsers.regex import RegexParser
|
||||
from langchain.prompts.few_shot import FewShotPromptTemplate
|
||||
from langchain.prompts.prompt import PromptTemplate
|
||||
from langchain.schema import BaseLLMOutputParser, BasePromptTemplate, NoOpOutputParser
|
||||
from langchain.schema import BaseLLMOutputParser, BasePromptTemplate, StrOutputParser
|
||||
from langchain.utilities.loading import try_load_from_hub
|
||||
|
||||
URL_BASE = "https://raw.githubusercontent.com/hwchase17/langchain-hub/master/prompts/"
|
||||
@ -80,7 +80,7 @@ def _load_output_parser(config: dict) -> dict:
|
||||
if output_parser_type == "regex_parser":
|
||||
output_parser: BaseLLMOutputParser = RegexParser(**_config)
|
||||
elif output_parser_type == "default":
|
||||
output_parser = NoOpOutputParser(**_config)
|
||||
output_parser = StrOutputParser(**_config)
|
||||
else:
|
||||
raise ValueError(f"Unsupported output parser {output_parser_type}")
|
||||
config["output_parser"] = output_parser
|
||||
|
@ -24,8 +24,8 @@ from langchain.schema.output import (
|
||||
from langchain.schema.output_parser import (
|
||||
BaseLLMOutputParser,
|
||||
BaseOutputParser,
|
||||
NoOpOutputParser,
|
||||
OutputParserException,
|
||||
StrOutputParser,
|
||||
)
|
||||
from langchain.schema.prompt import PromptValue
|
||||
from langchain.schema.prompt_template import BasePromptTemplate, format_document
|
||||
@ -62,7 +62,7 @@ __all__ = [
|
||||
"RUN_KEY",
|
||||
"Memory",
|
||||
"OutputParserException",
|
||||
"NoOpOutputParser",
|
||||
"StrOutputParser",
|
||||
"BaseOutputParser",
|
||||
"BaseLLMOutputParser",
|
||||
"BasePromptTemplate",
|
||||
|
@ -137,8 +137,8 @@ class BaseOutputParser(BaseLLMOutputParser, Runnable[Union[str, BaseMessage], T]
|
||||
return output_parser_dict
|
||||
|
||||
|
||||
class NoOpOutputParser(BaseOutputParser[str]):
|
||||
"""'No operation' OutputParser that returns the text as is."""
|
||||
class StrOutputParser(BaseOutputParser[str]):
|
||||
"""OutputParser that parses LLMResult into the top likely string.."""
|
||||
|
||||
@property
|
||||
def lc_serializable(self) -> bool:
|
||||
@ -155,6 +155,10 @@ class NoOpOutputParser(BaseOutputParser[str]):
|
||||
return text
|
||||
|
||||
|
||||
# TODO: Deprecate
|
||||
NoOpOutputParser = StrOutputParser
|
||||
|
||||
|
||||
class OutputParserException(ValueError):
|
||||
"""Exception that output parsers should raise to signify a parsing error.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user