news 2026/9/13 21:24:10

Gemini Function Calling 实战指南:从基础声明到并行调用、强制工具配置与多模态输入

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Gemini Function Calling 实战指南:从基础声明到并行调用、强制工具配置与多模态输入

Gemini Function Calling 实战指南:从基础声明到并行调用、强制工具配置与多模态输入

【免费下载链接】generative-aiSample code and notebooks for Generative AI on Google Cloud, with Gemini Enterprise Agent Platform项目地址: https://gitcode.com/GitHub_Trending/ge/generative-ai

导读

本指南以 gemini/function-calling/ 目录下的 README.md 及其 5 个配套 Jupyter Notebook 为技术骨架,系统讲解 Google Cloud Generative AI(Vertex AI + Gemini)中的 Function Calling(函数调用)能力。你将掌握:如何用FunctionDeclaration描述函数、用Tool封装工具、通过Part.from_function_response闭环调用外部 API,并进阶掌握并行函数调用、AUTO/ANY/NONE三种工具配置模式,以及基于图像、视频、音频、PDF 的多模态函数调用。读完本指南,你可以直接复用仓库中的代码示例,构建"能连接外部系统"的 Agent 应用。

什么是 Gemini Function Calling

gemini/function-calling/README.md 对 Function Calling 给出了精确定义:

开发者先在代码中创建对某个函数的描述,然后将该描述随请求一起传给语言模型;模型的响应中会包含与描述匹配的函数名,以及调用它所需的参数。

也就是说,模型本身不执行你的业务代码,它只负责做两件事:从你提供的函数描述集中挑选最合适的函数、从用户的自然语言中抽取该函数所需的参数,然后以结构化的FunctionCall返回。真正的执行发生在你的应用代码里(调用外部 REST API、查询数据库、下单、发邮件等),执行结果再回传给模型,由模型生成面向最终用户的自然语言回复。

为什么需要函数调用:告别"解析自由文本"的痛点

在 intro_function_calling.ipynb 的 Overview 中,作者用一个形象的比喻解释了动机:让一个人"写下重要信息"却不提供任何表单或结构约束,你会得到一段漂亮的散文,但想从中精确提取姓名、日期、数字会非常痛苦。直接要求生成式文本模型输出 JSON 也往往不一致、不可靠。

Function Calling 正是解决这一痛点的"表单":

  • 你定义带有具体参数与数据类型的函数声明,它们成为引导模型的结构化约束;
  • 模型输出被规范化为可预测、可直接使用的结构化对象,无需再解析自由文本;
  • 它架起了"人类语言"与"外部系统所需的结构化数据"之间的桥梁:需要查数据库就定义search_db,需要对接天气 API 就定义get_weather

核心工作流(五个步骤)

从 multimodal_function_calling.ipynb 的 How It Works 小节可以提炼出完整的调用闭环:

  1. 定义函数与工具:用FunctionDeclaration描述函数,并分组打包成Tool对象;
  2. 发送输入与提示:将多模态输入(文本、图像、音频、PDF 等)与提示词一起发送给 Gemini;
  3. 模型预测动作:Gemini 分析输入并预测要调用的函数及其参数;
  4. 执行并回传:在应用代码中执行真实 API 调用,把结果通过Part.from_function_response发回给 Gemini;
  5. 生成回复:Gemini 基于 API 结果生成最终自然语言回复。

环境准备:SDK、认证与项目初始化

目录下所有 notebook 的环境准备步骤完全一致,是可直接复用的最小化启动流程。

1. 安装 Google Gen AI SDK

%pip install --upgrade --quiet google-genai

parallel_function_calling.ipynb 和 forced_function_calling.ipynb 还会额外安装第三方库(wikipediaarxiv),用于演示真实的"外部 API 调用"环节:

%pip install --upgrade --quiet google-genai wikipedia

2. 认证(仅 Colab 环境需要)

如果运行在 Google Colab 上,需要执行认证;使用 Vertex AI Workbench 或本地环境则不需要:

import sys if "google.colab" in sys.modules: from google.colab import auth auth.authenticate_user()

3. 设置项目信息并创建客户端

使用 Vertex AI 的前提是拥有 Google Cloud 项目并启用 Vertex AI API(aiplatform.googleapis.com)。初始化代码在各个 notebook 中几乎一致:

import os PROJECT_ID = "[your-project-id]" if not PROJECT_ID or PROJECT_ID == "[your-project-id]": PROJECT_ID = str(os.environ.get("GOOGLE_CLOUD_PROJECT")) LOCATION = "global" from google import genai client = genai.Client(enterprise=True, project=PROJECT_ID, location=LOCATION)

