2
2
GenerateAnswerNode Module
3
3
"""
4
4
5
- import time
6
5
import json
6
+ import time
7
7
from typing import List , Optional
8
8
9
9
from langchain .prompts import PromptTemplate
@@ -105,10 +105,7 @@ def process(self, state: dict) -> dict:
105
105
raise ValueError ("No user prompt found in state" )
106
106
107
107
# Create the chain input with both content and question keys
108
- chain_input = {
109
- "content" : content ,
110
- "question" : user_prompt
111
- }
108
+ chain_input = {"content" : content , "question" : user_prompt }
112
109
113
110
try :
114
111
response = self .invoke_with_timeout (self .chain , chain_input , self .timeout )
@@ -167,25 +164,13 @@ def execute(self, state: dict) -> dict:
167
164
and not self .script_creator
168
165
or self .is_md_scraper
169
166
):
170
- template_no_chunks_prompt = (
171
- TEMPLATE_NO_CHUNKS_MD + "\n \n IMPORTANT: " + format_instructions
172
- )
173
- template_chunks_prompt = (
174
- TEMPLATE_CHUNKS_MD + "\n \n IMPORTANT: " + format_instructions
175
- )
176
- template_merge_prompt = (
177
- TEMPLATE_MERGE_MD + "\n \n IMPORTANT: " + format_instructions
178
- )
167
+ template_no_chunks_prompt = TEMPLATE_NO_CHUNKS_MD
168
+ template_chunks_prompt = TEMPLATE_CHUNKS_MD
169
+ template_merge_prompt = TEMPLATE_MERGE_MD
179
170
else :
180
- template_no_chunks_prompt = (
181
- TEMPLATE_NO_CHUNKS + "\n \n IMPORTANT: " + format_instructions
182
- )
183
- template_chunks_prompt = (
184
- TEMPLATE_CHUNKS + "\n \n IMPORTANT: " + format_instructions
185
- )
186
- template_merge_prompt = (
187
- TEMPLATE_MERGE + "\n \n IMPORTANT: " + format_instructions
188
- )
171
+ template_no_chunks_prompt = TEMPLATE_NO_CHUNKS
172
+ template_chunks_prompt = TEMPLATE_CHUNKS
173
+ template_merge_prompt = TEMPLATE_MERGE
189
174
190
175
if self .additional_info is not None :
191
176
template_no_chunks_prompt = self .additional_info + template_no_chunks_prompt
@@ -210,8 +195,14 @@ def execute(self, state: dict) -> dict:
210
195
chain , {"question" : user_prompt }, self .timeout
211
196
)
212
197
except (Timeout , json .JSONDecodeError ) as e :
213
- error_msg = "Response timeout exceeded" if isinstance (e , Timeout ) else "Invalid JSON response format"
214
- state .update ({self .output [0 ]: {"error" : error_msg , "raw_response" : str (e )}})
198
+ error_msg = (
199
+ "Response timeout exceeded"
200
+ if isinstance (e , Timeout )
201
+ else "Invalid JSON response format"
202
+ )
203
+ state .update (
204
+ {self .output [0 ]: {"error" : error_msg , "raw_response" : str (e )}}
205
+ )
215
206
return state
216
207
217
208
state .update ({self .output [0 ]: answer })
@@ -241,7 +232,11 @@ def execute(self, state: dict) -> dict:
241
232
async_runner , {"question" : user_prompt }, self .timeout
242
233
)
243
234
except (Timeout , json .JSONDecodeError ) as e :
244
- error_msg = "Response timeout exceeded during chunk processing" if isinstance (e , Timeout ) else "Invalid JSON response format in chunk processing"
235
+ error_msg = (
236
+ "Response timeout exceeded during chunk processing"
237
+ if isinstance (e , Timeout )
238
+ else "Invalid JSON response format in chunk processing"
239
+ )
245
240
state .update ({self .output [0 ]: {"error" : error_msg , "raw_response" : str (e )}})
246
241
return state
247
242
@@ -261,7 +256,11 @@ def execute(self, state: dict) -> dict:
261
256
self .timeout ,
262
257
)
263
258
except (Timeout , json .JSONDecodeError ) as e :
264
- error_msg = "Response timeout exceeded during merge" if isinstance (e , Timeout ) else "Invalid JSON response format during merge"
259
+ error_msg = (
260
+ "Response timeout exceeded during merge"
261
+ if isinstance (e , Timeout )
262
+ else "Invalid JSON response format during merge"
263
+ )
265
264
state .update ({self .output [0 ]: {"error" : error_msg , "raw_response" : str (e )}})
266
265
return state
267
266
0 commit comments