Skip to content

Commit

Permalink
Merge pull request #121 from TogetherCrew/feat/116-hivemind-source-th…
Browse files Browse the repository at this point in the history
…reshold

fix: Handle None responses in ask function and update prepare_answer_…
  • Loading branch information
amindadgar authored Jan 20, 2025
2 parents 64b74e3 + 6521f82 commit a4ab241
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions routers/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ async def ask(payload: Payload, logger: Logger):
persister = PersistPayload()
persister.persist_amqp(response_payload)

if response is None:
raise ValueError("not confident in answering!")

job_send(
event=payload.content.route.destination.event,
queue_name=payload.content.route.destination.queue,
Expand Down
6 changes: 4 additions & 2 deletions utils/query_engine/prepare_answer_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
self.threshold = threshold
self.max_refs_per_source = max_refs_per_source

def prepare_answer_sources(self, nodes: list[NodeWithScore]) -> str:
def prepare_answer_sources(self, nodes: list[NodeWithScore | None]) -> str:
"""
Prepares a formatted string containing source URLs organized by tool name from the provided nodes.
Expand Down Expand Up @@ -70,9 +70,11 @@ def prepare_answer_sources(self, nodes: list[NodeWithScore]) -> str:
logging.error("No reference nodes available! returning empty string.")
return ""

cleaned_nodes = [n for n in nodes if n is not None]

# link of places that we got the answer from
all_sources: str = "References:\n"
for tool_nodes in nodes:
for tool_nodes in cleaned_nodes:
# platform name
tool_name = tool_nodes.sub_q.tool_name

Expand Down

0 comments on commit a4ab241

Please sign in to comment.