需要注意两点:

  • PROJECT_ID支持通过GOOGLE_CLOUD_PROJECT环境变量回退获取,方便在 CI 或本地环境中免改代码运行;
  • 目录内 notebook 在genai.Client()的构造上存在enterprise=True(如 intro_function_calling.ipynb、forced_function_calling.ipynb)与vertexai=True(如 parallel_function_calling.ipynb)两种写法,两者都指向 Vertex AI 上的 Gemini API,读者可按实际使用的 Gemini Enterprise Agent Platform 或 Vertex AI 环境选择。

4. 选择模型

本目录示例使用的模型为gemini-3.7-flashgemini-3.5-flash(不同 notebook 略有差异),例如:

MODEL_ID = "gemini-3.7-flash"

模型的选型会影响 Function Calling 的能力边界(如是否支持并行函数调用、是否支持工具配置),官方文档对此有明确说明,具体以当前模型版本的 Gemini Function Calling 文档为准。

三大核心 API 类型:FunctionDeclaration、Tool 与 Part

所有示例都建立在google.genai.types提供的几个类型之上。导入语句统一为:

from google.genai.types import FunctionDeclaration, GenerateContentConfig, Part, Tool

FunctionDeclaration:用 JSON Schema 描述函数

函数声明由三部分组成:函数名、功能描述、参数 Schema。参数遵循 OpenAPI JSON Schema 格式,以 Python 字典书写(这一点在 intro_function_calling.ipynb 中有明确说明):

get_product_info = FunctionDeclaration( name="get_product_info", description="Get the stock amount and identifier for a given product", parameters={ "type": "object", "properties": { "product_name": {"type": "string", "description": "Product name"} }, }, )

函数名与描述的质量直接决定模型能否准确选择函数、正确抽取参数——描述越精确,模型的预测越可靠。

Tool:函数声明的容器

一个Tool可以打包多个函数声明,模型会从其中选择要调用的函数:

retail_tool = Tool( function_declarations=[ get_product_info, get_store_location, place_order, ], )

GenerateContentConfig 与 Part:配置与回传

GenerateContentConfig负责携带toolstemperature等生成参数;Part.from_function_response()则把外部 API 的执行结果以"工具响应"的形式回传给模型:

response = chat.send_message( Part.from_function_response( name="get_product_info", response={ "content": api_response, }, ), )

在 forced_function_calling.ipynb 中还引入了更底层的Content(role="tool", parts=[...])构造方式,同样用于回传工具执行结果。

实战一:多轮对话中的函数调用(Google Store 场景)

intro_function_calling.ipynb 的核心示例是构建一个面向 Google Store 的客服机器人。它演示了 Function Calling 在多轮会话中的完整工作方式。

定义三个业务函数

客服机器人需要三种能力:查询库存、查找最近门店、下单:

get_product_info = FunctionDeclaration( name="get_product_info", description="Get the stock amount and identifier for a given product", parameters={ "type": "object", "properties": { "product_name": {"type": "string", "description": "Product name"} }, }, ) get_store_location = FunctionDeclaration( name="get_store_location", description="Get the location of the closest store", parameters={ "type": "object", "properties": {"location": {"type": "string", "description": "Location"}}, }, ) place_order = FunctionDeclaration( name="place_order", description="Place an order", parameters={ "type": "object", "properties": { "product": {"type": "string", "description": "Product name"}, "address": {"type": "string", "description": "Shipping address"}, }, }, )

初始化带工具的聊天会话

关键技巧:在client.chats.create()初始化时通过config指定tools避免在后续每一轮请求中重复携带

chat = client.chats.create( model=MODEL_ID, config=GenerateContentConfig( temperature=0, tools=[retail_tool], ), )

temperature参数用于控制生成随机性:较低温度适合需要确定性参数值的函数调用场景(如库存查询),较高温度适合参数更开放、更多样的场景;temperature=0表示确定性输出,但即使如此,同一提示词下的响应仍可能存在极小的波动(notebook 中的原话是"mostly deterministic, but a small amount of variation is still possible")。

第一轮:单函数调用

用户提问"Pixel 9 有货吗?",模型返回结构化调用请求:

prompt = """ Do you have the Pixel 9 in stock? """ response = chat.send_message(prompt) response.function_calls[0]

返回结果是一个FunctionCall对象:

