Skip to content

Conversation

drbh
Copy link
Collaborator

@drbh drbh commented Jul 7, 2025

This PR enables $defs to be set inside of function parameters

example:

import requests
import json

url = "http://localhost:3000/v1/chat/completions"

payload = {
    "messages": [
        {
            "content": "Classify the weather: It's sunny outside with clear skies",
            "role": "user",
        }
    ],
    "model": "test-model",
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "classify_weather",
                "description": "Classify weather conditions",
                "parameters": {
                    "$defs": {
                        "WeatherType": {
                            "enum": ["sunny", "cloudy", "rainy", "snowy"],
                            "type": "string",
                        }
                    },
                    "properties": {"weather": {"$ref": "#/$defs/WeatherType"}},
                    "required": ["weather"],
                    "type": "object",
                },
            },
        }
    ],
}

response = requests.post(url, json=payload)

print(json.dumps(response.json(), indent=2))

expected response

{
  "object": "chat.completion",
  "id": "",
  "created": 1751895703,
  "model": "test-model",
  "system_fingerprint": "3.3.4-dev0-native",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "tool_calls": [
          {
            "id": "0",
            "type": "function",
            "function": {
              "description": null,
              "name": "classify_weather",
              "arguments": "{\"weather\":\"sunny\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 196,
    "completion_tokens": 18,
    "total_tokens": 214
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant