8000 fix: dealing with empty tool_calls by jacopo-chevallard · Pull Request #3514 · QuivrHQ/quivr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: dealing with empty tool_calls #3514

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

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
17 changes: 13 additions & 4 deletions core/quivr_core/rag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ def parse_chunk_response(
"""
rolling_msg += raw_chunk

if not supports_func_calling or not rolling_msg.tool_calls:
tool_calls = rolling_msg.tool_calls

if not supports_func_calling or not tool_calls:
new_content = raw_chunk.content # Just the new chunk's content
full_content = rolling_msg.content # The full accumulated content
return rolling_msg, new_content, full_content

current_answers = get_answers_from_tool_calls(rolling_msg.tool_calls)
current_answers = get_answers_from_tool_calls(tool_calls)
full_answer = "\n\n".join(current_answers)
if not full_answer:
full_answer = previous_content

new_content = full_answer[len(previous_content) :]

return rolling_msg, new_content, full_answer
Expand All @@ -111,8 +116,12 @@ def parse_chunk_response(
def get_answers_from_tool_calls(tool_calls):
answers = []
for tool_call in tool_calls:
if tool_call.get("name") == "cited_answer" and "args" in tool_call:
answers.append(tool_call["args"].get("answer", ""))
if tool_call.get("name") == "cited_answer":
args = tool_call.get("args", {})
if isinstance(args, dict):
answers.append(args.get("answer", ""))
else:
logger.warning(f"Expected dict for tool_call args, got {type(args)}")
return answers


Expand Down
Loading
0