Repository: ollama
Issue: Support Nested Parameters for Tools
Labels: feature request,api

### What is the issue?

I have been trying to get ollama tool use to work with https://github.com/jekalmin/extended_openai_conversation but was getting errors. It looked like in the response from ollama `tool_calls.0.function.aguments` is not an object but a string containing the (sometimes correct) object with the params. I tried to debug where it's coming from and it seems to be an issue with ollama (or the models if they are so bad but I tried a few and it's consistent)

I put together a minimal example:

```
import requests
import json

# Define the API key and endpoint
api_key = 'ollama'
api_endpoint = 'http://localhost:11434/v1/chat/completions'

# Define the headers
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {api_key}',
}

tools = {
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "execute_services",
                "description": "Use this function to execute service of devices in Home Assistant.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "list": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "domain": {
                                        "type": "string",
                                        "description": "The domain of the service",
                                    },
                                    "service": {
                                        "type": "string",
                                        "description": "The service to be called",
                                    },
                                    "service_data": {
                                        "type": "object",
                                        "description": "The service data object to indicate what to control.",
                                        "properties": {
                                            "entity_id": {
                                                "type": "string",
                                                "description": "The entity_id retrieved from available devices. It must start with domain, followed by dot character.",
                                            }
                                        },
                                        "required": ["entity_id"],
                                    },
                                },
                                "required": ["domain", "service", "service_data"],
                            },
                        }
                    },
                },
            },
        }
    ],
    "tool_choice": "auto"
}
messages = [
    {
        "role": "system",
        "content": "Ich möchte, dass du als Smart Home Manager von Home Assistant agierst. Ich werde Informationen über das Smart Home zusammen mit einer Frage bereitstellen. Du wirst wahrheitsgemäß Korrekturen vornehmen oder die Frage in einem Satz in Alltagssprache anhand der bereitgestellten Informationen beantworten.\n\nAktuelle Zeit: 2024-08-03 22:11:35.920461+02:00\n\nVerfügbare Geräte:\n```csv\nentity_id,name,state,aliases\nlight.buro_deckenlampe_2,Kinderzimmer Deckenlampe,off\nDer aktuelle Zustand der Geräte ist in den verfügbaren Geräten angegeben. Verwende die execute_services-Funktion nur für angeforderte Aktionen, nicht für aktuelle Zustände. Benötigst keine Bestätigung für tool calls. Wiederhole oder lobe nicht, was der Benutzer sagt, sondern stelle eine kurze Anfrage.",
    },
    {
        "role": "user",
        "content": "Mach das Licht aus.",
        "name": "Daniel Kirsch",
    },
]

# Define the request payload
payload = {
    "model": "llama3.1:8b",
    "messages": messages,
    "max_tokens": 100,
    "temperature": 0.5
} | tools

# Make the POST request
response = requests.post(api_endpoint, headers=headers, data=json.dumps(payload))
response.json()
type(response.json()['choices'][0]['message']['tool_calls'][0]['function']['arguments'])
```

I've tried
- llama3.1:8b
- llama3.1:70b
- mistral-nemo
- llama3-groq-tool-use

and they all suffer from the problem.

### OS

macOS, Windows

### GPU

Nvidia, Apple

### CPU

AMD, Apple

### Ollama version

0.3.3