FunctionCall( args={'product_name': 'Pixel 9'}, name='get_product_info' )

notebook 在此处用合成数据模拟外部 API 响应(真实场景中应使用自己的客户端库或 REST API 调用库存系统):

api_response = {"sku": "GA04834-US", "in_stock": "yes"}

随后回传给模型并展示最终回答:

response = chat.send_message( Part.from_function_response( name="get_product_info", response={"content": api_response}, ), ) display(Markdown(response.text))

模型输出:"Yes, the Pixel 9 is currently in stock."

第二轮:一次对话触发两个函数调用

当用户同时询问"Pixel 9 Pro XL 有货吗?山景城有店可以试机吗?",Gemini 在单个响应对象中返回了两个FunctionCall

[FunctionCall(args={'product_name': 'Pixel 9 Pro XL'}, name='get_product_info'), FunctionCall(args={'location': 'Mountain View, CA'}, name='get_store_location')]

这正是并行函数调用的体现(详见后文)。处理方式同样简单:分别构造两个外部 API 的模拟响应,然后一次性回传:

response = chat.send_message( [ Part.from_function_response( name="get_product_info", response={"content": product_info_api_response}, ), Part.from_function_response( name="get_store_location", response={"content": store_location_api_response}, ), ] ) display(Markdown(response.text))

第三轮:多参数抽取与下单

用户说"我要订一台 Pixel 9 Pro XL,送到 1155 Borregas Ave, Sunnyvale, CA 94089",模型自动抽取出productaddress两个参数并调用place_order。模拟下单 API 返回payment_statusorder_numberest_arrival后,模型最终生成:"Your order for a Pixel 9 Pro XL has been placed! Your order number is 12345 and it is estimated to arrive in 2 days."

这三轮对话完整覆盖了 Function Calling 的典型闭环:结构化请求 → 外部执行 → 结构化回传 → 自然语言总结,是后续所有高级技巧的基础范式。

实战二:函数参数的数据结构与 Schema

function_calling_data_structures.ipynb 专注于回答一个问题:函数参数到底能有多复杂?它用递进式的四个示例给出了答案。

单参数

最简单的场景——从提示词中抽取一个目的地:

get_destination = FunctionDeclaration( name="get_destination", description="Get directions to a destination", parameters={ "type": "object", "properties": { "destination": { "type": "string", "description": "Destination that the user wants to go to", }, }, }, )

发送"I'd like to travel to Paris",返回{'destination': 'Paris'}

多参数

properties中增加多个键即可。示例定义了destinationmode_of_transportationdeparture_time三个参数:

get_destination_params = FunctionDeclaration( name="get_destination_params", description="Get directions to a destination", parameters={ "type": "object", "properties": { "destination": { "type": "string", "description": "Destination that the user wants to go to", }, "mode_of_transportation": { "type": "string", "description": "Mode of transportation to use", }, "departure_time": { "type": "string", "description": "Time that the user will leave for the destination", }, }, }, )

发送"I'd like to travel to Paris by train and leave at 9:00 am",模型一次性抽取全部三个键值对:{'departure_time': '9:00 am', 'destination': 'Paris', 'mode_of_transportation': 'train'}

参数列表(array + 嵌套 object)

当需要在一次函数调用内处理多个地点时,可以使用array类型,其items为嵌套的object,并可通过required指定必填字段:

get_multiple_location_coordinates = FunctionDeclaration( name="get_location_coordinates", description="Get coordinates of multiple locations", parameters={ "type": "object", "properties": { "locations": { "type": "array", "description": "A list of locations", "items": { "description": "Components of the location", "type": "object", "properties": { "point_of_interest": { "type": "string", "description": "Name or type of point of interest", }, "city": {"type": "string", "description": "City"}, "country": {"type": "string", "description": "Country"}, }, "required": [ "point_of_interest", "city", "country", ], }, } }, }, )

发送包含埃菲尔铁塔、自由女神像、道格拉斯港三个地点的提示词后,模型返回一个包含三个完整对象的locations数组。notebook 特别指出:因为这三个字段都被标记为required,模型为每个地点都填齐了全部字段——这体现了required约束对输出完整性的保障作用。

嵌套数据结构

最复杂的场景——用几句话说清楚商品信息,模型负责填好嵌套的product对象(含namepricecategorydescription):

