core: add error message for non-structured llm to StructuredPrompt (#22684)

previously was the blank `NotImplementedError` from
`BaseLanguageModel.with_structured_output`
pull/21885/head
Erick Friis 2 months ago committed by GitHub
parent 02ff78deb8
commit 9e03864d64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -118,10 +118,19 @@ class StructuredPrompt(ChatPromptTemplate):
if isinstance(other, BaseLanguageModel) or hasattr( if isinstance(other, BaseLanguageModel) or hasattr(
other, "with_structured_output" other, "with_structured_output"
): ):
return RunnableSequence(self, other.with_structured_output(self.schema_)) try:
return RunnableSequence(
self, other.with_structured_output(self.schema_)
)
except NotImplementedError as e:
raise NotImplementedError(
"Structured prompts must be piped to a language model that "
"implements with_structured_output."
) from e
else: else:
raise NotImplementedError( raise NotImplementedError(
"Structured prompts need to be piped to a language model." "Structured prompts must be piped to a language model that "
"implements with_structured_output."
) )
def pipe( def pipe(

Loading…
Cancel
Save