Google 的 Gemma 3 模型(27B 变体特别强大,我一直在通过 Ollama 进行尝试)仅支持通过提示工程进行函数调用。官方文档描述了两个推荐的提示 – 它们都建议将工具定义作为 JSON 模式传入,但模型请求工具执行的方式不同。
第一个提示使用 Python 风格的函数调用语法:
You have access to functions. If you decide to invoke any of the function(s), you MUST put it in the format of [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]
You SHOULD NOT include any other text in the response if you call a function
(总是喜欢在提示中看到大写字母来强调,这让我想知道他们是否向自己证明大写字母在这种情况下会产生影响。)
第二种变体使用 JSON 代替:
You have access to functions. If you decide to invoke any of the function(s), you MUST put it in the format of {"name": function name, "parameters": dictionary of argument name and its value}
You SHOULD NOT include any other text in the response if you call a function
这是一个简洁的说明,表明所有这些使用 LLM 的奇特工具仍然有效地使用与 2022 年 11 月的 ReAct 论文中描述的相同的模式。这是我在 2023 年 3 月实现的该模式。
通过黑客新闻
标签:提示工程、谷歌、生成人工智能、 llm-工具使用、 gemma 、 ai 、 llms
原文: https://simonwillison.net/2025/Mar/26/function-calling-with-gemma/#atom-everything