mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
log output parser (#8446)
This commit is contained in:
parent
7d79178827
commit
13b4f465e2
@ -35,9 +35,19 @@ class BaseGenerationOutputParser(
|
|||||||
self, input: str | BaseMessage, config: RunnableConfig | None = None
|
self, input: str | BaseMessage, config: RunnableConfig | None = None
|
||||||
) -> T:
|
) -> T:
|
||||||
if isinstance(input, BaseMessage):
|
if isinstance(input, BaseMessage):
|
||||||
return self.parse_result([ChatGeneration(message=input)])
|
return self._call_with_config(
|
||||||
|
lambda inner_input: self.parse_result(
|
||||||
|
[ChatGeneration(message=inner_input)]
|
||||||
|
),
|
||||||
|
input,
|
||||||
|
config,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return self.parse_result([Generation(text=input)])
|
return self._call_with_config(
|
||||||
|
lambda inner_input: self.parse_result([Generation(text=inner_input)]),
|
||||||
|
input,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BaseOutputParser(BaseLLMOutputParser, Runnable[Union[str, BaseMessage], T]):
|
class BaseOutputParser(BaseLLMOutputParser, Runnable[Union[str, BaseMessage], T]):
|
||||||
@ -71,9 +81,19 @@ class BaseOutputParser(BaseLLMOutputParser, Runnable[Union[str, BaseMessage], T]
|
|||||||
self, input: str | BaseMessage, config: RunnableConfig | None = None
|
self, input: str | BaseMessage, config: RunnableConfig | None = None
|
||||||
) -> T:
|
) -> T:
|
||||||
if isinstance(input, BaseMessage):
|
if isinstance(input, BaseMessage):
|
||||||
return self.parse_result([ChatGeneration(message=input)])
|
return self._call_with_config(
|
||||||
|
lambda inner_input: self.parse_result(
|
||||||
|
[ChatGeneration(message=inner_input)]
|
||||||
|
),
|
||||||
|
input,
|
||||||
|
config,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return self.parse_result([Generation(text=input)])
|
return self._call_with_config(
|
||||||
|
lambda inner_input: self.parse_result([Generation(text=inner_input)]),
|
||||||
|
input,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
|
||||||
def parse_result(self, result: List[Generation]) -> T:
|
def parse_result(self, result: List[Generation]) -> T:
|
||||||
"""Parse a list of candidate model Generations into a specific format.
|
"""Parse a list of candidate model Generations into a specific format.
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user