create_product_listing = FunctionDeclaration( name="create_product_listing", description="Create a product listing using the details provided by the user.", parameters={ "type": "object", "properties": { "product": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"}, "category": {"type": "string"}, "description": {"type": "string"}, }, } }, }, )

提示词"Create a listing for noise-canceling headphones for $149.99. These headphones create a distraction-free environment."被完整抽取为:

{'product': {'category': 'Electronics', 'description': 'These headphones create a distraction-free environment.', 'name': 'Noise-canceling headphones', 'price': 149.99}}

小结:JSON Schema 表达力有多强,函数调用就能支持多复杂的数据结构。从单参数到多层嵌套,模型都会严格按照 Schema 约束输出。

实战三:并行函数调用(Parallel Function Calling)

parallel_function_calling.ipynb 深入讲解了并行函数调用这一高级特性,并给出了清晰的历史背景。

什么是并行函数调用

在 2024 年 5 月之前的旧版 Gemini 中,如果模型判断需要多次调用函数,只能采用"链式"模式:拿到第一个函数调用 → 回传结果 → 再拿第二个函数调用 → 再回传……如此往返。而从 2024 年 5 月起的新版本模型(具体版本以官方文档为准)支持在同一个响应对象内返回两个或更多函数调用

并行调用的核心价值在于:它允许你在应用代码中"扇出"(fan out)并并行执行多个 API 请求,而不是逐个串行往返,从而显著减少与 Gemini API 的交互轮次,改善端到端延迟。

场景一:同一函数的重复并行调用

典型的适用场景是:某个函数每次只能接收一个参数,但一次请求需要处理多个条目。示例用 Wikipedia 搜索演示——单个search_wikipedia函数、三条查询(solar panels、renewable energy、battery storage),一次提示词返回三个FunctionCall

notebook 提供了一个通用的提取辅助函数(可以自行改写为任意目标格式):

def extract_function_calls(response: GenerateContentResponse) -> list[dict]: function_calls: list[dict] = [] for function_call in response.function_calls: function_call_dict: dict[str, dict[str, Any]] = {function_call.name: {}} for key, value in function_call.args.items(): function_call_dict[function_call.name][key] = value function_calls.append(function_call_dict) return function_calls

提取结果:

[{'search_wikipedia': {'query': 'solar panel'}}, {'search_wikipedia': {'query': 'renewable energy'}}, {'search_wikipedia': {'query': 'battery storage power station'}}]

然后在应用代码中循环执行外部 API 调用:

api_response = [] for function_call in function_calls: print(function_call) result = wikipedia.summary(function_call["search_wikipedia"]["query"]) api_response.append(result)

最后一次性批量回传所有结果(三个Part.from_function_response装入一个列表),Gemini 据此生成综合总结。整个过程无需任何额外配置——不需要修改函数声明、工具或请求参数。

场景二:多个独立函数的并行调用

第二个场景定义三个独立函数(search_wikipediasuggest_wikipediasummarize_wikipedia),提示词要求"搜索太阳系、推荐相关术语、总结主文章",模型在一个响应内并行返回对三个函数的调用:

[{'search_wikipedia': {'query': 'Solar System'}}, {'suggest_wikipedia': {'query': 'Solar System'}}, {'summarize_wikipedia': {'topic': 'Solar System'}}]

执行阶段按函数名分发到对应的 Wikipedia API:

for function_call in function_calls: for function_name, function_args in function_call.items(): if function_name == "search_wikipedia": result = wikipedia.search(function_args["query"]) if function_name == "suggest_wikipedia": result = wikipedia.suggest(function_args["query"]) if function_name == "summarize_wikipedia": result = wikipedia.summary(function_args["topic"], auto_suggest=False) api_response[function_name] = result

最后按函数名将结果批量回传(使用api_response.get(function_name, "")防缺失)。

重要提示(notebook 原文强调):Gemini 会根据FunctionDeclaration中的信息自主决定哪些调用可以并行、哪些调用必须在其他调用之后执行(即存在依赖关系时)。因此你的应用逻辑必须同时兼容"并行响应"与"串行依赖"两种情况。

实战四:强制函数调用与工具配置(AUTO / ANY / NONE)

forced_function_calling.ipynb 展示了用ToolConfig控制模型行为的三种模式。其示例围绕 arXiv 论文搜索函数search_arxiv展开(该函数声明使用了Schema/Type类型的替代写法,与字典写法等价)。

三种模式的语义

tool_config = ToolConfig( function_calling_config=FunctionCallingConfig( mode=FunctionCallingConfigMode.AUTO, # 默认行为:模型自行决定是预测函数调用还是自然语言回复 allowed_function_names=["function_to_call"], # ANY 模式下允许调用的函数子集;为空则允许调用任一已提供函数 ) )
模式行为
AUTO(默认)模型根据提示词自主决定是否调用函数、调用哪个函数,也可直接输出自然语言回复
ANY强制模型从allowed_function_names指定的函数子集中预测一个函数调用(列表为空则从全部已声明函数中选)
NONE禁用函数调用,等价于未提供任何函数声明,模型仅生成自然语言回复

AUTO 模式:默认行为

不设置tool_config时即为AUTO。示例中显式设置以便对照:

config.tool_config = ToolConfig( function_calling_config=FunctionCallingConfig( mode=FunctionCallingConfigMode.AUTO, ) )

对提示词"用几句话解释强化学习,并给出 arXiv 上的论文"——模型直接返回了自然语言总结,没有调用search_arxiv。这正是 AUTO 模式的特性:是否调用函数完全由模型判断,结果并不总是符合开发者的预期。

ANY 模式:强制调用

设置ANY并指定allowed_function_names=["search_arxiv"]后,同样的提示词被强制触发函数调用:

config.tool_config = ToolConfig( function_calling_config=FunctionCallingConfig( mode=FunctionCallingConfigMode.ANY, allowed_function_names=["search_arxiv"], ) )

模型返回:

FunctionCall( args={'query': 'Deep Reinforcement Learning survey overview introduction'}, name='search_arxiv' )

随后应用代码用arxiv包执行真实搜索(arxiv.Search(query=params["query"], max_results=3, sort_by=arxiv.SortCriterion.Relevance)),再把结果构造为Content(role="tool", parts=[Part.from_function_response(...)])回传,模型最终生成包含真实论文清单与推荐理由的回复。

NONE 模式:完全禁用

config.tool_config = ToolConfig( function_calling_config=FunctionCallingConfig( mode=FunctionCallingConfigMode.NONE, ) )

NONE模式下模型只依赖训练数据生成回答,即使提示词明确索要 arXiv 论文,也不会调用search_arxiv。notebook 用它直观地对比出"调用工具获取实时数据"与"纯模型知识作答"的差异。

适用场景总结

  • AUTO:大多数常规场景,让模型智能判断;
  • ANY:流程要求必须触发函数调用的场景(如先查数据库再回答、结构化信息抽取管线、按固定流程执行的 Agent);
  • NONE:临时禁用工具(如某些回复希望走纯模型通道)、A/B 对比、调试。

实战五:多模态函数调用(图像 / 视频 / 音频 / PDF)

multimodal_function_calling.ipynb 是目录中最具前瞻性的示例,展示了Gemini 的输入模态不止于文本——函数调用可以基于图像、视频、音频和 PDF 触发。notebook 明确指出,这一能力也被称为"带受控生成的函数调用"(function calling with controlled generation),保证输出始终符合特定 Schema。它用一个 API 调用取代了以往"先抽取媒体信息文本、再生成函数调用"的两段式流程,避免了信息损失与工程复杂度。

所有多模态示例的统一模式是:用Part.from_uri(file_uri=..., mime_type=...)注入媒体文件,配合提示词与tools配置调用client.models.generate_content

图像输入:识别动物并查询栖息地

定义get_wildlife_region函数,输入一张鸟类图片(多色鸟,Lilac-breasted Roller):

response = client.models.generate_content( model=MODEL_ID, contents=[ Part.from_uri( file_uri="gs://github-repo/generative-ai/gemini/function-calling/multi-color-bird.jpg", mime_type="image/jpeg", ), "What is the typical habitat or region where this animal lives?", ], config=GenerateContentConfig(temperature=0, tools=[image_tool]), )

模型返回{'animal': 'Lilac-breasted Roller'}。随后用wikipedia.page(function_args["animal"]).content做真实 API 调用,将结果以Content(role="tool", ...)回传,Gemini 最终生成包含分布区域、典型栖息地描述的完整回答。注意:最终回传时需要在contents中带上原始的UserContent(图片 + 提示)与模型的model_response_content(函数调用),保持多轮上下文完整。

视频输入:识别产品特性

get_feature_info函数从一段 "Made by Google" 发布视频(MP4)中提取产品功能列表,返回的features数组中包含了 Gemini、Gemini Live、Pixel 9 系列、Pixel Studio、Pixel Watch 3、Pixel Buds Pro 2 等结构化条目——这些参数严格遵循FunctionDeclaration中定义的 JSON Schema。

音频输入:基于播客内容推荐书目

get_recommended_books函数接收播客音频(MP3),模型从中识别出 Site Reliability Engineering、System Thinking、Scalability、Incident Response 等主题词列表,可用于后续的书籍推荐 API。

PDF 输入:从发票中抽取公司名

get_company_information函数同时接收5 份合成发票 PDF,模型一次调用即抽取出全部虚构公司名(AMNOSH SUPPLIERS、BIKBEAR LAW FIRM 等),展示了文档处理场景(如财务自动化、KYC)中"文档 → 结构化数据"的直接通路。

综合示例:多模态聊天机器人

最后,notebook 把多模态与多轮对话结合,构建了一个"看图聊天"机器人:定义get_animal_detailssearch_similar_imagescheck_color_palette三个函数,在client.chats.create()中注入工具后,用户依次发送同一张狐狸图片的不同指令——"介绍图中的动物"触发get_animal_details、"找相似图片"触发search_similar_images(抽取query: 'red fox in a grassy field with flowers')、"提取色板并检查可访问性"触发check_color_palette(返回十六进制色值数组)。该示例虽未真正执行函数,但完整演示了"多模态输入 + 函数调用 + 聊天"的交互式 Agent 形态。

仓库内配套资源一览

  • gemini/function-calling/README.md:目录总览,含四个官方入口 notebook 的描述表格;
  • gemini/function-calling/intro_function_calling.ipynb:入门必读,多轮对话 + 地理编码两大实战;
  • gemini/function-calling/function_calling_data_structures.ipynb:参数 Schema 从简到繁的完整演进;
  • gemini/function-calling/parallel_function_calling.ipynb:并行调用的两个典型场景与批量回传范式;
  • gemini/function-calling/forced_function_calling.ipynb:AUTO/ANY/NONE三种工具配置模式的对照实验;
  • gemini/function-calling/multimodal_function_calling.ipynb:图像、视频、音频、PDF 四类多模态输入 + 多模态聊天机器人。

在整个仓库的上下文中,Function Calling 是 gemini/ 目录下的核心能力之一(gemini/README.md 在 "Using this repository" 一节将其单列为function-calling/学习入口),并与仓库中的 Agent Engine、MCP、Agent 示例(如 agents/adk/、gemini/agent-engine/)共同构成 Gemini 驱动的智能体应用技术栈——函数调用正是这些 Agent 与外部世界交互的"手和脚"。

总结与进阶路径

通过本指南,你已经掌握了 Gemini Function Calling 的完整技能栈:

  1. 基础闭环FunctionDeclaration声明 →Tool打包 → 聊天/内容生成 →Part.from_function_response回传 → 自然语言总结;
  2. Schema 设计:单参数、多参数、数组、嵌套对象与required约束,覆盖绝大多数结构化输出需求;
  3. 并行调用:一次响应内处理多个(同函数或跨函数)调用并批量回传,降低交互延迟;
  4. 工具配置AUTO/ANY/NONE三种模式精确控制模型行为,适配不同业务流程;
  5. 多模态扩展:图像、视频、音频、PDF 均可作为函数调用决策的输入,开启"能看、能听、能读"的智能应用。

建议的进阶路线:先完整运行 intro_function_calling.ipynb 打牢基础,再根据业务需要选读 function_calling_data_structures.ipynb(结构化输出)与 parallel_function_calling.ipynb(性能优化),随后用 forced_function_calling.ipynb 精细化控制行为,最后通过 multimodal_function_calling.ipynb 突破纯文本限制。更进一步,可将函数调用能力与仓库中的 Agent Engine 结合,构建生产级的 Agent 应用。

【免费下载链接】generative-aiSample code and notebooks for Generative AI on Google Cloud, with Gemini Enterprise Agent Platform项目地址: https://gitcode.com/GitHub_Trending/ge/generative-ai

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/13 21:22:25

企业IT服务创新:模块化设计与生产力转化实践

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/9/13 21:22:20

高并发秒杀库存超卖?AI实时对账与自动补偿方案实战解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/9/13 21:20:29

用MATLAB实现PQ分解法潮流计算:从IEEE 14节点到N-1分析

简介:IEEE标准14节点PQ分解法MATLAB程序(.m)是一份面向电力系统专业学生、研究人员与工程初学者的仿真算法源码,用于在14节点标准算例上进行快速潮流计算与稳态分析。程序基于PQ分解思想,将潮流方程组拆分为P-θ与Q-V两…

作者头像 李华