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
相关产品推荐
相关产品推荐

