log output parser (#8446)

pull/8456/head
Harrison Chase 1 year ago committed by GitHub
parent 7d79178827
commit 13b4f465e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,9 +35,19 @@ class BaseGenerationOutputParser(
self, input: str | BaseMessage, config: RunnableConfig | None = None
) -> T:
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:
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]):
@ -71,9 +81,19 @@ class BaseOutputParser(BaseLLMOutputParser, Runnable[Union[str, BaseMessage], T]
self, input: str | BaseMessage, config: RunnableConfig | None = None
) -> T:
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:
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:
"""Parse a list of candidate model Generations into a specific format.

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save