log output parser (#8446)

This commit is contained in:
Harrison Chase 2023-07-28 23:53:45 -07:00 committed by GitHub
parent 7d79178827
commit 13b4f465e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -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