Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle None responses in ask function and update prepare_answer_… #121

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading