You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
must include instructions for formatting the output into the
728
+
desired schema into the model call.
729
+
730
+
.. versionchanged:: 0.2.5
731
+
732
+
Added method="json_schema"
733
+
720
734
include_raw:
721
735
If False then only the parsed structured output is returned. If
722
736
an error occurs during model output parsing it will be raised. If True
@@ -877,11 +891,11 @@ class AnswerWithJustification(BaseModel):
877
891
878
892
structured_llm.invoke(
879
893
"Answer the following question. "
880
-
"Make sure to return a JSON blob with keys 'answer' and 'justification'.\n\n"
894
+
"Make sure to return a JSON blob with keys 'answer' and 'justification'.\\n\\n"
881
895
"What's heavier a pound of bricks or a pound of feathers?"
882
896
)
883
897
# -> {
884
-
# 'raw': AIMessage(content='{\n "answer": "They are both the same weight.",\n "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight." \n}'),
898
+
# 'raw': AIMessage(content='{\\n "answer": "They are both the same weight.",\\n "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight." \\n}'),
885
899
# 'parsed': AnswerWithJustification(answer='They are both the same weight.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'),
886
900
# 'parsing_error': None
887
901
# }
@@ -893,17 +907,18 @@ class AnswerWithJustification(BaseModel):
893
907
894
908
structured_llm.invoke(
895
909
"Answer the following question. "
896
-
"Make sure to return a JSON blob with keys 'answer' and 'justification'.\n\n"
910
+
"Make sure to return a JSON blob with keys 'answer' and 'justification'.\\n\\n"
897
911
"What's heavier a pound of bricks or a pound of feathers?"
898
912
)
899
913
# -> {
900
-
# 'raw': AIMessage(content='{\n "answer": "They are both the same weight.",\n "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight." \n}'),
914
+
# 'raw': AIMessage(content='{\\n "answer": "They are both the same weight.",\\n "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight." \\n}'),
901
915
# 'parsed': {
902
916
# 'answer': 'They are both the same weight.',
903
917
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'
0 commit comments