fix: resolved outparser issue

This commit is contained in:
aziz-ullah-khan 2024-11-03 20:23:29 +05:00
parent 65d39bbaf0
commit e8cabfd1ae
2 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -122,11 +122,11 @@ class GenerateAnswerNode(BaseNode):
partial_variables={"context": doc, "format_instructions": format_instructions} partial_variables={"context": doc, "format_instructions": format_instructions}
) )
chain = prompt | self.llm_model chain = prompt | self.llm_model
raw_response = str((prompt | self.llm_model).invoke({"question": user_prompt})) raw_response = chain.invoke({"question": user_prompt})
if output_parser: if output_parser:
try: try:
answer = output_parser.parse(raw_response) answer = output_parser.parse(raw_response.content)
except JSONDecodeError: except JSONDecodeError:
lines = raw_response.split('\n') lines = raw_response.split('\n')
if lines[0].strip().startswith('```'): if lines[0].strip().startswith('```'):
@ -136,7 +136,7 @@ class GenerateAnswerNode(BaseNode):
cleaned_response = '\n'.join(lines) cleaned_response = '\n'.join(lines)
answer = output_parser.parse(cleaned_response) answer = output_parser.parse(cleaned_response)
else: else:
answer = raw_response answer = raw_response.content
state.update({self.output[0]: answer}) state.update({self.output[0]: answer})
return state return state