You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VertexAI中Gemini-Pro调用含对象数组的FunctionDeclaration报500错误

Vertex AI Gemini-Pro函数调用中对象数组参数引发500错误的问题

在Vertex AI中使用Gemini-Pro函数调用功能时,简单函数调用可正常运行,但当函数声明中包含对象数组类型的属性时,会抛出InternalServerError: 500 Internal error encountered错误。

触发错误的代码示例(contact为对象数组)

from vertexai.preview.generative_models import FunctionDeclaration, GenerativeModel, GenerationConfig, Tool


function = {
    'name': 'Save',
    'description': 'Saves contact data for a person',
    'parameters': {
        'type_': 'OBJECT',
        'properties': {
            'name': {
                'type_': 'STRING',
                'description': "The person's name"
            },
            'contact': {
                'type_': 'ARRAY',
                'description': "The person's contact information",
                'items': {
                    'type_': 'OBJECT',
                    'description': 'Contact information for the person in a specific context',
                    'properties': {
                        'email': {
                            'type_': 'STRING',
                            'description': "The person's email"
                        },
                        'phone': {
                            'type_': 'STRING',
                            'description': "The person's phone number"
                        },
                        'context': {
                            'type_': 'STRING',
                            'description': 'The context in which the contact information is applicable',
                            'enum': ['work', 'personal', 'other']
                        }
                    },
                }
            }
        }
    }
}

func = FunctionDeclaration(**function)

prompt = (
    "Extract the contact information from the below data and store it using the function provided.\n"
    "John Smith, work: john.smith@smithinc.com, 212-555-5309, home: johnny@thesmiths.com, 917-555-9512"
)

config = GenerationConfig(
    temperature=0.1,
    top_p=0.95,
    top_k=20,
    candidate_count=1,
    max_output_tokens=2048,
    stop_sequences=[]
)

llm = GenerativeModel('gemini-pro', generation_config=config, tools=[Tool(function_declarations=[func])])
llm.generate_content(prompt, stream=False)

正常运行的代码示例(contact为单个对象)

function = {
    'name': 'Save',
    'description': 'Saves contact data for a person',
    'parameters': {
        'type_': 'OBJECT',
        'properties': {
            'name': {
                'type_': 'STRING',
                'description': "The person's name"
            },
            'contact': {
                'type_': 'OBJECT',
                'description': "The person's contact information",
                'properties': {
                    'email': {
                        'type_': 'STRING',
                        'description': "The person's email"
                    },
                    'phone': {
                        'type_': 'STRING',
                        'description': "The person's phone number"
                    },
                    'context': {
                        'type_': 'STRING',
                        'description': 'The context in which the contact information is applicable',
                        'enum': ['work', 'personal', 'other']
                    }
                }
            }
        }
    }
}

正常运行的代码示例(contact的子属性为字符串数组)

function = {
    'name': 'Save',
    'description': 'Saves contact data for a person',
    'parameters': {
        'type_': 'OBJECT',
        'properties': {
            'name': {
                'type_': 'STRING',
                'description': "The person's name"
            },
            'contact': {
                'type_': 'OBJECT',
                'description': "The person's contact information",
                'properties': {
                    'email': {
                        'type_': 'ARRAY',
                        'description': "The person's email addresses",
                        'items': {'type_': 'STRING'}
                    },
                    'phone': {
                        'type_': 'ARRAY',
                        'description': "The person's phone numbers",
                        'items': {'type_': 'STRING'}
                    }
                }
            }
        }
    }
}

请问第一段函数声明中哪里出现了错误?


内容的提问来源于stack exchange,提问作者Dev Developer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:33:17