Skip to content

Commit

Permalink
Feat/0.3.1.5 (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgqgit authored Jun 26, 2024
2 parents 6a49e1a + b417b22 commit 8a32f0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 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,24 +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}).")

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:
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
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 8a32f0d

Please sign in to comment.