Azure / Azure/azure-sdk-for-python

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

Aperta
#41,447 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Client needs-team-attention OpenAI Service Attention
Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g 2h
PR unite (30g)
213

Descrizione

- **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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start at the client.chat.completions.create entry point and trace how the tools argument is packed when a function's parameters contain only {'type': 'object'}. Reproduce the Windows/Python 3.12.10 case with the shown AzureOpenAI example, then verify that a parameterless tool is accepted while tools with parameters continue to work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.