| 64 | |
| 65 | |
| 66 | class ToolOutput(BaseModel): |
| 67 | type: ToolType = Field( |
| 68 | ..., |
| 69 | description="The tool type, which can be `function` or `action`.", |
| 70 | examples=["action", "plugin"], |
| 71 | ) |
| 72 | |
| 73 | tool_id: str = Field( |
| 74 | ..., |
| 75 | description="The tool ID.", |
| 76 | examples=["action_1"], |
| 77 | ) |
| 78 | |
| 79 | tool_call_id: str = Field( |
| 80 | ..., |
| 81 | description="The tool call ID.", |
| 82 | examples=["call_1"], |
| 83 | ) |
| 84 | |
| 85 | status: int = Field( |
| 86 | ..., |
| 87 | description="The tool output status.", |
| 88 | examples=[200, 400, 500], |
| 89 | ) |
| 90 | |
| 91 | data: Union[Dict, List] = Field( |
| 92 | ..., |
| 93 | description="The tool output data.", |
| 94 | ) |
| 95 | |
| 96 | def to_function_message(self): |
| 97 | if self.status == 200: |
| 98 | return { |
| 99 | "role": "function", |
| 100 | "content": json.dumps(self.data), |
| 101 | "id": self.tool_call_id, |
| 102 | } |
| 103 | else: |
| 104 | return { |
| 105 | "role": "function", |
| 106 | "content": json.dumps({"status": self.status, "error": self.data}), |
| 107 | "id": self.tool_call_id, |
| 108 | } |