Function call within a tool call (OpenAI format). Mutable counterpart to chuk_llm.core.models.FunctionCall (frozen). Must remain mutable because ToolCallData.merge_chunk() accumulates streaming chunks by mutating name/arguments in place.
| 43 | |
| 44 | |
| 45 | class FunctionCallData(BaseModel): |
| 46 | """Function call within a tool call (OpenAI format). |
| 47 | |
| 48 | Mutable counterpart to chuk_llm.core.models.FunctionCall (frozen). |
| 49 | Must remain mutable because ToolCallData.merge_chunk() accumulates |
| 50 | streaming chunks by mutating name/arguments in place. |
| 51 | """ |
| 52 | |
| 53 | name: str = Field(description="Function/tool name") |
| 54 | arguments: str = Field(description="JSON string of arguments") |
| 55 | |
| 56 | model_config = {"frozen": False} |
| 57 | |
| 58 | def get_arguments_dict(self) -> dict[str, Any]: |
| 59 | """Parse arguments JSON string to dict.""" |
| 60 | try: |
| 61 | result = json.loads(self.arguments) |
| 62 | return dict(result) if isinstance(result, dict) else {} |
| 63 | except json.JSONDecodeError: |
| 64 | return {} |
| 65 | |
| 66 | @classmethod |
| 67 | def from_dict_args(cls, name: str, arguments: dict[str, Any]) -> "FunctionCallData": |
| 68 | """Create FunctionCallData from dict arguments.""" |
| 69 | return cls(name=name, arguments=json.dumps(arguments)) |
| 70 | |
| 71 | |
| 72 | class ToolCallData(BaseModel): |
no outgoing calls