Skip to content

Commit

Permalink
fix: QAGenerationChain隐藏preset question
Browse files Browse the repository at this point in the history
  • Loading branch information
zgqgit committed Jun 26, 2024
1 parent af72b4d commit b417b22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/backend/bisheng/template/frontend_node/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ def format_field(field: TemplateField, name: Optional[str] = None) -> None:
field.show = True
field.field_type = 'function'
field.name = 'atransform'
if name in ['QAGenerationChain', 'QAGenerationChainV2'] and field.name in ['k', 'chunk_size']:
field.show = True
if name in ['QAGenerationChain', 'QAGenerationChainV2']:
if field.name in ['k', 'chunk_size']:
field.show = True
elif field.name =='input_node':
field.show = False



class SeriesCharacterChainNode(FrontendNode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,19 @@ def _call(
docs = self.text_splitter.create_documents([contents])
# len(qa) = min(len(docs), self.k)
logger.info(f"Split {len(docs)} documents. Gen qa num: min({len(docs)}, {self.k}).")

<<<<<<< feat/rag_optimize
qa = []
for doc in docs:
results = self.llm_chain.generate([{"text": doc.page_content}], run_manager=run_manager)
res = results.generations[0]
=======
results = self.llm_chain.generate(
[{"text": d.page_content} for d in docs], run_manager=run_manager
)
qa = ''
qa_i = 0
for res in results.generations:
>>>>>>> feat/0.3.1.5
for doc in docs:
try:
# response = json.loads(parse_json(res[0].text))
results = self.llm_chain.generate([{"text": doc.page_content}], run_manager=run_manager)
res = results.generations[0]
qa += res[0].text
qa_i += 1
except Exception as e:
logger.error(f"Failed to parse response: {res[0].text}. Error: {e}")
logger.error(f"Failed to parse response Error: {e}")
continue

if self.k is not None:
if qa_i >= self.k:
break

# results = self.llm_chain.generate(
# [{"text": d.page_content} for d in docs], run_manager=run_manager
# )
# qa = []
# for res in results.generations:
# try:
# response = json.loads(parse_json(res[0].text))
# qa.append(response)
# except Exception as e:
# logger.error(f"Failed to parse response: {res[0].text}. Error: {e}")
# continue

# if self.k is not None:
# if len(qa) >= self.k:
# break
if self.k is not None and qa_i >= self.k:
break
return {self.output_key: qa}

async def _acall(
Expand Down

0 comments on commit b417b22

Please sign in to comment.