diff --git a/validator_api/serializers.py b/validator_api/serializers.py index ffc59ee1d..21be84109 100644 --- a/validator_api/serializers.py +++ b/validator_api/serializers.py @@ -1,11 +1,18 @@ +import json from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, model_validator class CompletionsRequest(BaseModel): """Request model for the /v1/chat/completions endpoint.""" + @model_validator(mode="after") + def add_tools(self): + if self.tools: + self.messages.append({"role": "tool", "content": json.dumps(self.tools)}) + return self + uids: Optional[List[int]] = Field( default=None, description="List of specific miner UIDs to query. If not provided, miners will be selected automatically.", @@ -59,6 +66,21 @@ class CompletionsRequest(BaseModel): ) json_format: bool = Field(default=False, description="Enable JSON format for the response.", example=True) stream: bool = Field(default=False, description="Enable streaming for the response.", example=True) + tools: Optional[List[Dict[str, Any]]] = Field( + default=None, + description="List of tools to use for the task.", + # TODO: Add example that's not just from claude + example=[ + { + "type": "function", + "function": { + "name": "get_current_time", + "description": "Get the current time", + "parameters": {"timezone": {"type": "string", "description": "The timezone to get the time in"}}, + }, + } + ], + ) class WebRetrievalRequest(BaseModel):