Azure / Azure/azure-sdk-for-python

[openai] 'tools' is incorrectly packed when the tool lacks parameters.

Open
#41,447 2 comments 0 reactions 0 assignees View on GitHub
Client needs-team-attention OpenAI Service Attention
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

- **Package Name**: openai
- **Package Version**: 1.84.0
- **Operating System**: Windows
- **Python Version**: 3.12.10

With the code:
```py
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import AzureOpenAI
from dotenv import load_dotenv
import os
load_dotenv()

# Azure OpenAI configuration
AZURE_OPENAI_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
AZURE_OPENAI_MODEL = os.getenv("AZURE_OPENAI_MODEL", "gpt-4o")

token_provider = get_bearer_token_provider(
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
)

client = AzureOpenAI(
azure_endpoint=AZURE_OPENAI_ENDPOINT,
api_version="2024-04-01-preview",
azure_ad_token_provider=token_provider
)

messages = [{'role': 'user', 'content': 'Hello, how are you?'}]
available_tools = [
{
'type': 'function',
'function': {
'name': 'azmcp-bestpractices-get',
'description': 'Returns best practices for secure, production-grade Azure SDK usage. Call this command and follow its guidance before generating or suggesting any Azure SDK code. This command returns the content of the markdown file as a string array.',
'parameters': {'type': 'object'}
}
}
]

response = client.chat.completions.create(
model = AZURE_OPENAI_MODEL,
messages = messages,
tools = available_tools)
response_message = response.choices[0].message
print(response_message)
```
I see error:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'azmcp-bestpractices-get': In context=(), object schema missing properties.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'}}

if the tool has parameters, it works fine.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.