Skip to content

only include tool_calls or tool_call_id in requests #3170

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

Closed
Closed
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: 17 additions & 0 deletions src/huggingface_hub/inference/_generated/types/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ class ChatCompletionInputMessage(BaseInferenceType):
content: Optional[Union[List[ChatCompletionInputMessageChunk], str]] = None
name: Optional[str] = None
tool_calls: Optional[List[ChatCompletionInputToolCall]] = None
tool_call_id: Optional[str] = None
refusal: Optional[str] = None

def __post_init__(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean it's broken for all providers currently? 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's broken for all providers, my intuition is that groq seems to be a bit more strict on this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I tested on other providers and it seems that groq is the only one to enforce.

super().__post_init__()
valid_fields_by_role = {
"developer": {"role", "content", "name"},
"system": {"role", "content", "name"},
"user": {"role", "content", "name"},
"assistant": {"role", "content", "name", "refusal", "tool_calls", "function_call", "audio"},
"tool": {"role", "content", "tool_call_id"},
}
valid_fields = valid_fields_by_role.get(self.role, set())
for field_name in ["content", "name", "tool_calls", "tool_call_id", "refusal"]:
if field_name not in valid_fields and field_name in self:
self.pop(field_name, None)
setattr(self, field_name, None)


@dataclass_with_extra
Expand Down