<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>素问 - iOS技术</title><link>https://suwenclub.cn/</link><description>做一件事，做到极致</description><item><title>全文转载：OpenHarmony TaskPool 指定任务并发度场景</title><link>https://suwenclub.cn/?id=45</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;OpenHarmony TaskPool 指定任务并发度场景&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;OpenHarmony docs contributors / OpenHarmony docs&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://github.com/openharmony/docs/blob/master/zh-cn/application-dev/arkts-utils/taskpool-async-task-guide.md&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/openharmony/docs/blob/master/zh-cn/application-dev/arkts-utils/taskpool-async-task-guide.md&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://github.com/openharmony/docs/blob/master/LICENSE&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 International (CC BY 4.0)&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 OpenHarmony docs 开源文档仓库，按 CC BY 4.0 署名转载。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;h1 dir=&quot;auto&quot;&gt;TaskPool指定任务并发度场景&lt;/h1&gt;
&lt;p dir=&quot;auto&quot;&gt;TaskPool支持使用异步队列来控制任务的并发度，能有效避免资源过载，减少任务阻塞，适用于网络请求、视频流处理和数据库操作等场景。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;此处提供使用TaskPool创建&lt;a href=&quot;../reference/apis-arkts/js-apis-taskpool.md#asyncrunner18&quot;&gt;异步队列&lt;/a&gt;的开发指导，以相机预览流采集数据处理的功能为例。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;由于处理过程是一个频繁且耗时的任务，当相机采集速度过快时，将丢弃之前的采集数据，仅保留最新的一帧数据进行处理。&lt;/p&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;导入需要用到的模块。&lt;/p&gt;
&lt;div class=&quot;highlight highlight-source-ts&quot; dir=&quot;auto&quot;&gt;&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;pl-c&quot;&gt;// TaskpoolAsyncLevel.ets&lt;/span&gt;
&lt;span class=&quot;pl-k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;taskpool&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'@kit.ArkTS'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;pl-k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;pl-v&quot;&gt;BusinessError&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'@kit.BasicServicesKit'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;pl-k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;pl-v&quot;&gt;PromptAction&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'@kit.ArkUI'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;定义耗时任务。&lt;/p&gt;
&lt;div class=&quot;highlight highlight-source-ts&quot; dir=&quot;auto&quot;&gt;&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;pl-c&quot;&gt;// TaskpoolAsyncLevel.ets&lt;/span&gt;
@&lt;span class=&quot;pl-v&quot;&gt;Concurrent&lt;/span&gt;
&lt;span class=&quot;pl-k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;pl-en&quot;&gt;collectFrame&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;pl-c&quot;&gt;// 采集数据，并且进行处理&lt;/span&gt;
  &lt;span class=&quot;pl-c&quot;&gt;// 模拟处理过程，这里是个耗时任务，持续时间为30秒&lt;/span&gt;
  &lt;span class=&quot;pl-k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-v&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;pl-k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-v&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;30000&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;pl-k&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;pl-smi&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'collectFrame finished'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;创建异步队列并执行采集任务。&lt;/p&gt;
&lt;div class=&quot;highlight highlight-source-ts&quot; dir=&quot;auto&quot;&gt;&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;pl-c&quot;&gt;// TaskpoolAsyncLevel.ets&lt;/span&gt;
@&lt;span class=&quot;pl-v&quot;&gt;Entry&lt;/span&gt;
@&lt;span class=&quot;pl-v&quot;&gt;Component&lt;/span&gt;
&lt;span class=&quot;pl-s1&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;pl-v&quot;&gt;TaskpoolAsyncLevel&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
  @&lt;span class=&quot;pl-v&quot;&gt;State&lt;/span&gt; message: &lt;span class=&quot;pl-s1&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'触发采集任务'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
  @&lt;span class=&quot;pl-v&quot;&gt;State&lt;/span&gt; returnMessage: &lt;span class=&quot;pl-s1&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'return...'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
  @&lt;span class=&quot;pl-v&quot;&gt;State&lt;/span&gt; promptAction: &lt;span class=&quot;pl-v&quot;&gt;PromptAction&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-smi&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;getUIContext&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;getPromptAction&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
  
  &lt;span class=&quot;pl-en&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;pl-en&quot;&gt;Row&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;pl-v&quot;&gt;Column&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;pl-v&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;fontSize&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;fontWeight&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-v&quot;&gt;FontWeight&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;Bold&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;pl-c&quot;&gt;// 创建并发度为5的异步队列，等待队列个数为5，当加入的任务数量超过5时，等待列表中处于队头的任务会被丢弃&lt;/span&gt;
            &lt;span class=&quot;pl-k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;asyncRunner&lt;/span&gt;:&lt;span class=&quot;pl-s1&quot;&gt;taskpool&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;AsyncRunner&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;taskpool&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;AsyncRunner&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'async'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;pl-c&quot;&gt;// 触发采集任务&lt;/span&gt;
            &lt;span class=&quot;pl-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;pl-k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;task&lt;/span&gt;:&lt;span class=&quot;pl-s1&quot;&gt;taskpool&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;taskpool&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;`async&lt;span class=&quot;pl-s1&quot;&gt;&lt;span class=&quot;pl-kos&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;pl-s1&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;/span&gt;`&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pl-s1&quot;&gt;collectFrame&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
              &lt;span class=&quot;pl-s1&quot;&gt;asyncRunner&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s1&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;pl-smi&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'the current task name is '&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
              &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s1&quot;&gt;e&lt;/span&gt;:&lt;span class=&quot;pl-smi&quot;&gt;BusinessError&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;pl-smi&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'async: error is '&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;pl-s1&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
              &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;pl-smi&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'asyncRunner task finished'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;pl-smi&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;returnMessage&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;'asyncRunner task finished'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;pl-smi&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;promptAction&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;showToast&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;message&lt;/span&gt;: &lt;span class=&quot;pl-smi&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;returnMessage&lt;/span&gt; &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;pl-c&quot;&gt;// ...&lt;/span&gt;
      &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'100%'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;&lt;/span&gt;
    &lt;span class=&quot;pl-kos&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-en&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pl-s&quot;&gt;'100%'&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;</description><pubDate>Wed, 17 Jun 2026 12:27:00 +0800</pubDate></item><item><title>全文转载：OpenHarmony UIAbility 组件概述</title><link>https://suwenclub.cn/?id=44</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;OpenHarmony UIAbility 组件概述&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;OpenHarmony docs contributors / OpenHarmony docs&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://github.com/openharmony/docs/blob/master/zh-cn/application-dev/application-models/uiability-overview.md&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/openharmony/docs/blob/master/zh-cn/application-dev/application-models/uiability-overview.md&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://github.com/openharmony/docs/blob/master/LICENSE&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 International (CC BY 4.0)&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 OpenHarmony docs 开源文档仓库，按 CC BY 4.0 署名转载。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;h1 dir=&quot;auto&quot;&gt;UIAbility组件概述&lt;/h1&gt;
&lt;h2 dir=&quot;auto&quot;&gt;概述&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;a href=&quot;../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md&quot;&gt;UIAbility&lt;/a&gt;组件是一种包含UI的应用组件，主要用于和用户交互。例如，图库类应用可以在UIAbility组件中展示图片瀑布流。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;UIAbility的设计理念：&lt;/p&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;支持应用组件级的跨端迁移和多端协同。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;支持多设备和多窗口形态。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p dir=&quot;auto&quot;&gt;UIAbility划分原则与建议：&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;UIAbility组件是系统调度的基本单元，为应用提供绘制界面的窗口。一个应用可以包含一个或多个UIAbility组件。例如，在支付应用中，可以将入口功能和收付款功能分别配置为独立的UIAbility。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;每一个UIAbility组件实例都会在最近任务列表中显示一个对应的任务。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;对于开发者而言，可以根据具体场景选择单个还是多个UIAbility，划分建议如下：&lt;/p&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;如果开发者希望在任务视图中看到一个任务，建议使用“一个UIAbility+多个页面”的方式，可以避免不必要的资源加载。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p dir=&quot;auto&quot;&gt;如果开发者希望在任务视图中看到多个任务，或者需要同时开启多个窗口，建议使用多个UIAbility实现不同的功能。&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;例如，即时通讯类应用中的消息列表与音视频通话采用不同的UIAbility进行开发，既可以方便地切换任务窗口，又可以实现应用的两个任务窗口在一个屏幕上分屏显示。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;说明&lt;/strong&gt;：&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;任务视图用于快速查看和管理当前设备上运行的所有任务或应用。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 dir=&quot;auto&quot;&gt;声明配置&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;为使应用能够正常使用UIAbility，需要在&lt;a href=&quot;../quick-start/module-configuration-file.md&quot;&gt;module.json5配置文件&lt;/a&gt;的&lt;a href=&quot;../quick-start/module-configuration-file.md#abilities%E6%A0%87%E7%AD%BE&quot;&gt;abilities标签&lt;/a&gt;中声明UIAbility的名称、入口、标签等相关信息。&lt;/p&gt;
&lt;div class=&quot;highlight highlight-source-js&quot; dir=&quot;auto&quot;&gt;&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;pl-s&quot;&gt;&quot;module&quot;&lt;/span&gt;: &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;pl-c&quot;&gt;// ···&lt;/span&gt;
    &lt;span class=&quot;pl-s&quot;&gt;&quot;abilities&quot;&lt;/span&gt;: &lt;span class=&quot;pl-kos&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;pl-kos&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;EntryAbility&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件的名称&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;srcEntry&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;./ets/entryability/EntryAbility.ets&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件的代码路径&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;description&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;$string:EntryAbility_desc&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件的描述信息&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;icon&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;$media:layered_image&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件的图标&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;label&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;$string:EntryAbility_label&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件对用户显示的名称&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;startWindowIcon&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;$media:startIcon&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件启动页面图标资源文件的索引&lt;/span&gt;
        &lt;span class=&quot;pl-s&quot;&gt;&quot;startWindowBackground&quot;&lt;/span&gt;: &lt;span class=&quot;pl-s&quot;&gt;&quot;$color:start_window_background&quot;&lt;/span&gt;&lt;span class=&quot;pl-kos&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;pl-c&quot;&gt;// UIAbility组件启动页面背景颜色资源文件的索引&lt;/span&gt;
        &lt;span class=&quot;pl-c&quot;&gt;// ···&lt;/span&gt;
      &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;pl-kos&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;pl-c&quot;&gt;// ···&lt;/span&gt;
  &lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;pl-kos&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</description><pubDate>Wed, 17 Jun 2026 12:24:00 +0800</pubDate></item><item><title>全文转载：Gemini API 结构化输出</title><link>https://suwenclub.cn/?id=43</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Gemini API 结构化输出&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Google AI for Developers / Google AI for Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developers.google.com/site-policies?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 / Apache 2.0 for code samples&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Google AI for Developers 官方中文文档。页面文字为 CC BY 4.0，代码示例为 Apache 2.0。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;
&lt;/p&gt;

&lt;div id=&quot;gemini-api-switcher-trigger&quot; style=&quot;display:none;&quot;&gt;&lt;/div&gt;

&lt;h1 class=&quot;devsite-page-title&quot; id=&quot;structured-outputs&quot; tabindex=&quot;-1&quot;&gt;结构化输出&lt;/h1&gt;

&lt;p&gt;您可以配置 Gemini 模型，使其生成的回答符合提供的 JSON 架构。这样可以确保获得可预测的类型安全结果，并简化从非结构化文本中提取结构化数据的过程。&lt;/p&gt;

&lt;p&gt;使用结构化输出非常适合以下情况：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;数据提取&lt;/strong&gt;：从文本中提取特定信息，例如姓名和日期。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;结构化分类&lt;/strong&gt;：将文本分类为预定义的类别。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;智能体工作流&lt;/strong&gt;：为工具或 API 生成结构化输入。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;除了在 REST API 中支持 JSON 架构之外，Google GenAI SDK 还可让您使用 &lt;a href=&quot;https://docs.pydantic.dev/latest/&quot;&gt;Pydantic&lt;/a&gt; (Python) 和 &lt;a href=&quot;https://zod.dev/&quot;&gt;Zod&lt;/a&gt; (JavaScript) 轻松定义架构。&lt;/p&gt;

&lt;h2 id=&quot;structured_output_examples&quot; tabindex=&quot;-1&quot;&gt;结构化输出示例&lt;/h2&gt;

&lt;h3 id=&quot;recipe&quot; tabindex=&quot;-1&quot;&gt;Recipe Extractor&lt;/h3&gt;

&lt;p&gt;此示例演示了如何使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;object&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;array&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;string&lt;/code&gt; 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;integer&lt;/code&gt; 等基本 JSON 架构类型从文本中提取结构化数据。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;typing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Optional&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;Ingredient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Name of the ingredient.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;quantity&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Quantity of the ingredient, including units.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;Recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;recipe_name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;prep_time_minutes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Optional time in minutes to prepare the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;ingredients&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Ingredient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;instructions&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Please extract the recipe from the following text.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;The user wants to make delicious chocolate chip cookies.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;They need 2 and 1/4 cups of all-purpose flour, 1 teaspoon of baking soda,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;1 teaspoon of salt, 1 cup of unsalted butter (softened), 3/4 cup of granulated sugar,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;3/4 cup of packed brown sugar, 1 teaspoon of vanilla extract, and 2 large eggs.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;For the best part, they'll need 2 cups of semisweet chocolate chips.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;First, preheat the oven to 375°F (190°C). Then, in a small bowl, whisk together the flour,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;baking soda, and salt. In a large bowl, cream together the butter, granulated sugar, and brown sugar&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;until light and fluffy. Beat in the vanilla and eggs, one at a time. Gradually beat in the dry&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;ingredients until just combined. Finally, stir in the chocolate chips. Drop by rounded tablespoons&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;onto ungreased baking sheets and bake for 9 to 11 minutes.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response_format&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_json_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;recipe&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_validate_json&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod-to-json-schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ingredientSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Name of the ingredient.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;quantity&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Quantity of the ingredient, including units.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipe_name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prep_time_minutes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Optional time in minutes to prepare the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ingredients&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ingredientSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;instructions&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;Please extract the recipe from the following text.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;The user wants to make delicious chocolate chip cookies.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;They need 2 and 1/4 cups of all-purpose flour, 1 teaspoon of baking soda,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;1 teaspoon of salt, 1 cup of unsalted butter (softened), 3/4 cup of granulated sugar,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;3/4 cup of packed brown sugar, 1 teaspoon of vanilla extract, and 2 large eggs.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;For the best part, they'll need 2 cups of semisweet chocolate chips.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;First, preheat the oven to 375°F (190°C). Then, in a small bowl, whisk together the flour,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;baking soda, and salt. In a large bowl, cream together the butter, granulated sugar, and brown sugar&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;until light and fluffy. Beat in the vanilla and eggs, one at a time. Gradually beat in the dry&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;ingredients until just combined. Finally, stir in the chocolate chips. Drop by rounded tablespoons&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;onto ungreased baking sheets and bake for 9 to 11 minutes.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;recipe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;log&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  Please extract the recipe from the following text.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  The user wants to make delicious chocolate chip cookies.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  They need 2 and 1/4 cups of all-purpose flour, 1 teaspoon of baking soda,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  1 teaspoon of salt, 1 cup of unsalted butter (softened), 3/4 cup of granulated sugar,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  3/4 cup of packed brown sugar, 1 teaspoon of vanilla extract, and 2 large eggs.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  For the best part, they'll need 2 cups of semisweet chocolate chips.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  First, preheat the oven to 375°F (190°C). Then, in a small bowl, whisk together the flour,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  baking soda, and salt. In a large bowl, cream together the butter, granulated sugar, and brown sugar&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  until light and fluffy. Beat in the vanilla and eggs, one at a time. Gradually beat in the dry&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  ingredients until just combined. Finally, stir in the chocolate chips. Drop by rounded tablespoons&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  onto ungreased baking sheets and bake for 9 to 11 minutes.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  `&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseMIMEType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;recipe_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;The name of the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;prep_time_minutes&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;integer&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Optional time in minutes to prepare the recipe.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;ingredients&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Name of the ingredient.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Quantity of the ingredient, including units.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;instructions&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;recipe_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;ingredients&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;instructions&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;contents&quot;: [{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;:[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          { &quot;text&quot;: &quot;Please extract the recipe from the following text.\nThe user wants to make delicious chocolate chip cookies.\nThey need 2 and 1/4 cups of all-purpose flour, 1 teaspoon of baking soda,\n1 teaspoon of salt, 1 cup of unsalted butter (softened), 3/4 cup of granulated sugar,\n3/4 cup of packed brown sugar, 1 teaspoon of vanilla extract, and 2 large eggs.\nFor the best part, they will need 2 cups of semisweet chocolate chips.\nFirst, preheat the oven to 375°F (190°C). Then, in a small bowl, whisk together the flour,\nbaking soda, and salt. In a large bowl, cream together the butter, granulated sugar, and brown sugar\nuntil light and fluffy. Beat in the vanilla and eggs, one at a time. Gradually beat in the dry\ningredients until just combined. Finally, stir in the chocolate chips. Drop by rounded tablespoons\nonto ungreased baking sheets and bake for 9 to 11 minutes.&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;responseFormat&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;text&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;mimeType&quot;: &quot;application/json&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;schema&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;recipe_name&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;description&quot;: &quot;The name of the recipe.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;prep_time_minutes&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;type&quot;: &quot;integer&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;description&quot;: &quot;Optional time in minutes to prepare the recipe.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;ingredients&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;items&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;name&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Name of the ingredient.&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;quantity&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Quantity of the ingredient, including units.&quot;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;required&quot;: [&quot;name&quot;, &quot;quantity&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;instructions&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;items&quot;: { &quot;type&quot;: &quot;string&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;required&quot;: [&quot;recipe_name&quot;, &quot;ingredients&quot;, &quot;instructions&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;示例回答&lt;/strong&gt;：&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JSON&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;recipe_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Delicious Chocolate Chip Cookies&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;ingredients&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;all-purpose flour&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;2 and 1/4 cups&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;baking soda&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;1 teaspoon&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;salt&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;1 teaspoon&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;unsalted butter (softened)&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;1 cup&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;granulated sugar&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;3/4 cup&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;packed brown sugar&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;3/4 cup&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;vanilla extract&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;1 teaspoon&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;large eggs&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;2&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;semisweet chocolate chips&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;2 cups&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;instructions&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Preheat the oven to 375°F (190°C).&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;In a small bowl, whisk together the flour, baking soda, and salt.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;In a large bowl, cream together the butter, granulated sugar, and brown sugar until light and fluffy.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Beat in the vanilla and eggs, one at a time.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Gradually beat in the dry ingredients until just combined.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Stir in the chocolate chips.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Drop by rounded tablespoons onto ungreased baking sheets and bake for 9 to 11 minutes.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;h3 id=&quot;feedback&quot; tabindex=&quot;-1&quot;&gt;内容审核&lt;/h3&gt;

&lt;p&gt;此示例展示了 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;anyOf&lt;/code&gt;（用于条件架构）和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;（用于分类），从而使输出结构能够根据内容而变化。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_1&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;typing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Literal&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;SpamDetails&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;reason&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The reason why the content is considered spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;spam_type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Literal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;phishing&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;scam&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;unsolicited promotion&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;other&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The type of spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;NotSpamDetails&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;A brief summary of the content.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;is_safe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Whether the content is safe for all audiences.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;ModerationResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;decision&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SpamDetails&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;NotSpamDetails&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Please moderate the following content and provide a decision.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Content: 'Congratulations! You''ve won a free cruise to the Bahamas. Click here to claim your prize: www.definitely-not-a-scam.com'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response_format&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;ModerationResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_json_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;ModerationResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_validate_json&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_1&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod-to-json-schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;spamDetailsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;reason&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The reason why the content is considered spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;spam_type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;phishing&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;scam&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;unsolicited promotion&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;other&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The type of spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;notSpamDetailsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;A brief summary of the content.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;is_safe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;boolean&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Whether the content is safe for all audiences.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;moderationResultSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;decision&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;spamDetailsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;notSpamDetailsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;Please moderate the following content and provide a decision.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;Content: 'Congratulations! You''ve won a free cruise to the Bahamas. Click here to claim your prize: www.definitely-not-a-scam.com'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;moderationResultSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;moderationResultSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_1&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;log&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  Please moderate the following content and provide a decision.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  Content: 'Congratulations! You''ve won a free cruise to the Bahamas. Click here to claim your prize: www.definitely-not-a-scam.com'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  `&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseMIMEType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;decision&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;anyOf&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;SpamDetails&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Details for content classified as spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;reason&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;The reason why the content is considered spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;spam_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;enum&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;phishing&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;scam&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;unsolicited promotion&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;other&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;The type of spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;reason&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;spam_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;NotSpamDetails&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Details for content classified as not spam.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;summary&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;A brief summary of the content.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;is_safe&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;boolean&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Whether the content is safe for all audiences.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;summary&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;is_safe&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;decision&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_1&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;contents&quot;: [{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;:[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          { &quot;text&quot;: &quot;Please moderate the following content and provide a decision.\nContent: ''Congratulations! You have won a free cruise to the Bahamas. Click here to claim your prize: www.definitely-not-a-scam.com''&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;responseFormat&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;text&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;mimeType&quot;: &quot;application/json&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;schema&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;decision&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;anyOf&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;title&quot;: &quot;SpamDetails&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;Details for content classified as spam.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;reason&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;The reason why the content is considered spam.&quot; },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;spam_type&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;enum&quot;: [&quot;phishing&quot;, &quot;scam&quot;, &quot;unsolicited promotion&quot;, &quot;other&quot;], &quot;description&quot;: &quot;The type of spam.&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;required&quot;: [&quot;reason&quot;, &quot;spam_type&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                 },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                 {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;title&quot;: &quot;NotSpamDetails&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;description&quot;: &quot;Details for content classified as not spam.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                     &quot;summary&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;A brief summary of the content.&quot; },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                     &quot;is_safe&quot;: { &quot;type&quot;: &quot;boolean&quot;, &quot;description&quot;: &quot;Whether the content is safe for all audiences.&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                   &quot;required&quot;: [&quot;summary&quot;, &quot;is_safe&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                 }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;               ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;             }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;           },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;           &quot;required&quot;: [&quot;decision&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;         }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;       }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;     }'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;```&lt;/span&gt;

**Example&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;Response:**

&lt;span class=&quot;devsite-syntax-sb&quot;&gt;```&lt;/span&gt;json
&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;decision&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;reason&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The content is an unsolicited prize notification attempting to trick the user into clicking a suspicious link.&quot;&lt;/span&gt;,
&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;spam_type&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;scam&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;recursive&quot; tabindex=&quot;-1&quot;&gt;递归结构&lt;/h3&gt;

&lt;p&gt;此示例展示了如何定义递归架构，例如组织结构图。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_2&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;typing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;Employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Represents an employee in an organization.&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;reports&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Employee&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;default_factory&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;A list of employees reporting to this employee.&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Generate an organization chart for a small team.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;The manager is Alice, who manages Bob and Charlie. Bob manages David.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response_format&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_json_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;employee&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_validate_json&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_2&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod-to-json-schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employeeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;reports&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&amp;gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employeeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;A list of employees reporting to this employee.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;Generate an organization chart for a small team.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;The manager is Alice, who manages Bob and Charlie. Bob manages David.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employeeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employeeSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;employee&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_2&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;log&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  Generate an organization chart for a small team.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  The manager is Alice, who manages Bob and Charlie. Bob manages David.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s&quot;&gt;  `&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseMIMEType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;integer&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;A list of employees reporting to this employee.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;$ref&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_2&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;contents&quot;: [{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;:[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          { &quot;text&quot;: &quot;Generate an organization chart for a small team.\nThe manager is Alice, who manages Bob and Charlie. Bob manages David.&quot; }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;responseFormat&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;text&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;mimeType&quot;: &quot;application/json&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;schema&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;name&quot;: { &quot;type&quot;: &quot;string&quot; },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;employee_id&quot;: { &quot;type&quot;: &quot;integer&quot; },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;reports&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;description&quot;: &quot;A list of employees reporting to this employee.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;items&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;$ref&quot;: &quot;#&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;required&quot;: [&quot;name&quot;, &quot;employee_id&quot;, &quot;reports&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;示例回答&lt;/strong&gt;：&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JSON&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Alice&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Bob&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;David&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;104&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Charlie&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;employee_id&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;103&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nt&quot;&gt;&quot;reports&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;h2 id=&quot;streaming&quot; tabindex=&quot;-1&quot;&gt;流式&lt;/h2&gt;

&lt;p&gt;您可以流式传输结构化输出，这样一来，您就可以在生成回答的同时开始处理回答，而无需等待整个输出完成。这有助于提升应用的感知性能。&lt;/p&gt;

&lt;p&gt;流式传输的块将是有效的部分 JSON 字符串，可以连接起来形成最终的完整 JSON 对象。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_3&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;typing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Literal&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;Feedback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;sentiment&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Literal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;positive&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;neutral&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;negative&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The new UI is incredibly intuitive and visually appealing. Great job. Add a very long summary to test streaming!&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response_stream&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content_stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response_format&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Feedback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_json_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response_stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_3&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod-to-json-schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The new UI is incredibly intuitive and visually appealing. Great job! Add a very long summary to test streaming!&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;feedbackSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sentiment&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;positive&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;neutral&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;negative&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContentStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;feedbackSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;structured_outputs_with_tools&quot; tabindex=&quot;-1&quot;&gt;使用工具生成结构化输出&lt;/h2&gt;
&lt;aside class=&quot;preview&quot;&gt;&lt;strong&gt;预览版&lt;/strong&gt;：&lt;span&gt; 此功能仅适用于 Gemini 3 系列模型，&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;gemini-3.1-pro-preview&lt;/code&gt; 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;gemini-3.5-flash&lt;/code&gt;。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;Gemini 3 可让您将结构化输出与内置工具相结合，包括&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/google-search?hl=zh-cn&quot;&gt;依托 Google 搜索进行接地&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/url-context?hl=zh-cn&quot;&gt;网址上下文&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/code-execution?hl=zh-cn&quot;&gt;代码执行&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/file-search?hl=zh-cn#structured-output&quot;&gt;文件搜索&lt;/a&gt;和&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn&quot;&gt;函数调用&lt;/a&gt;。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_4&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;typing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;MatchResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;winner&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the winner.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;final_match_score&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The final match score.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;scorers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the scorer.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.1-pro-preview&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Search for all details for the latest Euro.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;tools&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;google_search&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{}},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;url_context&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{}}&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response_format&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;MatchResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_json_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;  
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;MatchResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model_validate_json&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_4&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;zod-to-json-schema&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;matchSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;winner&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the winner.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;final_match_score&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The final score.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;scorers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name of the scorer.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.1-pro-preview&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Search for all details for the latest Euro.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;googleSearch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;urlContext&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;zodToJsonSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;matchSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;matchSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_3&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-pro-preview:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;parts&quot;: [{&quot;text&quot;: &quot;Search for all details for the latest Euro.&quot;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;tools&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&quot;googleSearch&quot;: {}},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&quot;urlContext&quot;: {}}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;responseFormat&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;text&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;mimeType&quot;: &quot;application/json&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;schema&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;winner&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;The name of the winner.&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;final_match_score&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;The final score.&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;scorers&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;items&quot;: {&quot;type&quot;: &quot;string&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;description&quot;: &quot;The name of the scorer.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;required&quot;: [&quot;winner&quot;, &quot;final_match_score&quot;, &quot;scorers&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;json_schema_support&quot; tabindex=&quot;-1&quot;&gt;JSON 架构支持&lt;/h2&gt;

&lt;p&gt;如需生成 JSON 对象，请在生成配置中设置 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;response_format&lt;/code&gt;。该架构必须是描述所需输出格式的有效 &lt;a href=&quot;https://json-schema.org/&quot;&gt;JSON 架构&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;然后，模型会生成一个语法上有效的 JSON 字符串，该字符串与所提供的架构相符。使用结构化输出时，模型将按架构中键的顺序生成输出。&lt;/p&gt;

&lt;p&gt;Gemini 的结构化输出模式支持部分 &lt;a href=&quot;https://json-schema.org&quot;&gt;JSON 架构&lt;/a&gt;规范。&lt;/p&gt;

&lt;p&gt;支持以下 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;type&lt;/code&gt; 值：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;string&lt;/code&gt;&lt;/strong&gt;：对于文本。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;number&lt;/code&gt;&lt;/strong&gt;：适用于浮点数。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;integer&lt;/code&gt;&lt;/strong&gt;：适用于整数。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;boolean&lt;/code&gt;&lt;/strong&gt;：对于 true/false 值。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;object&lt;/code&gt;&lt;/strong&gt;：适用于包含键值对的结构化数据。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;array&lt;/code&gt;&lt;/strong&gt;：适用于商品列表。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;null&lt;/code&gt;&lt;/strong&gt;：如需允许属性为 null，请在类型数组中添加 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;quot;null&amp;quot;&lt;/code&gt;（例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;{&amp;quot;type&amp;quot;: [&amp;quot;string&amp;quot;, &amp;quot;null&amp;quot;]}&lt;/code&gt;）。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;这些描述性属性有助于引导模型：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;title&lt;/code&gt;&lt;/strong&gt;：属性的简短说明。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;description&lt;/code&gt;&lt;/strong&gt;：属性的更长、更详细的说明。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;type-specific_properties&quot; tabindex=&quot;-1&quot;&gt;特定于类型的属性&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;对于 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;object&lt;/code&gt; 值&lt;/strong&gt;：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;properties&lt;/code&gt;&lt;/strong&gt;：一个对象，其中每个键都是属性名称，每个值都是相应属性的架构。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;required&lt;/code&gt;&lt;/strong&gt;：一个字符串数组，列出了哪些属性是必需的。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;additionalProperties&lt;/code&gt;&lt;/strong&gt;：控制是否允许使用未在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;properties&lt;/code&gt; 中列出的属性。可以是布尔值或架构。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;对于 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;string&lt;/code&gt; 值&lt;/strong&gt;：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;&lt;/strong&gt;：列出分类任务的一组特定可能字符串。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;format&lt;/code&gt;&lt;/strong&gt;：指定字符串的语法，例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;date-time&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;date&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;time&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;对于 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;number&lt;/code&gt; 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;integer&lt;/code&gt; 值&lt;/strong&gt;：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;&lt;/strong&gt;：列出了一组特定的可能数值。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;minimum&lt;/code&gt;&lt;/strong&gt;：包含在内的最小值。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;maximum&lt;/code&gt;&lt;/strong&gt;：最大值（含）。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;对于 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;array&lt;/code&gt; 值&lt;/strong&gt;：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;items&lt;/code&gt;&lt;/strong&gt;：定义数组中所有元素的架构。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;prefixItems&lt;/code&gt;&lt;/strong&gt;：为前 N 个项定义架构列表，从而实现类似元组的结构。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;minItems&lt;/code&gt;&lt;/strong&gt;：数组中的最小项数。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;maxItems&lt;/code&gt;&lt;/strong&gt;：数组中的项数上限。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;model_support&quot; tabindex=&quot;-1&quot;&gt;模型支持&lt;/h2&gt;

&lt;p&gt;以下模型支持结构化输出：&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;模型&lt;/th&gt;
&lt;th style=&quot;text-align: center&quot;&gt;结构化输出&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Flash-Lite&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3 Pro 预览版&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.5 Flash&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Flash-Lite 预览版&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Pro&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Flash&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Flash-Lite&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.0 Flash&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️*&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.0 Flash-Lite&lt;/td&gt;
&lt;td style=&quot;text-align: center&quot;&gt;✔️*&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;em&gt;* 请注意，Gemini 2.0 需要在 JSON 输入中明确指定 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;propertyOrdering&lt;/code&gt; 列表，以定义首选结构。您可以在此&lt;a href=&quot;https://github.com/google-gemini/cookbook/blob/main/examples/Pdf_structured_outputs_on_invoices_and_forms.ipynb&quot;&gt;实用指南&lt;/a&gt;中找到相关示例。&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;structured_outputs_vs_function_calling&quot; tabindex=&quot;-1&quot;&gt;结构化输出与函数调用&lt;/h2&gt;

&lt;p&gt;结构化输出和函数调用都使用 JSON 架构，但用途不同：&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align: left&quot;&gt;功能&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;主要使用场景&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;结构化输出&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;设置最终用户响应的格式。&lt;/strong&gt;如果您希望模型的&lt;em&gt;回答&lt;/em&gt;采用特定格式（例如，从文档中提取数据以保存到数据库），请使用此参数。&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;函数调用&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;在对话期间采取行动。&lt;/strong&gt;当模型需要&lt;em&gt;要求您&lt;/em&gt;执行任务（例如“获取当前天气”）才能提供最终答案时，请使用此选项。&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;best_practices&quot; tabindex=&quot;-1&quot;&gt;最佳做法&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;清晰的说明&lt;/strong&gt;：使用架构中的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;description&lt;/code&gt; 字段向模型清晰说明每个属性的含义。这对于引导模型的输出至关重要。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;强类型&lt;/strong&gt;：尽可能使用特定类型（&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;integer&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;string&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;）。如果某个形参的有效值集有限，请使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;提示工程&lt;/strong&gt;：在提示中明确说明您希望模型执行的操作。例如，“从文本中提取以下信息…”或“根据提供的架构对这条反馈进行分类…”。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;验证&lt;/strong&gt;：虽然结构化输出可保证 JSON 在语法上正确，但无法保证值在语义上正确。请务必先验证应用代码中的最终输出，然后再使用。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;错误处理&lt;/strong&gt;：在应用中实现强大的错误处理机制，以便妥善管理模型输出（虽然符合架构，但可能不符合业务逻辑要求）的情况。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;limitations&quot; tabindex=&quot;-1&quot;&gt;限制&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;架构子集&lt;/strong&gt;：不支持 JSON 架构规范的所有功能。模型会忽略不支持的属性。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;架构复杂性&lt;/strong&gt;：该 API 可能会拒绝非常大或嵌套很深的架构。如果您遇到错误，请尝试缩短属性名称、减少嵌套或限制约束数量，以简化架构。&lt;/li&gt;
&lt;/ul&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Google+Symbols:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&quot; rel=&quot;stylesheet&quot; /&gt;
  

  

  
&lt;/div&gt;

  
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
         
       
    
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:21:00 +0800</pubDate></item><item><title>全文转载：Gemini API 长上下文</title><link>https://suwenclub.cn/?id=42</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Gemini API 长上下文&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Google AI for Developers / Google AI for Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/long-context?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://ai.google.dev/gemini-api/docs/long-context?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developers.google.com/site-policies?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 / Apache 2.0 for code samples&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Google AI for Developers 官方中文文档。页面文字为 CC BY 4.0，代码示例为 Apache 2.0。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;
&lt;/p&gt;































&lt;p&gt;许多 Gemini 模型都配备了 100 万个或更多 token 的大型上下文窗口。过去，大语言模型 (LLM) 受到一次可传递给模型的文本（或 token）数量的极大限制。Gemini 的长上下文窗口发掘了许多新的应用场景和开发者模式。&lt;/p&gt;

&lt;p&gt;您已用于&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/text-generation?hl=zh-cn&quot;&gt;文本生成&lt;/a&gt;或&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/vision?hl=zh-cn&quot;&gt;多模态输入&lt;/a&gt;等场景的代码可以直接用于长上下文，无需进行任何更改。&lt;/p&gt;

&lt;p&gt;本文档简要介绍了如何使用上下文窗口包含 100 万个及更多 token 的模型。本页面简要介绍了上下文窗口，并探讨了开发者应如何考虑长上下文、长上下文的各种实际应用场景，以及优化长上下文使用的方法。&lt;/p&gt;

&lt;p&gt;如需了解特定模型的上下文窗口大小，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models?hl=zh-cn&quot;&gt;模型&lt;/a&gt;页面。&lt;/p&gt;

&lt;h2 id=&quot;what-is-context-window&quot; tabindex=&quot;-1&quot;&gt;什么是上下文窗口？&lt;/h2&gt;

&lt;p&gt;使用 Gemini 模型的基本方法是将信息（上下文）传递给模型，模型随后会生成回答。上下文窗口可以比作短期记忆。人们的短期记忆可以存储有限的信息量，生成模型也是如此。&lt;/p&gt;

&lt;p&gt;您可以参阅我们的&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting-strategies?hl=zh-cn#under-the-hood&quot;&gt;生成模型指南&lt;/a&gt;，详细了解模型在后台的工作原理。&lt;/p&gt;

&lt;h2 id=&quot;getting-started-with-long-context&quot; tabindex=&quot;-1&quot;&gt;开始使用长上下文&lt;/h2&gt;

&lt;p&gt;早期的生成模型一次只能处理 8,000 个词元。较新的模型进一步提高了此数字，可接受 32,000 个甚至 128,000 个词元。Gemini 是第一个能够接受 100 万个 token 的模型。&lt;/p&gt;

&lt;p&gt;在实际中，100 万个词元相当于：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;50,000 行代码（标准为每行 80 个字符）&lt;/li&gt;
&lt;li&gt;您在过去 5 年内发送的所有短信&lt;/li&gt;
&lt;li&gt;8 部平均长度的英语小说&lt;/li&gt;
&lt;li&gt;200 多个平均时长播客剧集的转写内容&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;许多其他模型中常见的上下文窗口较为有限，因此通常需要采用一些策略，例如随意舍弃旧消息、总结内容、将 RAG 与向量数据库搭配使用，或过滤提示以节省 token。&lt;/p&gt;

&lt;p&gt;虽然这些技巧在特定场景中仍然很有价值，但 Gemini 庞大的上下文窗口支持更直接的方法：预先提供所有相关信息。由于 Gemini 模型是使用强大的上下文功能专门构建的，因此它们具有强大的上下文学习能力。例如，仅使用上下文中的教学材料（一本 500 页的参考语法书、一本字典和约 400 个平行句子），Gemini &lt;a href=&quot;https://storage.googleapis.com/deepmind-media/gemini/gemini_v1_5_report.pdf&quot;&gt;学会了&lt;/a&gt;将英语翻译成卡拉芒语（一种使用者不到 200 人的巴布亚语言），翻译质量与使用相同材料的人类学习者相当。这说明了 Gemini 的长上下文所带来的范式转变，通过强大的上下文学习能力开辟了新的可能性。&lt;/p&gt;

&lt;h2 id=&quot;long-context-use-cases&quot; tabindex=&quot;-1&quot;&gt;长上下文应用场景&lt;/h2&gt;

&lt;p&gt;虽然大多数生成模型的标准应用场景仍然是文本输入，但 Gemini 模型系列可实现多模态应用场景的新模式。这些模型可采用原生方式理解文本、视频、音频和图片。它们附带&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting_with_media?hl=zh-cn&quot;&gt;可接受多模态文件类型的 Gemini API&lt;/a&gt;，以方便使用。&lt;/p&gt;

&lt;h3 id=&quot;long-form-text&quot; tabindex=&quot;-1&quot;&gt;长文本&lt;/h3&gt;

&lt;p&gt;事实证明，文本是支撑 LLM 大部分发展势头的智能层。如前所述，LLM 的很多实际限制是因为没有足够大的上下文窗口来执行某些任务。这导致了检索增强生成 (RAG) 和其他技术的快速采用，这些技术可为模型动态提供相关的上下文信息。现在，随着上下文窗口越来越大，出现了一些新技术可用于发掘新的应用场景。&lt;/p&gt;

&lt;p&gt;基于文本的长上下文的一些新兴和标准应用场景包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;总结大型文本语料库
&lt;ul&gt;
&lt;li&gt;之前使用较小上下文模型的总结方法需要使用滑动窗口或其他技术，以便在新词元传递给模型时保留之前部分的状态&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;问答
&lt;ul&gt;
&lt;li&gt;过去在上下文数量有限且模型的真实召回率较低的情况下，只有使用 RAG 才能实现这一目的&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;智能体工作流
&lt;ul&gt;
&lt;li&gt;文本是智能体如何保存已完成的操作和需要执行的操作的状态的基础；如果没有关于实际世界和智能体目标的足够信息，会限制智能体的可靠性&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/pdf/2404.11018&quot;&gt;多样本上下文学习&lt;/a&gt;是长上下文模型发掘的最独特功能之一。研究表明，采用常见的“单样本”或“多样本”示例模式，在其中向模型提供一个或几个任务示例，然后扩展到多达数百个、数千个甚至数十万个示例，这可能形成全新的模型功能。事实证明，这种多样本方法的性能与针对特定任务进行了微调的模型类似。对于 Gemini 模型的性能尚不足以满足生产发布的应用场景，您可以尝试多样本方法。正如您稍后将在长上下文优化部分中所了解的那样，上下文缓存使这种高输入词元工作负载类型在经济上更加可行，在某些场景中甚至可降低延迟。&lt;/p&gt;

&lt;h3 id=&quot;long-form-video&quot; tabindex=&quot;-1&quot;&gt;长视频&lt;/h3&gt;

&lt;p&gt;无法访问媒体本身长期以来一直限制着视频内容的实用性。浏览内容并非易事，转写通常无法捕获视频的细微差别，而且大多数工具无法同时处理图片、文本和音频。在 Gemini 中，长上下文文本功能可转换为以持续的性能推理和回答有关多模态输入的问题的能力。&lt;/p&gt;

&lt;p&gt;视频长上下文的一些新兴和标准应用场景包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;视频问答&lt;/li&gt;
&lt;li&gt;视频内存，如 &lt;a href=&quot;https://deepmind.google/technologies/gemini/project-astra/?hl=zh-cn&quot;&gt;Google 的 Project Astra&lt;/a&gt; 所示&lt;/li&gt;
&lt;li&gt;视频字幕&lt;/li&gt;
&lt;li&gt;视频推荐系统，通过新的多模态理解来丰富现有元数据&lt;/li&gt;
&lt;li&gt;视频自定义，可查看数据以及关联视频元数据的语料库，然后移除与观看者无关的视频部分&lt;/li&gt;
&lt;li&gt;视频内容审核&lt;/li&gt;
&lt;li&gt;实时视频处理&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;处理视频时，重要的是考虑如何&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/tokens?hl=zh-cn#media-token&quot;&gt;将视频处理为词元&lt;/a&gt;，这会影响结算和用量限额。如需详细了解如何使用视频文件进行提示，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=python&amp;hl=zh-cn#prompting-with-videos&quot;&gt;提示指南&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;long-form-audio&quot; tabindex=&quot;-1&quot;&gt;长音频&lt;/h3&gt;

&lt;p&gt;Gemini 模型是首批能够理解音频的原生多模态大语言模型。传统上，典型的开发者工作流涉及将多个特定于领域的模型（例如语音转文字模型和文本到文本模型）串联起来，以便处理音频。这会导致执行多次往返请求所需的延迟时间增加并且性能下降，这通常归因于多模型设置的分离架构。&lt;/p&gt;

&lt;p&gt;音频上下文的一些新兴和标准应用场景包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;实时转写和翻译&lt;/li&gt;
&lt;li&gt;播客/视频问答&lt;/li&gt;
&lt;li&gt;会议转写和总结&lt;/li&gt;
&lt;li&gt;语音助理&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如需详细了解如何使用音频文件进行提示，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=python&amp;hl=zh-cn#prompting-with-videos&quot;&gt;提示指南&lt;/a&gt;。&lt;/p&gt;

&lt;h2 id=&quot;long-context-optimizations&quot; tabindex=&quot;-1&quot;&gt;长上下文优化&lt;/h2&gt;

&lt;p&gt;使用长上下文和 Gemini 模型时，主要优化方法是使用&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/caching?hl=zh-cn&quot;&gt;上下文缓存&lt;/a&gt;。除了以前无法在单个请求中处理大量词元之外，另一个主要限制是费用。如果您有一个“与数据聊天”应用，用户在其中上传了 10 个 PDF 文件、一个视频和一些工作文档，那么过去您必须使用更复杂的检索增强生成 (RAG) 工具/框架来处理这些请求，并为移入上下文窗口的词元支付大量费用。现在，您可以缓存用户上传的文件，并按小时为存储这些文件付费。例如，使用 Gemini Flash 时，每个请求的输入 / 输出费用比标准输入 / 输出费用低约 4 倍，因此如果用户与其数据进行足够多的聊天，便可为作为开发者的您节省大量费用。&lt;/p&gt;

&lt;h2 id=&quot;long-context-limitations&quot; tabindex=&quot;-1&quot;&gt;长上下文限制&lt;/h2&gt;

&lt;p&gt;在本指南的各个部分中，我们讨论了 Gemini 模型如何在各种“大海捞针”检索评估中实现高性能。这些测试考虑了最基本的设置，您在其中只需寻找一根“针”。如果您要寻找多根“针”或特定信息，模型执行的准确率会有所不同。性能可能会因上下文而变化很大。考虑这一点很重要，因为在检索到正确信息与费用之间存在固有的权衡。您在单个查询中可获得大约 99% 的准确率，但每次发送该查询时，您都必须支付输入词元费用。因此，要检索 100 条信息，如果您需要 99% 的性能，则可能需要发送 100 个请求。这是一个很好的示例，上下文缓存在其中可显著降低与使用 Gemini 模型关联的费用，同时保持高性能。&lt;/p&gt;

&lt;h2 id=&quot;faqs&quot; tabindex=&quot;-1&quot;&gt;常见问题解答&lt;/h2&gt;

&lt;h3 id=&quot;where_is_the_best_place_to_put_my_query_in_the_context_window&quot; tabindex=&quot;-1&quot;&gt;在上下文窗口中，将查询放在哪个位置效果最好？&lt;/h3&gt;

&lt;p&gt;在大多数情况下，尤其是当总上下文较长时，如果您将查询 / 问题放在提示的末尾（在所有其他上下文之后），模型的效果会更好。&lt;/p&gt;

&lt;h3 id=&quot;do_i_lose_model_performance_when_i_add_more_tokens_to_a_query&quot; tabindex=&quot;-1&quot;&gt;向查询中添加更多令牌后，模型性能会下降吗？&lt;/h3&gt;

&lt;p&gt;一般来说，如果您不需要将令牌传递给模型，最好避免传递令牌。不过，如果您有一大块包含某些信息的 token，并且想就这些信息提问，模型能够非常准确地提取这些信息（在许多情况下，准确率高达 99%）。&lt;/p&gt;

&lt;h3 id=&quot;how_can_i_lower_my_cost_with_long-context_queries&quot; tabindex=&quot;-1&quot;&gt;如何通过长上下文查询降低费用？&lt;/h3&gt;

&lt;p&gt;如果您有一组类似的 token / 上下文想要多次重复使用，&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/caching?hl=zh-cn&quot;&gt;上下文缓存&lt;/a&gt;有助于减少与询问该信息相关联的费用。&lt;/p&gt;

&lt;h3 id=&quot;does_the_context_length_affect_the_model_latency&quot; tabindex=&quot;-1&quot;&gt;上下文长度是否会影响模型延迟时间？&lt;/h3&gt;

&lt;p&gt;无论请求大小如何，任何给定请求都存在一定的固定延迟时间，但一般来说，较长的查询会产生更高的延迟时间（从发出请求到获得第一个令牌的时间）。&lt;/p&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Google+Symbols:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&quot; rel=&quot;stylesheet&quot; /&gt;
  

  

  
&lt;/div&gt;

  
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
         
       
    
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:18:00 +0800</pubDate></item><item><title>全文转载：Gemini API 函数调用</title><link>https://suwenclub.cn/?id=41</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Gemini API 函数调用&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Google AI for Developers / Google AI for Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developers.google.com/site-policies?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 / Apache 2.0 for code samples&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Google AI for Developers 官方中文文档。页面文字为 CC BY 4.0，代码示例为 Apache 2.0。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;
&lt;/p&gt;

&lt;div id=&quot;gemini-api-switcher-trigger&quot; style=&quot;display:none;&quot;&gt;&lt;/div&gt;

&lt;h1 class=&quot;devsite-page-title&quot; id=&quot;function-calling-with-the-gemini-api&quot; tabindex=&quot;-1&quot;&gt;使用 Gemini API 进行函数调用&lt;/h1&gt;

&lt;aside class=&quot;note&quot;&gt;
&lt;b&gt;重要提示&lt;/b&gt;：Gemini 3 模型 API 现在会为每个函数调用生成唯一的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;。如果您是手动构建对话历史记录或使用 REST API，建议您在将已执行函数的结果返回给模型时，在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt; 中传递匹配的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;。如果您使用的是标准 Python 或 Node.js SDK，系统会自动处理此问题。
&lt;/aside&gt;

&lt;p&gt;函数调用功能可让您将模型连接到外部工具和 API。模型不会生成文本回答，而是确定何时调用特定函数，并提供执行实际操作所需的参数。这样一来，模型就可以充当自然语言与实际操作和数据之间的桥梁。函数调用功能有 3 个主要使用情形：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#meeting&quot;&gt;&lt;strong&gt;执行操作&lt;/strong&gt;：&lt;/a&gt;使用 API 与外部系统互动，例如安排预约、创建账单、发送电子邮件或控制智能家居设备。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#weather&quot;&gt;&lt;strong&gt;扩充知识&lt;/strong&gt;：&lt;/a&gt;从数据库、API 和知识库等外部来源获取信息。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#chart&quot;&gt;&lt;strong&gt;扩展功能&lt;/strong&gt;：&lt;/a&gt;使用外部工具执行计算，并扩展模型的功能限制，例如使用计算器或创建图表。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;您可以浏览以下示例，了解这些使用情形：&lt;/p&gt;

&lt;h3 id=&quot;meeting&quot; tabindex=&quot;-1&quot;&gt;安排会议&lt;/h3&gt;

&lt;p&gt;此示例展示了如何定义一个函数，用于在特定时间安排与参会者的会议，从而使模型能够解析用户请求并返回结构化实参，以触发外部系统中的操作。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;schedule_meeting_function&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;schedule_meeting&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Schedules a meeting with specified attendees at a given time and date.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;attendees&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;List of people attending the meeting.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Date of the meeting (e.g., '2024-07-29')&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;time&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Time of the meeting (e.g., '15:00')&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;topic&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The subject or topic of the meeting.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;attendees&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;time&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;topic&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;schedule_meeting_function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Schedule a meeting with Bob and Alice for 03/14/2025 at 10:00 AM about the Q3 planning.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Check for a function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  In a real app, you would call your function here:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  result = schedule_meeting(**function_call.args)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;scheduleMeetingFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'schedule_meeting'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Schedules a meeting with specified attendees at a given time and date.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;attendees&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ARRAY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'List of people attending the meeting.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Date of the meeting (e.g., &quot;2024-07-29&quot;)'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Time of the meeting (e.g., &quot;15:00&quot;)'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;topic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'The subject or topic of the meeting.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'attendees'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'date'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'time'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'topic'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Schedule a meeting with Bob and Alice for 03/27/2025 at 10:00 AM about the Q3 planning.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;scheduleMeetingFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Check for function calls in the response&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Assuming one function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// In a real app, you would call your actual function here:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// const result = await scheduleMeeting(functionCall.args);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Schedule a meeting with Bob and Alice for 03/27/2025 at 10:00 AM about the Q3 planning.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;tools&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;functionDeclarations&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;name&quot;: &quot;schedule_meeting&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;description&quot;: &quot;Schedules a meeting with specified attendees at a given time and date.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;parameters&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;attendees&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;items&quot;: {&quot;type&quot;: &quot;string&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;List of people attending the meeting.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;date&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;Date of the meeting (e.g., '&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;2024&lt;/span&gt;-07-29&lt;span class=&quot;devsite-syntax-s1&quot;&gt;')&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;time&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;Time of the meeting (e.g., '&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;15&lt;/span&gt;:00&lt;span class=&quot;devsite-syntax-s1&quot;&gt;')&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;topic&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;The subject or topic of the meeting.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;required&quot;: [&quot;attendees&quot;, &quot;date&quot;, &quot;time&quot;, &quot;topic&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;weather&quot; tabindex=&quot;-1&quot;&gt;获取天气信息&lt;/h3&gt;

&lt;p&gt;此示例展示了如何定义一个用于检索某个位置的温度数据的函数，从而使模型能够调用外部 API 来回答需要实时信息或外部信息的查询。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_1&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;weather_function&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;get_current_temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Gets the current temperature for a given location.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;location&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The city name, e.g. San Francisco&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;location&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;weather_function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What's the temperature in London?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Check for a function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  In a real app, you would call your function here:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  result = get_current_temperature(**function_call.args)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_1&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;weatherFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'get_current_temperature'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Gets the current temperature for a given location.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'The city name, e.g. San Francisco'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'location'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What's the temperature in London?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;weatherFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Check for function calls in the response&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Assuming one function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// In a real app, you would call your actual function here:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// const result = await getCurrentTemperature(functionCall.args);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_1&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;What'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'s the temperature in London?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;tools&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;functionDeclarations&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;name&quot;: &quot;get_current_temperature&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;description&quot;: &quot;Gets the current temperature for a given location.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;parameters&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;location&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;The city name, e.g. San Francisco&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;required&quot;: [&quot;location&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;chart&quot; tabindex=&quot;-1&quot;&gt;创建图表&lt;/h3&gt;

&lt;p&gt;此示例展示了如何定义一个可根据结构化数据生成条形图的函数，演示了模型如何使用外部工具执行计算或创建视觉资源：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_2&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;create_chart_function&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;create_bar_chart&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Creates a bar chart given a title, labels, and corresponding values.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The title for the chart.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;labels&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;List of labels for the data points (e.g., ['Q1', 'Q2', 'Q3']).&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;values&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;array&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;number&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;List of numerical values corresponding to the labels (e.g., [50000, 75000, 60000]).&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;labels&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;values&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;create_chart_function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Create a bar chart titled 'Quarterly Sales' with data: Q1: 50000, Q2: 75000, Q3: 60000.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Check for a function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  In a real app, you would call your function here using a charting library:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#  result = create_bar_chart(**function_call.args)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_2&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Define the function declaration for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createChartFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'create_bar_chart'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Creates a bar chart given a title, labels, and corresponding values.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'The title for the chart.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ARRAY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'List of labels for the data points (e.g., [&quot;Q1&quot;, &quot;Q2&quot;, &quot;Q3&quot;]).'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ARRAY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NUMBER&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'List of numerical values corresponding to the labels (e.g., [50000, 75000, 60000]).'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'title'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'labels'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'values'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Create a bar chart titled 'Quarterly Sales' with data: Q1: 50000, Q2: 75000, Q3: 60000.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createChartFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Check for function calls in the response&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Assuming one function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Function to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Arguments: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// In a real app, you would call your actual function here:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// const result = await createBarChart(functionCall.args);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;No function call found in the response.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_2&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Create a bar chart titled ''Quarterly Sales'' with data: Q1: 50000, Q2: 75000, Q3: 60000.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;tools&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;functionDeclarations&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;name&quot;: &quot;create_bar_chart&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;description&quot;: &quot;Creates a bar chart given a title, labels, and corresponding values.&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;parameters&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;type&quot;: &quot;object&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;properties&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;title&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;string&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;The title for the chart.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;labels&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;items&quot;: {&quot;type&quot;: &quot;string&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;List of labels for the data points (e.g., [''Q1'', ''Q2'', ''Q3'']).&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;values&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;type&quot;: &quot;array&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;items&quot;: {&quot;type&quot;: &quot;number&quot;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;description&quot;: &quot;List of numerical values corresponding to the labels (e.g., [50000, 75000, 60000]).&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;required&quot;: [&quot;title&quot;, &quot;labels&quot;, &quot;values&quot;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;how-it-works&quot; tabindex=&quot;-1&quot;&gt;函数调用的工作原理&lt;/h2&gt;

&lt;p&gt;&lt;img alt=&quot;函数调用概览&quot; src=&quot;https://ai.google.dev/static/gemini-api/docs/images/function-calling-overview.png?hl=zh-cn&quot; /&gt;&lt;/p&gt;

&lt;p&gt;函数调用涉及应用、模型和外部函数之间的结构化互动。下面详细介绍了这个流程：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;定义函数声明&lt;/strong&gt;：在应用代码中定义函数声明。函数声明向模型描述函数的名称、参数和用途。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;使用函数声明调用 API&lt;/strong&gt;：将用户提示连同函数声明一起发送给模型。模型会分析请求，并确定函数调用是否有帮助。如果有，模型会返回一个结构化 JSON 对象，其中包含函数名称、实参和一个唯一 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;（对于 Gemini 3 模型，API 现在始终会返回此 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;&lt;sup&gt;*&lt;/sup&gt;）。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;执行函数代码（您的责任）&lt;/strong&gt;：模型&lt;em&gt;不会&lt;/em&gt;自行执行函数。您的应用有责任处理响应并检查是否存在函数调用。如果&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;是&lt;/strong&gt;：提取函数的名称、实参和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;，并在应用中执行相应的函数。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;否&lt;/strong&gt;：模型已直接针对提示提供文本回答（此流程在示例中不太突出，但也是一种可能的结果）。&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;创建用户友好的回答&lt;/strong&gt;：如果执行了函数，请捕获结果并将其发送回模型，确保在后续对话轮次中包含匹配的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;。模型将使用该结果生成最终的、用户友好的回答，其中包含函数调用的信息。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;此过程可以重复多次，从而实现复杂的互动和工作流程。该模型还支持在单个轮次中调用多个函数（&lt;a href=&quot;#parallel_function_calling&quot;&gt;并行函数调用&lt;/a&gt;）、按顺序调用多个函数（&lt;a href=&quot;#compositional_function_calling&quot;&gt;组合式函数调用&lt;/a&gt;）以及使用内置 Gemini 工具（&lt;a href=&quot;#native-tools&quot;&gt;多工具使用&lt;/a&gt;）。&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;*&lt;/sup&gt; &lt;strong&gt;始终映射函数 ID&lt;/strong&gt;：Gemini 3 现在始终会为每个 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionCall&lt;/code&gt; 返回唯一的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;。请在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt; 中包含此确切的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;，以便模型能够准确地将结果映射回原始请求。&lt;/p&gt;

&lt;h3 id=&quot;step-1&quot; tabindex=&quot;-1&quot;&gt;第 1 步：定义函数声明&lt;/h3&gt;

&lt;p&gt;在应用代码中定义一个函数及其声明，以便用户设置灯光值并发出 API 请求。此函数可以调用外部服务或 API。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_3&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define a function that the model can call to control smart lights&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;set_light_values_declaration&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;set_light_values&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Sets the brightness and color temperature of a light.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;integer&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Light level from 0 to 100. Zero is off and 100 is full brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;color_temp&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;enum&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;daylight&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;cool&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;warm&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Color temperature of the light fixture, which can be `daylight`, `cool` or `warm`.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;color_temp&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# This is the actual function that would be called based on the model's suggestion&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;set_light_values&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Set the brightness and color temperature of a room light. (mock API).&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Args:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        brightness: Light level from 0 to 100. Zero is off and 100 is full brightness&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        color_temp: Color temperature of the light fixture, which can be `daylight`, `cool` or `warm`.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        A dictionary containing the set brightness and color temperature.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;colorTemperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_3&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Define a function that the model can call to control smart lights&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;setLightValuesFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'set_light_values'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Sets the brightness and color temperature of a light.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NUMBER&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Light level from 0 to 100. Zero is off and 100 is full brightness'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'daylight'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'cool'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'warm'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Color temperature of the light fixture, which can be `daylight`, `cool` or `warm`.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'brightness'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'color_temp'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-cm&quot;&gt;/**&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-cm&quot;&gt;*   Set the brightness and color temperature of a room light. (mock API)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-cm&quot;&gt;*   @param {number} brightness - Light level from 0 to 100. Zero is off and 100 is full brightness&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-cm&quot;&gt;*   @param {string} color_temp - Color temperature of the light fixture, which can be `daylight`, `cool` or `warm`.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-cm&quot;&gt;*   @return {Object} A dictionary containing the set brightness and color temperature.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-cm&quot;&gt;*/&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;setLightValues&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;colorTemperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;color_temp&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;step-2&quot; tabindex=&quot;-1&quot;&gt;第 2 步：使用函数声明调用模型&lt;/h3&gt;

&lt;p&gt;定义函数声明后，您可以提示模型使用这些声明。模型会分析提示和函数声明，并决定是直接回答还是调用函数。如果调用了函数，响应对象将包含函数调用建议。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_4&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;set_light_values_declaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define user prompt&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Turn the lights down to a romantic level&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_4&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Generation config with function declaration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;setLightValuesFunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Define user prompt&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Turn the lights down to a romantic level'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send request with function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;然后，模型会返回一个 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionCall&lt;/code&gt; 对象，该对象采用与 OpenAPI 兼容的架构，用于指定如何调用一个或多个已声明的函数，以便回答用户的问题。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_5&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'8f2b1a3c'&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'color_temp'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'warm'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'brightness'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'set_light_values'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_5&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'8f2b1a3c'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'set_light_values'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'warm'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;step-3&quot; tabindex=&quot;-1&quot;&gt;第 3 步：执行 set_light_values 函数代码&lt;/h3&gt;

&lt;p&gt;从模型的响应中提取函数调用详细信息，解析实参，并执行 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;set_light_values&lt;/code&gt; 函数。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_6&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Extract tool call details, it may not be in the first part.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_call&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;set_light_values&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;set_light_values&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Function execution result: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_6&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Extract tool call details&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'set_light_values'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;setLightValues&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;color_temp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Function execution result: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;step-4&quot; tabindex=&quot;-1&quot;&gt;第 4 步：根据函数结果创建用户友好的回答，然后再次调用模型&lt;/h3&gt;

&lt;p&gt;最后，将函数执行结果发送回模型，以便模型将此信息纳入其对用户的最终回答中。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_7&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Create a function response part&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_part&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;from_function_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;result&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Append function call and result of the function execution to contents&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Append the content from the model's response.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]))&lt;/span&gt; &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Append the function response&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;final_response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;final_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_7&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create a function response part&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;function_response_part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tool_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Append function call and result of the function execution to contents&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;function_response_part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Get the final response from the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;final_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;final_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;这样就完成了函数调用流程。模型成功使用了 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;set_light_values&lt;/code&gt; 函数来执行用户的请求操作。&lt;/p&gt;

&lt;h2 id=&quot;function-declarations&quot; tabindex=&quot;-1&quot;&gt;函数声明&lt;/h2&gt;

&lt;p&gt;在提示中实现函数调用时，您需要创建一个 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;tools&lt;/code&gt; 对象，其中包含一个或多个 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function declarations&lt;/code&gt;。您可以使用 JSON（具体来说是 &lt;a href=&quot;https://spec.openapis.org/oas/v3.0.3#schemaw&quot;&gt;OpenAPI 架构&lt;/a&gt;格式的&lt;a href=&quot;https://ai.google.dev/api/caching?hl=zh-cn#Schema&quot;&gt;选定子集&lt;/a&gt;）来定义函数。单个函数声明可以包含以下参数：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;name&lt;/code&gt;（字符串）：函数的唯一名称（&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_weather_forecast&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;send_email&lt;/code&gt;）。请使用不含空格或特殊字符的描述性名称（使用下划线或驼峰式命名法）。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;description&lt;/code&gt;（字符串）：对函数用途和功能的清晰详细说明。这对于模型了解何时使用该函数至关重要。请尽可能具体，并在有帮助的情况下提供示例（“根据位置信息查找影院，还可以选择查找当前正在影院上映的电影。”）。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;parameters&lt;/code&gt;（对象）：定义函数预期的输入参数。
&lt;ul&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;type&lt;/code&gt;（字符串）：指定总体数据类型，例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;object&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;properties&lt;/code&gt;（对象）：列出各个参数，每个参数都具有以下属性：
&lt;ul&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;type&lt;/code&gt;（字符串）：参数的数据类型，例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;string&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;integer&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;boolean, array&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;description&lt;/code&gt;（字符串）：对参数的用途和格式的说明。提供示例和限制条件（例如“城市和州，例如‘加利福尼亚州旧金山’或邮政编码，例如‘95616’。”）。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;enum&lt;/code&gt;（数组，可选）：如果参数值来自固定集，请使用“枚举”列出允许的值，而不是仅在说明中描述这些值。这有助于提高准确率（“枚举”：[&quot;daylight&quot;, &quot;cool&quot;, &quot;warm&quot;]）。&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;required&lt;/code&gt;（数组）：一个字符串数组，列出了函数运行所必需的参数名称。&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;您还可以使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;types.FunctionDeclaration.from_callable(client=client, callable=your_function)&lt;/code&gt; 直接从 Python 函数构建 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;FunctionDeclarations&lt;/code&gt;。&lt;/p&gt;

&lt;h2 id=&quot;thinking&quot; tabindex=&quot;-1&quot;&gt;使用思考模型进行函数调用&lt;/h2&gt;

&lt;p&gt;Gemini 3 和 2.5 系列模型使用内部&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thinking?hl=zh-cn&quot;&gt;“思考”&lt;/a&gt;过程来推理请求。这可显著提高函数调用性能，使模型能够更好地确定何时调用函数以及使用哪些参数。由于 Gemini API 是无状态的，因此模型会使用&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thought-signatures?hl=zh-cn&quot;&gt;思考特征&lt;/a&gt;在多轮对话中保持上下文。&lt;/p&gt;

&lt;p&gt;本部分介绍了如何对思维签名进行高级管理，仅在您手动构建 API 请求（例如通过 REST）或操纵对话历史记录时才需要阅读。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;如果您使用的是 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/libraries?hl=zh-cn&quot;&gt;Google GenAI SDK&lt;/a&gt;（我们的官方库），则无需管理此流程&lt;/strong&gt;。SDK 会自动处理必要的步骤，如之前的&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn#step-4&quot;&gt;示例&lt;/a&gt;所示。&lt;/p&gt;

&lt;h3 id=&quot;thought-signatures&quot; tabindex=&quot;-1&quot;&gt;手动管理对话记录&lt;/h3&gt;

&lt;p&gt;如果您手动修改对话历史记录，而不是发送&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn#step-4&quot;&gt;完整的上一个回答&lt;/a&gt;，则必须正确处理模型回答中包含的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;thought_signature&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;请遵循以下规则以确保保留模型的上下文：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;始终将 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;thought_signature&lt;/code&gt; 在其原始 &lt;a href=&quot;https://ai.google.dev/api?hl=zh-cn#request-body-structure&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Part&lt;/code&gt;&lt;/a&gt; 内发送回模型。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;请务必在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function_response&lt;/code&gt; 中包含 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function_call&lt;/code&gt; 中的确切 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt;，以便 API 将结果映射到正确的请求。&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;不要将包含签名的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Part&lt;/code&gt; 与不包含签名的部分合并。这会破坏思考的位置上下文。&lt;/li&gt;
&lt;li&gt;不要组合两个都包含签名的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Parts&lt;/code&gt;，因为签名字符串无法合并。&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;gemini_3_thought_signatures&quot; tabindex=&quot;-1&quot;&gt;Gemini 3 思维签名&lt;/h4&gt;

&lt;p&gt;在 Gemini 3 中，模型回答的任何 &lt;a href=&quot;https://ai.google.dev/api?hl=zh-cn#request-body-structure&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Part&lt;/code&gt;&lt;/a&gt; 都可能包含思考签名。虽然我们通常建议从所有 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Part&lt;/code&gt; 类型返回签名，但对于函数调用，必须传递思考签名。除非您手动操纵对话历史记录，否则 Google GenAI SDK 会自动处理思考签名。&lt;/p&gt;

&lt;p&gt;如果您要手动处理对话记录，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thought-signatures?hl=zh-cn&quot;&gt;思考签名&lt;/a&gt;页面，获取有关处理 Gemini 3 思考签名的完整指南和详细信息。&lt;/p&gt;

&lt;h5 id=&quot;inspecting-thought-signatures&quot; tabindex=&quot;-1&quot;&gt;检查思考签名&lt;/h5&gt;

&lt;p&gt;虽然不是必需的，但您可以检查响应，以查看 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;thought_signature&lt;/code&gt;，用于调试或学习。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_8&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;base64&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# After receiving a response from a model with thinking enabled&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# response = client.models.generate_content(...)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# The signature is attached to the response part containing the function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;part&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;thought_signature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;base64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;b64encode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;thought_signature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_8&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// After receiving a response from a model with thinking enabled&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// const response = await ai.models.generateContent(...)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// The signature is attached to the response part containing the function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thoughtSignature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thoughtSignature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;如需详细了解思路签名的限制和使用情况，以及一般的思考模型，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thinking?hl=zh-cn#signatures&quot;&gt;思考&lt;/a&gt;页面。&lt;/p&gt;

&lt;h2 id=&quot;parallel_function_calling&quot; tabindex=&quot;-1&quot;&gt;并行函数调用&lt;/h2&gt;

&lt;p&gt;除了单轮函数调用之外，您还可以一次调用多个函数。并行函数调用可让您同时执行多个函数，适用于函数之间没有依赖关系的情况。这在以下场景中非常有用：从多个独立来源收集数据，例如从不同数据库检索客户详细信息、检查各个仓库的库存水平，或执行多项操作，例如将公寓改造成迪斯科舞厅。&lt;/p&gt;

&lt;p&gt;当模型在单个对话轮次中发起多次函数调用时，您无需按接收 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function_call&lt;/code&gt; 对象的顺序返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function_result&lt;/code&gt; 对象。Gemini API 会使用模型输出中的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;id&lt;/code&gt; 将每个结果映射回其对应的调用。这样，您就可以异步执行函数，并在函数完成时将结果附加到列表中。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_9&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;power_disco_ball&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;power_disco_ball&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Powers the spinning disco ball.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;power&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;boolean&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Whether to turn the disco ball on or off.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;power&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;start_music&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;start_music&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Play some music matching the specified parameters.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;energetic&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;boolean&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Whether the music is energetic or not.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;loud&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;boolean&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Whether the music is loud or not.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;energetic&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;loud&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;dim_lights&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;dim_lights&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Dim the lights.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;number&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The brightness of the lights, 0.0 is off, 1.0 is full.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_9&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;powerDiscoBall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'power_disco_ball'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Powers the spinning disco ball.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;power&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;BOOLEAN&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Whether to turn the disco ball on or off.'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'power'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;startMusic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'start_music'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Play some music matching the specified parameters.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;energetic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;BOOLEAN&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Whether the music is energetic or not.'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;loud&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;BOOLEAN&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Whether the music is loud or not.'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'energetic'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'loud'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;dimLights&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'dim_lights'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Dim the lights.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NUMBER&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'The brightness of the lights, 0.0 is off, 1.0 is full.'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'brightness'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;配置函数调用模式，以允许使用所有指定的工具。如需了解详情，您可以阅读有关&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn#function_calling_modes&quot;&gt;配置函数调用&lt;/a&gt;的文章。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_10&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;house_tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;power_disco_ball&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;start_music&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;dim_lights&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;house_tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;automatic_function_calling&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;AutomaticFunctionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;disable&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Force the model to call 'any' function, instead of chatting.&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ToolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_calling_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'ANY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;send_message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Turn this place into a party!&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Print out each of the function calls requested from this single call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Example 1: Forced function calling&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_calls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;) - ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_10&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Set up function declarations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;houseFns&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;powerDiscoBall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;startMusic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;dimLights&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;houseFns&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Force the model to call 'any' function, instead of chatting.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'any'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create a chat session&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Turn this place into a party!'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Print out each of the function calls requested from this single call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Example 1: Forced function calling&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;entries&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(([&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&amp;gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;', '&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;) - ID: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;每个打印结果都反映了模型请求的单个函数调用。如需返回结果，请按请求顺序包含响应。&lt;/p&gt;

&lt;p&gt;Python SDK 支持&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn#automatic_function_calling_python_only&quot;&gt;自动函数调用&lt;/a&gt;，可自动将 Python 函数转换为声明，并为您处理函数调用执行和响应周期。以下是迪斯科用例的示例。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 自动函数调用目前仅为 Python SDK 功能。&lt;/span&gt;&lt;/aside&gt;&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_11&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Actual function implementations&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;power_disco_ball_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;power&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Powers the spinning disco ball.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Args:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        power: Whether to turn the disco ball on or off.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        A status dictionary indicating the current state.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Disco ball powered &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'on'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;power&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'off'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;start_music_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;energetic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;loud&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Play some music matching the specified parameters.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Args:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        energetic: Whether the music is energetic or not.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        loud: Whether the music is loud or not.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        A dictionary containing the music settings.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;music_type&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;energetic&quot;&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;energetic&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;chill&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;volume&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;loud&quot;&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;loud&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;quiet&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;music_type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;music_type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;volume&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;volume&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;dim_lights_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Dim the lights.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Args:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        brightness: The brightness of the lights, 0.0 is off, 1.0 is full.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        A dictionary containing the new brightness setting.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;brightness&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;brightness&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;power_disco_ball_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;start_music_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;dim_lights_impl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Make the request&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Do everything you need to this place into party!&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Example 2: Automatic function calling&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# I've turned on the disco ball, started playing loud and energetic music, and dimmed the lights to 50% brightness. Let's get this party started!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;compositional_function_calling&quot; tabindex=&quot;-1&quot;&gt;组合式函数调用&lt;/h2&gt;

&lt;p&gt;组合式或顺序式函数调用可让 Gemini 将多个函数调用链接在一起，以满足复杂的请求。例如，为了回答“获取我当前位置的温度”，Gemini API 可能会先调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_current_location()&lt;/code&gt; 函数，然后再调用以位置为参数的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_weather()&lt;/code&gt; 函数。&lt;/p&gt;

&lt;p&gt;以下示例演示了如何使用 Python SDK 和自动函数调用来实现组合式函数调用。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_12&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;p&gt;此示例使用了 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;google-genai&lt;/code&gt; Python SDK 的自动函数调用功能。该 SDK 会自动将 Python 函数转换为所需的架构，在模型请求时执行函数调用，并将结果发送回模型以完成任务。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Example Functions&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Gets the current weather temperature for a given location.&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Call: get_weather_forecast(location=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;)&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# TODO: Make API call&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Response: {'temperature': 25, 'unit': 'celsius'}&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;unit&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;celsius&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Dummy response&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Sets the thermostat to a desired temperature.&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Call: set_thermostat_temperature(temperature=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;)&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# TODO: Interact with a thermostat API&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Response: {'status': 'success'}&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;success&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client and model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Make the request&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;If it's warmer than 20°C in London, set the thermostat to 20°C, otherwise set it to 18°C.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Print the final, user-facing response&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;p&gt;&lt;strong&gt;预期输出&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;运行代码时，您会看到 SDK 编排函数调用。模型首先调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_weather_forecast&lt;/code&gt;，接收温度，然后根据提示中的逻辑调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;set_thermostat_temperature&lt;/code&gt; 并传入正确的值。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;London&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'temperature'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'unit'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'celsius'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'status'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'success'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;OK&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'ve set the thermostat to 20°C.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_11&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;p&gt;此示例展示了如何使用 JavaScript/TypeScript SDK 通过手动执行循环进行组合式函数调用。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Example Functions&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Tool Call: get_weather_forecast(location=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;)`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// TODO: Make API call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Response: {'temperature': 25, 'unit': 'celsius'}&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;unit&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;celsius&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Tool Call: set_thermostat_temperature(temperature=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;)`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// TODO: Make API call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tool Response: {'status': 'success'}&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;success&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolFunctions&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;get_weather_forecast&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Gets the current weather temperature for a given location.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;location&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;set_thermostat_temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Sets the thermostat to a desired temperature.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NUMBER&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Prompt for the model&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;If it's warmer than 20°C in London, set the thermostat to 20°C, otherwise set it to 18°C.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Loop until the model has no more function calls to make&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolFunctions&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;throw&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ne&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Unknown function call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Call the function and get the response.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolFunctions&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponsePart&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send the function response back to the model.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;model&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponsePart&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// No more function calls, break the loop.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;p&gt;&lt;strong&gt;预期输出&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;运行代码时，您会看到 SDK 编排函数调用。模型首先调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_weather_forecast&lt;/code&gt;，接收温度，然后根据提示中的逻辑调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;set_thermostat_temperature&lt;/code&gt; 并传入正确的值。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;get_weather_forecast&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;London&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'temperature'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'unit'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'celsius'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;set_thermostat_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'status'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'success'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OK&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;It&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'s 25°C in London, so I'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ve&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;the&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thermostat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-err&quot;&gt;°&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;组合式函数调用是一项原生 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/live?hl=zh-cn&quot;&gt;Live API&lt;/a&gt; 功能。这意味着 Live API 可以像 Python SDK 一样处理函数调用。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_13&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Light control schemas&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;turn_on_the_lights_schema&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'turn_on_the_lights'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;turn_off_the_lights_schema&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s1&quot;&gt;'turn_off_the_lights'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;  Hey, can you write run some python code to turn on the lights, wait 10s and then turn off the lights?&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s2&quot;&gt;  &quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'code_execution'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{}},&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'function_declarations'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;turn_on_the_lights_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;turn_off_the_lights_schema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;modality&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;AUDIO&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_12&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Light control schemas&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;turnOnTheLightsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'turn_on_the_lights'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;turnOffTheLightsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'turn_off_the_lights'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;  Hey, can you write run some python code to turn on the lights, wait 10s and then turn off the lights?&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;codeExecution&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;turnOnTheLightsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;turnOffTheLightsSchema&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;modality&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;AUDIO&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;function_calling_modes&quot; tabindex=&quot;-1&quot;&gt;函数调用模式&lt;/h2&gt;

&lt;p&gt;通过 Gemini API，您可以控制模型使用所提供工具（函数声明）的方式。具体来说，您可以在 .&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;function_calling_config&lt;/code&gt; 中设置模式。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;VALIDATED&lt;/code&gt;：工具组合的默认模式（当内置工具或结构化输出也处于启用状态时）。模型会受限于预测函数调用或自然语言，并确保遵循函数架构。如果未提供 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;allowed_function_names&lt;/code&gt;，模型会从所有可用的函数声明中进行选择。如果提供了 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;allowed_function_names&lt;/code&gt;，模型会从一组允许的函数中进行选择。与 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AUTO&lt;/code&gt; 模式相比，此模式可减少格式错误的函数调用。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AUTO&lt;/code&gt;：仅启用 function_declarations 工具时的默认模式。模型会根据提示和上下文决定是生成自然语言回答还是建议进行函数调用。&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ANY&lt;/code&gt;：模型会受到限制，始终预测函数调用，并确保符合函数架构。如果未指定 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;allowed_function_names&lt;/code&gt;，模型可以从提供的任何函数声明中进行选择。如果 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;allowed_function_names&lt;/code&gt; 以列表形式提供，模型只能从该列表中的函数中进行选择。如果您需要针对每个提示（如果适用）获得函数调用响应，请使用此模式。&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;NONE&lt;/code&gt;：模型&lt;em&gt;禁止&lt;/em&gt;进行函数调用。这相当于发送不含任何函数声明的请求。使用此参数可暂时停用函数调用，而无需移除工具定义。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_14&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure function calling mode&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ToolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_calling_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;ANY&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;allowed_function_names&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;get_current_temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Create the generation config&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# not defined here.&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_13&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;FunctionCallingConfigMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure function calling mode&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;FunctionCallingConfigMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ANY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;allowedFunctionNames&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'get_current_temperature'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create the generation config&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// not defined here.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;automatic_function_calling_python_only&quot; tabindex=&quot;-1&quot;&gt;自动函数调用（仅限 Python）&lt;/h2&gt;

&lt;p&gt;使用 Python SDK 时，您可以直接将 Python 函数作为工具提供。SDK 会将这些函数转换为声明，管理函数调用执行，并为您处理响应周期。使用类型提示和文档字符串定义函数。为获得最佳效果，建议使用 &lt;a href=&quot;https://google.github.io/styleguide/pyguide.html#383-functions-and-methods&quot;&gt;Google 风格的文档字符串&lt;/a&gt;。然后，SDK 会自动执行以下操作：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;检测模型返回的函数调用响应。&lt;/li&gt;
&lt;li&gt;在代码中调用相应的 Python 函数。&lt;/li&gt;
&lt;li&gt;将函数的响应发送回模型。&lt;/li&gt;
&lt;li&gt;返回模型的最终文本回答。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SDK 目前不会将实参说明解析为生成的函数声明的属性说明槽。而是将整个文档字符串作为顶级函数说明发送。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_15&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Define the function with type hints and docstring&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;get_current_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Gets the current temperature for a given location.&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Args:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        location: The city and state, e.g. San Francisco, CA&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;        A dictionary containing the temperature and unit.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# ... (implementation) ...&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;temperature&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;unit&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Celsius&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_current_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Pass the function itself&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Make the request&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What's the temperature in Boston?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# The SDK handles the function call and returns the final text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;您可以使用以下方法停用自动函数调用：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_16&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_current_temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;automatic_function_calling&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;AutomaticFunctionCallingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;disable&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;schema&quot; tabindex=&quot;-1&quot;&gt;自动函数架构声明&lt;/h3&gt;

&lt;p&gt;该 API 能够描述以下任何类型。允许使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Pydantic&lt;/code&gt; 类型，前提是这些类型上定义的字段也由允许的类型组成。此处不太支持字典类型（例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;dict[str: int]&lt;/code&gt;），请勿使用。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_17&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;AllowedType&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-nb&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'AllowedType'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;pydantic&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;BaseModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;如需查看推断架构的实际效果，您可以使用 &lt;a href=&quot;https://googleapis.github.io/python-genai/genai.html#genai.types.FunctionDeclaration.from_callable&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;from_callable&lt;/code&gt;&lt;/a&gt; 对其进行转换：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_18&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sd&quot;&gt;&quot;&quot;&quot;Returns a * b.&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;b&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;fn_decl&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;from_callable&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;callable&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# to_json_dict() provides a clean JSON representation.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;fn_decl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;to_json_dict&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;native-tools&quot; tabindex=&quot;-1&quot;&gt;多工具使用：将内置工具与函数调用相结合&lt;/h2&gt;

&lt;p&gt;您可以启用多个工具，在同一请求中将内置工具与函数调用相结合。&lt;/p&gt;

&lt;p&gt;借助工具上下文循环功能，Gemini 3 模型可以开箱即用地将内置工具与函数调用相结合。如需了解详情，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/tool-combination?hl=zh-cn&quot;&gt;结合使用内置工具和函数调用&lt;/a&gt;页面。&lt;/p&gt;
&lt;aside class=&quot;preview&quot;&gt;&lt;strong&gt;预览版&lt;/strong&gt;：&lt;span&gt; 在 Gemini 3 模型中，将内置工具与函数调用和工具上下文循环功能相结合的功能处于预览版阶段。&lt;/span&gt;&lt;/aside&gt;&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_19&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;getWeather&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;getWeather&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Gets the weather for a requested city.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;city&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The city and state, e.g. Utqiaġvik, Alaska&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;city&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What is the northernmost city in the United States? What's the weather like there today?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;google_search&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ToolGoogleSearch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Built-in tool&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;getWeather&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;       &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Custom tool&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;include_server_side_tool_invocations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What is the northernmost city in the United States? What's the weather like there today?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;getWeather&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;response&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Very cold. 22 degrees Fahrenheit.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response_2&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;google_search&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ToolGoogleSearch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;getWeather&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;include_server_side_tool_invocations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_14&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getWeather&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;getWeather&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Get the weather in a given location&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;OBJECT&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;STRING&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The city and state, e.g. San Francisco, CA&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;location&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;googleSearch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getWeather&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;includeServerSideToolInvocations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What is the northernmost city in the United States? What's the weather like there today?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCallId&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&amp;gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What is the northernmost city in the United States? What's the weather like there today?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;getWeather&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Very cold. 22 degrees Fahrenheit.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCallId&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;对于 Gemini 3 系列之前的型号，请使用 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/live-api/tools?hl=zh-cn&quot;&gt;Live API&lt;/a&gt;。&lt;/p&gt;

&lt;h2 id=&quot;multimodal&quot; tabindex=&quot;-1&quot;&gt;多模态函数响应&lt;/h2&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 此功能适用于 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/gemini-3?hl=zh-cn&quot;&gt;Gemini 3&lt;/a&gt; 系列型号。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;对于 Gemini 3 系列模型，您可以在发送给模型的函数响应部分中添加多模态内容。模型可以在下一轮对话中处理此多模态内容，从而生成更明智的回答。
函数响应中的多模态内容支持以下 MIME 类型：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;图片&lt;/strong&gt;：&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;image/png&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;image/jpeg&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;image/webp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;文档&lt;/strong&gt;：&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;application/pdf&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;text/plain&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如需在函数响应中包含多模态数据，请将其作为嵌套在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt; 部分内的一个或多个部分。每个多模态部分都必须包含 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;inlineData&lt;/code&gt;。如果您在结构化 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;response&lt;/code&gt; 字段中引用了多模态部分，则该字段必须包含唯一的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;displayName&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;您还可以使用 JSON 引用格式 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;{&amp;quot;$ref&amp;quot;: &amp;quot;&amp;lt;displayName&amp;gt;&amp;quot;}&lt;/code&gt; 从 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt; 部分的结构化 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;response&lt;/code&gt; 字段中引用多模态部分。模型在处理响应时，会将引用替换为多模态内容。每个 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;displayName&lt;/code&gt; 只能在结构化 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;response&lt;/code&gt; 字段中引用一次。&lt;/p&gt;

&lt;p&gt;以下示例展示了一条消息，其中包含名为 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;get_image&lt;/code&gt; 的函数的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt;，以及一个包含图片数据（带有 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;displayName: &amp;quot;instrument.jpg&amp;quot;&lt;/code&gt;）的嵌套部分。&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionResponse&lt;/code&gt; 的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;response&lt;/code&gt; 字段引用了此图片部分：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_20&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;requests&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# This is a manual, two turn multimodal function calling workflow:&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# 1. Define the function tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_image_declaration&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;get_image&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Retrieves the image file reference for a specific order item.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;object&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;properties&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;item_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
              &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name or description of the item ordered (e.g., 'instrument').&quot;&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;required&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;item_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Tool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_declarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_image_declaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# 2. Send a message that triggers the tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Show me the instrument I ordered last month.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response_1&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# 3. Handle the function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response_1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_calls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;requested_item&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;item_name&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Model wants to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Execute your tool (e.g., call an API)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# (This is a mock response for the example)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Calling external tool for: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;requested_item&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_data&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;image_ref&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;$ref&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;instrument.jpg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;image_path&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://goo.gle/instrument-img&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;image_bytes&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;image_path&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_multimodal_data&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionResponsePart&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;inline_data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;FunctionResponseBlob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;mime_type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;image/jpeg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;display_name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;instrument.jpg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;image_bytes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# 4. Send the tool's result back&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Append this turn's messages to history for a final response.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)]),&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;response_1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;from_function_response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_call&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;function_response_multimodal_data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response_2&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;tool_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
      &lt;span class=&quot;devsite-syntax-n&quot;&gt;thinking_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;include_thoughts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;Final model response: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response_2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_15&quot; tabindex=&quot;-1&quot;&gt;JavaScript &lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// This is a manual, two turn multimodal function calling workflow:&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// 1. Define the function tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getImageDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'get_image'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Retrieves the image file reference for a specific order item.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;item_name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;STRING&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;The name or description of the item ordered (e.g., 'instrument').&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'item_name'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionDeclarations&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getImageDeclaration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// 2. Send a message that triggers the tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Show me the instrument I ordered last month.'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// 3. Handle the function call&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCalls&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;requestedItem&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;item_name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Model wants to call: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Execute your tool (e.g., call an API)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// (This is a mock response for the example)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`Calling external tool for: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;requestedItem&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponseData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image_ref&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;$ref&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'instrument.jpg'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageUrl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://goo.gle/instrument-img&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageUrl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageArrayBuffer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;arrayBuffer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;base64ImageData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Buffer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageArrayBuffer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'base64'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponseMultimodalData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;inlineData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'image/jpeg'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;displayName&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'instrument.jpg'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;base64ImageData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// 4. Send the tool's result back&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Append this turn's messages to history for a final response.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionCall&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponseData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;functionResponseMultimodalData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'gemini-3.5-flash'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toolConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;includeThoughts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`\nFinal model response: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_3&quot; tabindex=&quot;-1&quot;&gt; REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;IMG_URL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://goo.gle/instrument-img&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nv&quot;&gt;MIME_TYPE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-sIL&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMG_URL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;grep&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-i&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'^content-type:'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;awk&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-F&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;': '&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{print $2}'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;sed&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'s/\r$//'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;head&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-n&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-z&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$MIME_TYPE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;||&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;!&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$MIME_TYPE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;image/*&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;then&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;MIME_TYPE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;image/jpeg&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;fi&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Check for macOS&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;uname&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Darwin&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;then&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;IMAGE_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-sL&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMG_URL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;base64&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-b&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;elif&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;base64&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;--version&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;2&amp;gt;&amp;amp;1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;*&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;FreeBSD&quot;&lt;/span&gt;*&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;then&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;IMAGE_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-sL&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMG_URL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;base64&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;IMAGE_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-sL&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMG_URL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;base64&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;-w0&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;fi&lt;/span&gt;

curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      ...,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;functionResponse&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;name&quot;: &quot;get_image&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;id&quot;: &quot;UNIQUE_CALL_ID_HERE&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;response&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                &quot;image_ref&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;$ref&quot;: &quot;instrument.jpg&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  &quot;inlineData&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;displayName&quot;: &quot;instrument.jpg&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;mimeType&quot;:&quot;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$MIME_TYPE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                    &quot;data&quot;: &quot;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMAGE_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                  }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;                }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;              ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;structured-output&quot; tabindex=&quot;-1&quot;&gt;使用结构化输出进行函数调用&lt;/h2&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 此功能适用于 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/gemini-3?hl=zh-cn&quot;&gt;Gemini 3&lt;/a&gt; 系列型号。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;对于 Gemini 3 系列模型，您可以将函数调用与&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn&quot;&gt;结构化输出&lt;/a&gt;搭配使用。这样，模型就可以预测符合特定架构的函数调用或输出。因此，当模型不生成函数调用时，您会收到格式一致的回答。&lt;/p&gt;

&lt;h2 id=&quot;mcp&quot; tabindex=&quot;-1&quot;&gt;Model Context Protocol (MCP)&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://modelcontextprotocol.io/introduction&quot;&gt;Model Context Protocol (MCP)&lt;/a&gt; 是一种开放标准，用于将 AI 应用与外部工具和数据连接起来。MCP 为模型提供了一种通用协议，用于访问上下文，例如函数（工具）、数据源（资源）或预定义的提示。&lt;/p&gt;

&lt;p&gt;Gemini SDK 内置了对 MCP 的支持，可减少样板代码，并为 MCP 工具提供&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn#automatic_function_calling_python_only&quot;&gt;自动工具调用&lt;/a&gt;。当模型生成 MCP 工具调用时，Python 和 JavaScript 客户端 SDK 可以自动执行 MCP 工具，并在后续请求中将响应发送回模型，从而继续此循环，直到模型不再进行工具调用。&lt;/p&gt;

&lt;p&gt;在此处，您可以找到一个示例，了解如何将本地 MCP 服务器与 Gemini 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;mcp&lt;/code&gt; SDK 搭配使用。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_21&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;p&gt;确保在所选平台上安装了最新版本的 &lt;a href=&quot;https://modelcontextprotocol.io/introduction&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;mcp&lt;/code&gt; SDK&lt;/a&gt;。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;pip&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;mcp
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; Python 支持通过将 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ClientSession&lt;/code&gt; 传递到 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;tools&lt;/code&gt; 参数中来实现自动调用工具。如果您想停用此功能，可以提供已停用的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;True&lt;/code&gt; 的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;automatic_function_calling&lt;/code&gt;。&lt;/span&gt;&lt;/aside&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;asyncio&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;datetime&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;mcp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;ClientSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;StdioServerParameters&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;mcp.client.stdio&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;stdio_client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Create server parameters for stdio connection&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;server_params&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;StdioServerParameters&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;npx&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Executable&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;-y&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@philschmid/weather-mcp&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# MCP Server&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Optional environment variables&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;stdio_client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;server_params&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;ClientSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Prompt to get the weather for the current day in London.&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;What is the weather in London in &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'%Y-%m-&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;?&quot;&lt;/span&gt;

            &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Initialize the connection between client and server&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

            &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Send request to the model with MCP function declarations&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;aio&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;  &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# uses the session, will automatically call the tool&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Uncomment if you **don't** want the SDK to automatically call the tool&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# automatic_function_calling=genai.types.AutomaticFunctionCallingConfig(&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;#     disable=True&lt;/span&gt;
                    &lt;span class=&quot;devsite-syntax-c1&quot;&gt;# ),&lt;/span&gt;
                &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Start the asyncio event loop and run the main function&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;asyncio&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_16&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;p&gt;确保您选择的平台上安装了最新版本的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;mcp&lt;/code&gt; SDK。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;npm&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;@modelcontextprotocol/sdk
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; JavaScript 通过将 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;client&lt;/code&gt; 封装在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;mcpToTool&lt;/code&gt; 中来支持自动工具调用。如果您想停用它，可以提供已停用的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;true&lt;/code&gt; 的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;automaticFunctionCalling&lt;/code&gt;。&lt;/span&gt;&lt;/aside&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;FunctionCallingConfigMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mcpToTool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'@google/genai'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@modelcontextprotocol/sdk/client/index.js&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;StdioClientTransport&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@modelcontextprotocol/sdk/client/stdio.js&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create server parameters for stdio connection&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;serverParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;StdioClientTransport&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;npx&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Executable&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;-y&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@philschmid/weather-mcp&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// MCP Server&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;example-client&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;1.0.0&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Configure the client&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Initialize the connection between client and server&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;serverParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Send request to the model with MCP tools&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;`What is the weather in London in &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;toLocaleDateString&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sb&quot;&gt;?`&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mcpToTool&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)],&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// uses the session, will automatically call the tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Uncomment if you **don't** want the sdk to automatically call the tool&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// automaticFunctionCalling: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;//   disable: true,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Close the connection&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;mcp-limitations&quot; tabindex=&quot;-1&quot;&gt;内置 MCP 支持的限制&lt;/h3&gt;

&lt;p&gt;内置 MCP 支持是我们 SDK 中的一项&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models?hl=zh-cn#preview&quot;&gt;实验性&lt;/a&gt;功能，具有以下限制：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;仅支持工具，不支持资源和提示&lt;/li&gt;
&lt;li&gt;适用于 Python 和 JavaScript/TypeScript SDK。&lt;/li&gt;
&lt;li&gt;未来版本可能会出现重大变更。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如果这些限制影响了您构建的内容，您可以随时选择手动集成 MCP 服务器。&lt;/p&gt;

&lt;h2 id=&quot;supported-models&quot; tabindex=&quot;-1&quot;&gt;支持的模型&lt;/h2&gt;

&lt;p&gt;本部分列出了模型及其函数调用功能。不包括实验性模型。您可以在&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models?hl=zh-cn&quot;&gt;模型概览&lt;/a&gt;页面上找到全面的功能概览。&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align: left&quot;&gt;模型&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;函数调用&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;并行函数调用&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;组合式函数调用&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-3.1-pro-preview?hl=zh-cn&quot;&gt;Gemini 3.1 Pro 预览版&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-3.1-flash-lite?hl=zh-cn&quot;&gt;Gemini 3.1 Flash-Lite&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-3.5-flash?hl=zh-cn&quot;&gt;Gemini 3.5 Flash&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-2.5-pro?hl=zh-cn&quot;&gt;Gemini 2.5 Pro&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-2.5-flash?hl=zh-cn&quot;&gt;Gemini 2.5 Flash&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-2.5-flash-lite?hl=zh-cn&quot;&gt;Gemini 2.5 Flash-Lite&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;✔️&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;best-practices&quot; tabindex=&quot;-1&quot;&gt;最佳做法&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;函数和参数说明&lt;/strong&gt;：说明应非常清晰且具体。模型会根据这些信息选择正确的函数并提供适当的实参。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;命名&lt;/strong&gt;：使用描述性函数名称（不含空格、英文句点或英文短划线）。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;强类型&lt;/strong&gt;：为参数使用特定类型（整数、字符串、枚举），以减少错误。如果某个形参的有效值集有限，请使用枚举。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;工具选择&lt;/strong&gt;：虽然模型可以使用任意数量的工具，但提供的工具过多可能会增加选择错误或次优工具的风险。为获得最佳结果，请尽量仅提供与上下文或任务相关的工具，最好将有效工具集保持在 10-20 个以内。如果您有大量工具，请考虑根据对话上下文动态选择工具。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;提示工程&lt;/strong&gt;：
&lt;ul&gt;
&lt;li&gt;提供背景信息：告知模型其角色（例如，“你是一位乐于助人的天气助理。”）。&lt;/li&gt;
&lt;li&gt;提供指令：指定如何以及何时使用函数（例如，“不要猜测日期；始终使用未来日期进行预测。”）。&lt;/li&gt;
&lt;li&gt;鼓励澄清：指示模型在需要时提出澄清性问题。&lt;/li&gt;
&lt;li&gt;如需了解有关设计这些提示的更多策略，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting-strategies?hl=zh-cn#agentic-workflows&quot;&gt;智能体工作流&lt;/a&gt;。以下是经过测试的&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/prompting-strategies?hl=zh-cn#agentic-si-template&quot;&gt;系统指令&lt;/a&gt;示例。&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;温度&lt;/strong&gt;：使用较低的温度（例如 0）可获得更具确定性和可靠性的函数调用。&lt;/p&gt;

&lt;aside class=&quot;note&quot;&gt;
`temperature`、`top_p` 和 `top_k` 参数控制着模型生成回答的方式。虽然您可以修改这些参数，但我们强烈建议您将 Gemini 3.x 模型的这些参数保留为默认值。更改这些参数（例如将温度设置为低于 1.0）可能会导致意外行为（例如循环或性能下降），尤其是在复杂的数学或推理任务中。
&lt;/aside&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;验证&lt;/strong&gt;：如果函数调用会产生重大后果（例如下单），请在执行之前先向用户验证该调用。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;检查完成原因&lt;/strong&gt;：始终检查模型回答中的 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#FinishReason&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;finishReason&lt;/code&gt;&lt;/a&gt;，以处理模型未能生成有效函数调用的情况。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;错误处理&lt;/strong&gt;：在函数中实现稳健的错误处理机制，以妥善处理意外输入或 API 故障。返回信息丰富的错误消息，供模型用来生成对用户的实用回答。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;安全性&lt;/strong&gt;：调用外部 API 时，请注意安全性。使用适当的身份验证和授权机制。避免在函数调用中公开敏感数据。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;令牌限制&lt;/strong&gt;：函数说明和参数会计入输入令牌限制。如果您遇到 token 限制，请考虑限制函数数量或说明长度，将复杂的任务分解为更小、更集中的函数集。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;混合使用 Bash 和自定义工具&lt;/strong&gt; 对于混合使用 Bash 和自定义工具的开发者，Gemini 3.1 Pro 预览版提供了一个单独的端点，可通过 API 调用 &lt;a href=&quot;https://ai.google.dev/gemini-api/docs/models/gemini-3.1-pro-preview?hl=zh-cn#gemini-31-pro-preview-customtools&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;gemini-3.1-pro-preview-customtools&lt;/code&gt;&lt;/a&gt; 来使用。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;limitations&quot; tabindex=&quot;-1&quot;&gt;注释和限制&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;函数调用部分的定位：当&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/tool-combination?hl=zh-cn&quot;&gt;将自定义函数声明与内置工具&lt;/a&gt;（例如 Google 搜索）搭配使用时，模型可能会在单个对话轮次中返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionCall&lt;/code&gt;、&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;toolCall&lt;/code&gt; 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;toolResponse&lt;/code&gt; 部分的混合结果。因此，请勿假定 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;functionCall&lt;/code&gt; 始终是 parts 数组中的最后一项。如果您要手动解析 JSON 响应，请务必遍历 parts 数组，而不是依赖于位置。&lt;/li&gt;
&lt;li&gt;仅支持 &lt;a href=&quot;https://ai.google.dev/api/caching?hl=zh-cn#FunctionDeclaration&quot;&gt;OpenAPI 架构的一部分&lt;/a&gt;。&lt;/li&gt;
&lt;li&gt;对于 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ANY&lt;/code&gt; 模式，API 可能会拒绝非常大或嵌套很深的架构。如果您遇到错误，请尝试通过缩短属性名称、减少嵌套或限制函数声明的数量来简化函数参数和响应架构。&lt;/li&gt;
&lt;li&gt;Python 中支持的形参类型有限。&lt;/li&gt;
&lt;li&gt;自动函数调用仅为 Python SDK 功能。&lt;/li&gt;
&lt;/ul&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Google+Symbols:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&quot; rel=&quot;stylesheet&quot; /&gt;
  

  

  
&lt;/div&gt;

  
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
         
       
    
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:15:00 +0800</pubDate></item><item><title>全文转载：Gemini API 文本生成</title><link>https://suwenclub.cn/?id=40</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Gemini API 文本生成&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Google AI for Developers / Google AI for Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/text-generation?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://ai.google.dev/gemini-api/docs/text-generation?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developers.google.com/site-policies?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Creative Commons Attribution 4.0 / Apache 2.0 for code samples&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Google AI for Developers 官方中文文档。页面文字为 CC BY 4.0，代码示例为 Apache 2.0。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;
&lt;/p&gt;

&lt;h1 class=&quot;devsite-page-title&quot; id=&quot;text-generation&quot; tabindex=&quot;-1&quot;&gt;文本生成&lt;/h1&gt;

&lt;div id=&quot;gemini-api-switcher-trigger&quot; style=&quot;display:none;&quot;&gt;&lt;/div&gt;

&lt;p&gt;Gemini API 可以根据文本、图片、视频和音频输入生成文本输出。&lt;/p&gt;

&lt;p&gt;下面是一个基本示例：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Explain how AI works in a few words&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentWithTextInput&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;How does AI work?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'How AI does work?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;&lt;a id=&quot;configuration-parameters&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;thinking-with-gemini&quot; tabindex=&quot;-1&quot;&gt;与 Gemini 一起思考&lt;/h2&gt;

&lt;p&gt;Gemini 模型通常默认启用&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thinking?hl=zh-cn&quot;&gt;“思考”&lt;/a&gt;功能，以便模型在回答请求之前进行推理。&lt;/p&gt;

&lt;p&gt;每种模型都支持不同的思考配置，让您可以控制费用、延迟时间和智能程度。如需了解详情，请参阅&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/thinking?hl=zh-cn#set-budget&quot;&gt;思维指南&lt;/a&gt;。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_1&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;thinking_config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;thinking_level&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;low&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_1&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ThinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ThinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;LOW&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_1&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingLevelVal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;low&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ThinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingLevelVal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_1&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.ThinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentWithThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;thinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ThinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;thinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ThinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;low&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How does AI work?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_1&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;How does AI work?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;thinkingConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;thinkingLevel&quot;: &quot;low&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_1&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'How AI does work?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generationConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;thinkingLevel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'low'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;system-instructions&quot; tabindex=&quot;-1&quot;&gt;系统指令和其他配置&lt;/h2&gt;

&lt;p&gt;您可以使用系统指令来引导 Gemini 模型的行为。为此，请传递一个 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#v1beta.GenerationConfig&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;GenerateContentConfig&lt;/code&gt;&lt;/a&gt; 对象。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_2&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;system_instruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;You are a cat. Your name is Neko.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Hello there&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_2&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Hello there&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;systemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;You are a cat. Your name is Neko.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_2&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;SystemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;You are a cat. Your name is Neko.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleUser&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Hello there&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_2&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentWithSystemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;systemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;fromParts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;fromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;You are a cat. Your name is Neko.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Hello there&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_2&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;system_instruction&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          &quot;text&quot;: &quot;You are a cat. Your name is Neko.&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Hello there&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_2&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;systemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'You are a cat. Your name is Neko.'&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;systemInstruction&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Hello there'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;您还可以使用 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#v1beta.GenerationConfig&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;GenerateContentConfig&lt;/code&gt;&lt;/a&gt; 对象替换默认生成参数，例如 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#v1beta.GenerationConfig&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;max_output_tokens&lt;/code&gt;&lt;/a&gt;。&lt;/p&gt;

&lt;aside class=&quot;note&quot;&gt;
`temperature`、`top_p` 和 `top_k` 参数控制着模型生成回答的方式。虽然您可以修改这些参数，但我们强烈建议您将 Gemini 3.x 模型的这些参数保留为默认值。更改这些参数（例如，将温度设置为低于 1.0）可能会导致意外行为（例如循环或性能下降），尤其是在复杂的数学或推理任务中。
&lt;/aside&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_3&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google.genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Explain how AI works&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;devsite-syntax-n&quot;&gt;max_output_tokens&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;1000&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_3&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Explain how AI works&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;maxOutputTokens&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_3&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;log&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;MaxOutputTokens&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;   &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ResponseMIMEType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;What is the average size of a swallow?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_3&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentWithConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;maxOutputTokens&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Explain how AI works&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_3&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Explain how AI works&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;generationConfig&quot;: {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;stopSequences&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;Title&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      ],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      &quot;maxOutputTokens&quot;: 1000&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_3&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generationConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;maxOutputTokens&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;responseFormat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text/plain&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generationConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Explain how AI works in a few words'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;如需查看可配置参数及其说明的完整列表，请参阅 API 参考文档中的 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#v1beta.GenerationConfig&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;GenerateContentConfig&lt;/code&gt;&lt;/a&gt;。&lt;/p&gt;

&lt;h2 id=&quot;multimodal-input&quot; tabindex=&quot;-1&quot;&gt;多模态输入&lt;/h2&gt;

&lt;p&gt;Gemini API 支持多模态输入，让您可以将文本与媒体文件相结合。以下示例演示了如何提供图片：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_4&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;PIL&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Image&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;Image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;/path/to/organ.png&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tell me about this instrument&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_4&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createUserContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createPartFromUri&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;upload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;/path/to/organ.png&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createUserContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;([&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tell me about this instrument&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;createPartFromUri&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_4&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imagePath&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;/path/to/organ.jpg&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imgData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ReadFile&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imagePath&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewPartFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Tell me about this instrument&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;InlineData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&amp;amp;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Blob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;MIMEType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;image/jpeg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imgData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromParts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleUser&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_4&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentWithMultiModalInputs&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;fromParts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;fromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Tell me about this instrument&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;fromUri&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;/path/to/organ.jpg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;image/jpeg&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_4&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Use a temporary file to hold the base64 encoded image data&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nv&quot;&gt;TEMP_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;mktemp&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;trap&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'rm -f &quot;$TEMP_B64&quot;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;EXIT
base64&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$B64FLAGS&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$IMG_PATH&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$TEMP_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;# Use a temporary file to hold the JSON payload&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nv&quot;&gt;TEMP_JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;mktemp&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;trap&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'rm -f &quot;$TEMP_JSON&quot;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;EXIT

cat&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$TEMP_JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;lt;&amp;lt; &lt;/span&gt;EOF
&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;contents&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;parts&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;text&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Tell me about this instrument&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;,
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;inline_data&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;mime_type&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;image/jpeg&quot;&lt;/span&gt;,
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;data&quot;&lt;/span&gt;:&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;$(&lt;/span&gt;cat&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$TEMP_B64&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-o&quot;&gt;}&lt;/span&gt;
EOF

curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$TEMP_JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_4&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageUrl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'http://image/url'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getImageData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;imageUrl&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Tell me about this instrument'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getImageData&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;blob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getBlob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;blob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getContentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Utilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;base64Encode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;blob&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getBytes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;如需了解提供图片的其他方法和更高级的图片处理功能，请参阅我们的&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/image-understanding?hl=zh-cn&quot;&gt;图片理解指南&lt;/a&gt;。该 API 还支持&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/document-processing?hl=zh-cn&quot;&gt;文档&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/video-understanding?hl=zh-cn&quot;&gt;视频&lt;/a&gt;和&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/audio?hl=zh-cn&quot;&gt;音频&lt;/a&gt;输入和理解。&lt;/p&gt;

&lt;h2 id=&quot;streaming-responses&quot; tabindex=&quot;-1&quot;&gt;流式响应&lt;/h2&gt;

&lt;p&gt;默认情况下，模型仅在整个生成过程完成后才返回回答。&lt;/p&gt;

&lt;p&gt;为了获得更流畅的互动体验，请使用流式传输来逐步接收 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#v1beta.GenerateContentResponse&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;GenerateContentResponse&lt;/code&gt;&lt;/a&gt; 实例（在生成时）。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_5&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;generate_content_stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Explain how AI works&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_5&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;generateContentStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Explain how AI works&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_5&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GenerateContentStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Write a story about a magic backpack.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_5&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.ResponseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;GenerateContentStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ResponseStream&amp;lt;GenerateContentResponse&amp;gt;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;generateContentStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Write a story about a magic backpack.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// To save resources and avoid connection leaks, it is recommended to close the response&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// stream after consumption (or using try block to get the response stream).&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_5&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;--no-buffer&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Explain how AI works&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_5&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Explain how AI works'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:streamGenerateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;multi-turn-conversations&quot; tabindex=&quot;-1&quot;&gt;多轮对话（聊天）&lt;/h2&gt;

&lt;p&gt;我们的 SDK 提供相应功能，可将多轮提示和回答收集到聊天中，让您轻松跟踪对话历史记录。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 聊天功能仅作为 SDK 的一部分实现。在幕后，它仍使用 &lt;a href=&quot;https://ai.google.dev/api/generate-content?hl=zh-cn#method:-models.generatecontent&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;generateContent&lt;/code&gt;&lt;/a&gt; API。对于多轮对话，系统会在每个后续轮次中将完整的对话记录发送给模型。&lt;/span&gt;&lt;/aside&gt;&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_6&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;send_message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;send_message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'role - &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_6&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;model&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Chat response 1:&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Chat response 2:&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_6&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Hi nice to meet you! I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleUser&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;SendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_6&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;MultiTurnConversation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;First response: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Second response: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Get the history of the chat session.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Passing 'true' to getHistory() returns the curated history, which excludes&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// empty or invalid parts.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Passing 'false' here would return the comprehensive history, including&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// empty or invalid parts.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ImmutableList&amp;lt;Content&amp;gt;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getHistory&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;History: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_6&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Hello&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;model&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;I have two dogs in my house. How many paws are in my house?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_6&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Hello'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'model'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Great to meet you. What would you like to know?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'I have two dogs in my house. How many paws are in my house?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;流式传输还可用于多轮对话。&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;python_7&quot; tabindex=&quot;-1&quot;&gt;Python&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Python&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;google&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;send_message_stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;send_message_stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;devsite-syntax-ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;get_history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'role - &lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;devsite-syntax-n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;devsite-syntax-nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;javascript_7&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kr&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;@google/genai&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-ow&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;GoogleGenAI&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;model&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sendMessageStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;_&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;sendMessageStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;({&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream2&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;_&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-k&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;go_7&quot; tabindex=&quot;-1&quot;&gt;Go&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Go&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;context&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;os&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;google.golang.org/genai&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewClient&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Hi nice to meet you! I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleUser&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;NewContentFromText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;RoleModel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;SendMessageStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;genai&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Candidates&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;part&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_7&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.ResponseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nn&quot;&gt;com.google.genai.types.GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;MultiTurnConversationWithStreaming&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Chat&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;chats&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;gemini-3.5-flash&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ResponseStream&amp;lt;GenerateContentResponse&amp;gt;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;sendMessageStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;I have 2 dogs in my house.&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;sendMessageStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;How many paws are in my house?&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;GenerateContentResponse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;responseStream&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Get the history of the chat session. History is added after the stream&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// is consumed and includes the aggregated response from the stream.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;History: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;chatSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getHistory&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;rest_7&quot; tabindex=&quot;-1&quot;&gt;REST&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;curl&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;sse&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;x-goog-api-key: &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;$GEMINI_API_KEY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-X&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    &quot;contents&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Hello&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;model&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;Great to meet you. What would you like to know?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      },&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;role&quot;: &quot;user&quot;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        &quot;parts&quot;: [&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          {&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;            &quot;text&quot;: &quot;I have two dogs in my house. How many paws are in my house?&quot;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;          }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;        ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;      }&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;    ]&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-s1&quot;&gt;  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;apps-script_7&quot; tabindex=&quot;-1&quot;&gt;Apps 脚本&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;JavaScript&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// See https://developers.google.com/apps-script/guides/properties&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// for instructions on how to set the API key.&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;PropertiesService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getScriptProperties&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'GEMINI_API_KEY'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Hello'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'model'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'Great to meet you. What would you like to know?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'user'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'I have two dogs in my house. How many paws are in my house?'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:streamGenerateContent'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'x-goog-api-key'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;UrlFetchApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nb&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'candidates'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'content'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'parts'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s1&quot;&gt;'text'&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h2 id=&quot;prompting-tips&quot; tabindex=&quot;-1&quot;&gt;撰写提示的技巧！&lt;/h2&gt;

&lt;p&gt;如需了解如何充分利用 Gemini，请参阅我们的&lt;a href=&quot;https://ai.google.dev/gemini/docs/prompting-strategies?hl=zh-cn&quot;&gt;提示工程指南&lt;/a&gt;。&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot; tabindex=&quot;-1&quot;&gt;后续步骤&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;在 &lt;a href=&quot;https://aistudio.google.com?hl=zh-cn&quot;&gt;Google AI Studio 中试用 Gemini&lt;/a&gt;。&lt;/li&gt;
&lt;li&gt;尝试使用&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn&quot;&gt;结构化输出&lt;/a&gt;来生成类似 JSON 的回答。&lt;/li&gt;
&lt;li&gt;探索 Gemini 的&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/image-understanding?hl=zh-cn&quot;&gt;图片&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/video-understanding?hl=zh-cn&quot;&gt;视频&lt;/a&gt;、&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/audio?hl=zh-cn&quot;&gt;音频&lt;/a&gt;和&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/document-processing?hl=zh-cn&quot;&gt;文档&lt;/a&gt;理解功能。&lt;/li&gt;
&lt;li&gt;了解多模态&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/files?hl=zh-cn#prompt-guide&quot;&gt;文件提示策略&lt;/a&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Google+Symbols:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&quot; rel=&quot;stylesheet&quot; /&gt;
  

  

  
&lt;/div&gt;

  
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
         
       
    
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:12:00 +0800</pubDate></item><item><title>全文转载：Jetpack Compose 自适应应用入门</title><link>https://suwenclub.cn/?id=39</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Jetpack Compose 自适应应用入门&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Android Developers / Android Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/develop/ui/compose/layouts/adaptive?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://developer.android.com/develop/ui/compose/layouts/adaptive?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/license?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Android Developers Content License&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Android Developers 官方中文文档，页面内容和代码示例受 Android Developers 内容许可约束。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;如今，Android 大屏设备（包括平板电脑、可折叠设备、ChromeOS 设备、车载显示屏和电视）的使用量已超过 3 亿部，并且还在不断增加。为了在不断增加且种类繁多的大屏&lt;span style=&quot;white-space: nowrap;&quot;&gt;设备&lt;/span&gt;以及标准&lt;span style=&quot;white-space: nowrap;&quot;&gt;手机&lt;/span&gt;上提供最佳用户体验，请构建自适应应用。&lt;/p&gt;

&lt;h2 id=&quot;what_are_adaptive_apps&quot; tabindex=&quot;-1&quot;&gt;什么是自适应应用？&lt;/h2&gt;

&lt;p&gt;自适应应用会根据应用显示的变化（主要是应用窗口的大小）来更改布局。不过，自适应应用还能适应可折叠设备折叠状态的变化（例如桌面折叠状态或图书折叠状态），以及屏幕密度和字体大小的变化。&lt;/p&gt;

&lt;p&gt;自适应应用不会仅仅通过拉伸或缩小界面元素来响应不同的窗口大小，而是会替换布局组件并显示或隐藏内容。例如，在标准手机上，自适应应用可能会显示底部导航栏，但在大屏设备上，则会显示侧边导航栏。在大型屏幕上，自适应应用会显示更多内容，例如双窗格的列表-详情布局；在小型屏幕上，则会显示较少内容，即列表或详情。&lt;/p&gt;

&lt;figure style=&quot;width: 75%; margin: 1.5rem auto 1.25rem;&quot;&gt;
    &lt;video controls&gt;
        &lt;source src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/adaptive_app.mp4?hl=zh-cn&quot; type=&quot;video/mp4&quot; /&gt;
        您的浏览器不支持视频标记。
    &lt;/video&gt;
    &lt;figcaption&gt;
        &lt;b&gt;图 1.&lt;/b&gt; 自适应应用可针对不同的窗口大小优化布局。
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;过去，应用通常以全屏模式运行。如今，应用可以在任意大小的窗口中以多窗口模式运行，不受设备屏幕尺寸的限制。用户可以随时更改窗口大小。因此，即使在单一设备类型上，应用也必须具有自适应性。&lt;/p&gt;

&lt;p&gt;自适应应用在任何配置的任何设备上都能呈现出色的外观和运行效果。&lt;/p&gt;

&lt;h2 id=&quot;why_build_adaptive_uis&quot; tabindex=&quot;-1&quot;&gt;为什么要构建自适应界面？&lt;/h2&gt;

&lt;p&gt;用户希望您的应用在他们的所有设备上都能顺畅运行，并在大屏设备上提供增强的功能。用户可以在多窗口模式下执行多项任务，从而获得更出色的应用体验并提高工作效率。&lt;/p&gt;

&lt;p&gt;如果应用在标准手机上只能执行单项任务，那么将错失不断壮大的用户群，以及各种各样的可能性。&lt;/p&gt;

&lt;h3 id=&quot;google_play&quot; tabindex=&quot;-1&quot;&gt;Google Play&lt;/h3&gt;

&lt;p&gt;Google Play 提供平板电脑和可折叠设备专用应用合集和推荐，让用户能够发现高品质应用。&lt;/p&gt;

&lt;p&gt;Play 会将针对大屏设备优化的应用和游戏排在未优化的应用前面。Play 会根据&lt;a href=&quot;https://developer.android.com/docs/quality-guidelines/large-screen-app-quality?hl=zh-cn&quot;&gt;大屏设备应用质量指南&lt;/a&gt;对应用进行排名。
排名越高，应用就越容易被发现，因为多设备用户可以在手机上看到针对大屏幕设备的评分和评价。&lt;/p&gt;

&lt;p&gt;如果应用不符合 Play 商店的大屏设备质量标准，系统会在应用详情页面上显示警告。该警告会告知用户，相应应用可能无法在大屏设备上正常运行。&lt;/p&gt;

&lt;figure style=&quot;margin: 1rem auto 1.25rem; width: 85%;&quot;&gt;
    &lt;img alt=&quot;Google Play 商店中某个应用的商品详情，其中包含一条警告，指出“可能未针对您的设备进行优化”。&quot; src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/app_with_Play_warning_message.png?hl=zh-cn&quot; /&gt;
    &lt;figcaption&gt;
        &lt;b&gt;图 2.&lt;/b&gt; 应用详情页面上的技术质量警告。
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;构建自适应应用，以提高在 Google Play 上的曝光度，并最大限度地增加可下载您应用的设备数量。&lt;/p&gt;

&lt;h2 id=&quot;how_to_get_started&quot; tabindex=&quot;-1&quot;&gt;如何开始&lt;/h2&gt;

&lt;p&gt;在应用开发的各个阶段（从规划到部署）都应考虑自适应设计。向平面设计师介绍自适应设计。将应用设计为自适应应用，您将构建出易于管理、可扩展且可适应未来设备类型和窗口模式的应用。&lt;/p&gt;

&lt;p&gt;如需创建支持所有显示大小和配置的自适应应用，请执行以下操作：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;使用窗口大小类做出布局决策&lt;/li&gt;
&lt;li&gt;使用 Compose Material 3 自适应库进行构建&lt;/li&gt;
&lt;li&gt;支持触控以外的输入方式&lt;/li&gt;
&lt;li&gt;在所有设备类型上进行测试&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;window_size_classes&quot; tabindex=&quot;-1&quot;&gt;窗口大小类别&lt;/h3&gt;

&lt;p&gt;即使应用处于全屏模式，应用窗口尺寸在不同设备上（或在可折叠设备上）也可能不同。不同的设备屏幕方向会产生不同的宽高比。在多窗口模式下，应用窗口的大小、宽高比和屏幕方向可能与设备屏幕的不同。&lt;/p&gt;

&lt;p&gt;自适应应用在渲染布局时仅考虑应用窗口，从而简化并概括了确定和管理窗口大小、宽高比和屏幕方向的问题，即使应用窗口占满整个屏幕，这种方式也适用。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://developer.android.com/develop/ui/compose/layouts/adaptive/window-size-classes?hl=zh-cn&quot;&gt;窗口大小类别&lt;/a&gt;可根据窗口宽度或高度将应用窗口分类为&lt;em&gt;紧凑&lt;/em&gt;、&lt;em&gt;中等&lt;/em&gt;或&lt;em&gt;展开&lt;/em&gt;。&lt;/p&gt;

&lt;figure style=&quot;margin-bottom: 2rem;&quot;&gt;
    &lt;img alt=&quot;紧凑型、中等和扩展型宽度窗口大小类的图示。&quot; src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/window-size-classes/window_size_classes_width.png?hl=zh-cn&quot; /&gt;
    &lt;figcaption&gt;
        &lt;b&gt;图 3.&lt;/b&gt; 基于显示宽度的窗口大小类别。
    &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 由于垂直滚动很常见，因此在确定窗口大小类别时，窗口宽度通常是主要考虑因素。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;使用 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/package-summary?hl=zh-cn&quot;&gt;Compose Material 3 Adaptive 库&lt;/a&gt; 的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/package-summary?hl=zh-cn#currentWindowAdaptiveInfo()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;currentWindowAdaptiveInfo()&lt;/code&gt;&lt;/a&gt; 顶级函数计算应用的 &lt;a href=&quot;https://developer.android.com/reference/androidx/window/core/layout/WindowSizeClass?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;WindowSizeClass&lt;/code&gt;&lt;/a&gt;。该函数会返回一个 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;WindowAdaptiveInfo&lt;/code&gt;&lt;/a&gt; 实例，其中包含 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo?hl=zh-cn#windowSizeClass()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;windowSizeClass&lt;/code&gt;&lt;/a&gt;。每当窗口大小类别发生变化时，应用都会收到更新：&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre id=&quot;android_compose_windowsizeclass-code-sample&quot; class=&quot;devsite-click-to-copy notranslate&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;windowSizeClass&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;currentWindowAdaptiveInfo&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;windowSizeClass&lt;div class=&quot;devsite-github-link nocode no-select nocontent&quot;&gt;&lt;a target=&quot;_top&quot; href=&quot;https://github.com/android/snippets/blob/392c3a718f8a2514bd0a55bd88b10fc17f38320a/compose/snippets/src/main/java/com/example/compose/snippets/layouts/AdaptiveLayoutSnippets.kt#L85-L85&quot; class=&quot;gc-analytics-event&quot;&gt;AdaptiveLayoutSnippets&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;kt&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;p&gt;&lt;/p&gt;

&lt;h3 id=&quot;content_panes&quot; tabindex=&quot;-1&quot;&gt;内容窗格&lt;/h3&gt;

&lt;p&gt;Activity 的布局有时称为“界面”。&lt;em&gt;&lt;/em&gt;例如，您的应用可能包含主屏幕、列表界面和商品详情界面。此术语表示每个 activity 都会填满设备屏幕。&lt;/p&gt;

&lt;p&gt;不过，在足够大的设备屏幕上，可以支持展开宽度窗口尺寸类，因此多个 activity &lt;em&gt;屏幕&lt;/em&gt;可以同时显示在屏幕上。&lt;em&gt;窗格&lt;/em&gt;是用于更精确地指代各个 activity 的内容显示区域的术语。&lt;/p&gt;

&lt;p&gt;窗口大小类别可让您确定在多窗格布局中显示多少个内容窗格，如 &lt;a href=&quot;https://m3.material.io/foundations/layout/applying-layout/window-size-classes#70d1b184-a940-4169-a79a-b6643c470e73&quot;&gt;Material Design&lt;/a&gt; 中所指定的那样。&lt;/p&gt;

&lt;figure style=&quot;width: 50%; margin: 1.5rem auto 1.25rem;&quot;&gt;
    &lt;img alt=&quot;设备屏幕拆分为窗格：在紧凑型和中等窗口大小类中，拆分为一个窗格；在扩展型窗口大小类中，拆分为两个窗格。&quot; src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/panes_for_window_size_classes.png?hl=zh-cn&quot; /&gt;
    &lt;figcaption&gt;
        &lt;b&gt;图 4.&lt;/b&gt; 每个窗口大小类的内容窗格数量。
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;窗格可供浏览。在紧凑型和中等窗口大小类中，应用会显示单个窗格；因此，导航到任何目的地都会显示一个窗格。&lt;/p&gt;

&lt;p&gt;在展开的窗口大小类别中，应用可以在多个窗格中显示相关内容，例如列表‑详情布局。导航到任一窗格都会显示双窗格布局。如果窗口大小变为紧凑或中等，自适应应用将仅显示一个窗格（即导航目的地），可以是列表或详情。&lt;/p&gt;

&lt;table&gt;
    &lt;tbody&gt;&lt;tr&gt;
        &lt;td&gt;
            &lt;figure style=&quot;width: 96.5%; margin: .08rem 0 .11rem;&quot;&gt;
                &lt;video controls&gt;
                    &lt;source src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/list-detail_list.mp4?hl=zh-cn&quot; type=&quot;video/mp4&quot; /&gt;
                    您的浏览器不支持视频标记。
                &lt;/video&gt;
                &lt;figcaption&gt;
                    &lt;b&gt;图 5.&lt;/b&gt; 列表-详情布局，其中列表窗格为导航目标。
                &lt;/figcaption&gt;
            &lt;/figure&gt;
        &lt;/td&gt;&lt;td&gt;
            &lt;figure style=&quot;width: 100%; margin: .07rem 1.5rem .06rem 0;&quot;&gt;
                &lt;video controls&gt;
                    &lt;source src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/list-detail_detail.mp4?hl=zh-cn&quot; type=&quot;video/mp4&quot; /&gt;
                    您的浏览器不支持视频标记。
                &lt;/video&gt;
                &lt;figcaption&gt;
                    &lt;b&gt;图 6.&lt;/b&gt; 以详情窗格为导航目标的列表-详情布局。
                &lt;/figcaption&gt;
            &lt;/figure&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;h3 id=&quot;compose_material_3_adaptive&quot; tabindex=&quot;-1&quot;&gt;Compose Material 3 自适应&lt;/h3&gt;

&lt;p&gt;Jetpack Compose 是一种现代声明性方法，可用于构建自适应应用，而无需处理多个布局文件带来的重复和维护负担。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/package-summary?hl=zh-cn&quot;&gt;Compose Material 3 自适应库&lt;/a&gt;包含用于管理窗口大小类别、导航组件、多窗格布局以及可折叠姿态和铰链位置的可组合项，例如：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/navigationsuite/NavigationSuiteScaffold.composable?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;NavigationSuiteScaffold&lt;/code&gt;&lt;/a&gt;：根据应用窗口大小类别和设备姿态，自动在导航栏和侧边导航栏之间切换。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/layout/ListDetailPaneScaffold.composable?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ListDetailPaneScaffold&lt;/code&gt;&lt;/a&gt;：实现&lt;a href=&quot;https://developer.android.com/guide/topics/large-screens/large-screen-canonical-layouts?hl=zh-cn#list-detail&quot;&gt;列表-详情规范布局&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;使布局适应应用窗口大小。在较大窗口大小类别中，以并排窗格的形式呈现列表和列表项的详细信息；但在较小和中等窗口大小类别中，只呈现列表或详细信息。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/layout/SupportingPaneScaffold.composable?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;SupportingPaneScaffold&lt;/code&gt;&lt;/a&gt;：实现&lt;a href=&quot;https://developer.android.com/guide/topics/large-screens/large-screen-canonical-layouts?hl=zh-cn#supporting_pane&quot;&gt;支持窗格规范布局&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;在扩展型窗口大小类别中显示主要内容窗格和辅助窗格，但在紧凑型和中等窗口大小类别中仅显示主要内容窗格。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compose Material 3 自适应库是开发自适应应用的关键依赖项。&lt;/p&gt;

&lt;h3 id=&quot;configuration_and_continuity&quot; tabindex=&quot;-1&quot;&gt;配置和连续性&lt;/h3&gt;

&lt;p&gt;自适应应用在配置更改期间会保持连续性。&lt;/p&gt;

&lt;p&gt;当应用窗口大小调整、可折叠设备的姿态发生变化，或者屏幕密度或字体发生变化时，就会发生配置变更。&lt;/p&gt;

&lt;p&gt;默认情况下，配置更改会重新创建应用 activity，并且所有 activity 状态都会丢失。为保持连续性，自适应应用会在 activity 的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/android/app/Activity?hl=zh-cn#onsaveinstancestate_1&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;onSaveInstanceState()&lt;/code&gt;&lt;/a&gt; 方法或 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ViewModel&lt;/code&gt;&lt;/a&gt; 中保存状态。&lt;/p&gt;

&lt;h4 id=&quot;posture&quot; tabindex=&quot;-1&quot;&gt;安全状况&lt;/h4&gt;

&lt;p&gt;自适应应用可以响应可折叠设备折叠状态的变化。姿态包括桌面姿态和图书姿态。&lt;/p&gt;

&lt;figure style=&quot;margin: 1.5rem auto 1.25rem; width: 60%;&quot;&gt;
    &lt;img alt=&quot;一部处于桌上模式的折叠屏手机，屏幕的下半部分放在平面上，上半部分竖立。&quot; src=&quot;https://developer.android.com/static/develop/ui/compose/images/layouts/adaptive/build-adaptive-apps/foldable_in_tabletop_posture.png?hl=zh-cn&quot; /&gt;
    &lt;figcaption&gt;
        &lt;b&gt;图 7.&lt;/b&gt; 处于桌面折叠状态的可折叠设备。
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;借助 Jetpack WindowManager 中的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/window/layout/WindowInfoTracker?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;WindowInfoTracker&lt;/code&gt;&lt;/a&gt; 接口，您可以获取设备的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/window/layout/DisplayFeature?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DisplayFeature&lt;/code&gt;&lt;/a&gt; 对象列表。显示功能包括 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/window/layout/FoldingFeature.State?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;FoldingFeature.State&lt;/code&gt;&lt;/a&gt;，用于指示设备是完全打开还是半打开。&lt;/p&gt;

&lt;p&gt;Compose Material 3 Adaptive 库提供 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/package-summary?hl=zh-cn#currentWindowAdaptiveInfo()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;currentWindowAdaptiveInfo()&lt;/code&gt;&lt;/a&gt; 顶级函数，该函数会返回一个包含 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo?hl=zh-cn#windowPosture()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;windowPosture&lt;/code&gt;&lt;/a&gt; 的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;WindowAdaptiveInfo&lt;/code&gt;&lt;/a&gt; 实例。&lt;/p&gt;

&lt;h3 id=&quot;input_beyond_touch&quot; tabindex=&quot;-1&quot;&gt;触控以外的输入方式&lt;/h3&gt;

&lt;p&gt;用户通常会将外接键盘、触控板、鼠标和触控笔连接到大屏设备。这些外围设备可提高用户的工作效率、输入精确度、个人表达能力和无障碍功能。大多数 ChromeOS 设备都内置了键盘和触控板。&lt;/p&gt;

&lt;p&gt;自适应应用支持外部输入设备，但 Android 框架会为您完成大部分工作：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Jetpack Compose 1.7 及更高版本：默认支持键盘标签页导航以及鼠标或触控板点击、选择和滚动。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jetpack &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;androidx.compose.material3&lt;/code&gt;&lt;/a&gt; 库：使用户能够使用触控笔在任何 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/material/TextField.composable?hl=zh-cn#TextField(androidx.compose.ui.text.input.TextFieldValue,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.ui.text.TextStyle,kotlin.Function0,kotlin.Function0,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.text.input.VisualTransformation,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.KeyboardActions,kotlin.Boolean,kotlin.Int,kotlin.Int,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.material.TextFieldColors)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextField&lt;/code&gt;&lt;/a&gt; 组件中书写。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://developer.android.com/develop/ui/compose/touch-input/keyboard-input/keyboard-shortcuts-helper?hl=zh-cn&quot;&gt;键盘快捷键辅助工具&lt;/a&gt;：让用户可以发现 Android 平台和应用键盘快捷键。通过替换 &lt;a href=&quot;https://developer.android.com/reference/kotlin/android/view/Window.Callback?hl=zh-cn#onprovidekeyboardshortcuts&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;onProvideKeyboardShortcuts()&lt;/code&gt;&lt;/a&gt; 窗口回调，在键盘快捷键帮助程序中发布应用的键盘快捷键。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;为了全面支持各种尺寸的设备，自适应应用支持所有类型的输入。&lt;/p&gt;

&lt;h2 id=&quot;how_to_test_adaptive_apps&quot; tabindex=&quot;-1&quot;&gt;如何测试自适应应用&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://developer.android.com/training/testing/different-screens?hl=zh-cn&quot;&gt;测试不同的屏幕和窗口尺寸&lt;/a&gt;以及不同的设备配置。
使用宿主端屏幕截图和 Compose 预览来检查应用布局。
在 Android Studio 模拟器和 Google 数据中心内托管的远程 Android 设备上运行应用。&lt;/p&gt;

&lt;h3 id=&quot;app_quality_guidelines&quot; tabindex=&quot;-1&quot;&gt;大屏设备应用质量指南&lt;/h3&gt;

&lt;p&gt;借助&lt;a href=&quot;https://developer.android.com/docs/quality-guidelines/large-screen-app-quality?hl=zh-cn&quot;&gt;大屏设备应用质量指南&lt;/a&gt;，您可以验证自适应应用在平板电脑、可折叠设备和 ChromeOS 设备上是否能正常运行。该指南包含一些测试，可让您验证关键用户历程的应用功能。虽然这些指南侧重于大屏幕，但它们与所有屏幕尺寸兼容。&lt;/p&gt;

&lt;h3 id=&quot;multiple_configurations&quot; tabindex=&quot;-1&quot;&gt;多个配置&lt;/h3&gt;

&lt;p&gt;Compose 1.7 及更高版本中的 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/ui/test/DeviceConfigurationOverride?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DeviceConfigurationOverride&lt;/code&gt;&lt;/a&gt; 接口可让您替换设备配置的各个方面。该 API 以本地化的方式模拟不同的设备配置，以便测试您所需的任何可组合内容。例如，您可以在单个设备或模拟器上运行测试套件，一次性测试多个任意界面尺寸。&lt;/p&gt;

&lt;p&gt;借助 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/ui/test/DeviceConfigurationOverride?hl=zh-cn#(androidx.compose.ui.test.DeviceConfigurationOverride).then(androidx.compose.ui.test.DeviceConfigurationOverride)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DeviceConfigurationOverride.then()&lt;/code&gt;&lt;/a&gt; 扩展函数，您可以同时测试多个配置参数，例如字体大小、语言区域、主题和布局大小。&lt;/p&gt;

&lt;h3 id=&quot;host-side_screenshots&quot; tabindex=&quot;-1&quot;&gt;主机端屏幕截图&lt;/h3&gt;

&lt;p&gt;主机端截屏测试是一种快速且可扩缩的方式，用于验证应用布局的视觉外观。使用主机端屏幕截图测试界面在各种显示尺寸下的效果。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅 &lt;a href=&quot;https://developer.android.com/studio/preview/compose-screenshot-testing?hl=zh-cn&quot;&gt;Compose 预览版屏幕截图测试&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;compose_previews&quot; tabindex=&quot;-1&quot;&gt;Compose 预览&lt;/h3&gt;

&lt;p&gt;借助 Compose 预览，您可以在 Android Studio 的设计视图中查看应用的界面。预览使用 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewScreenSizes?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;@PreviewScreenSizes&lt;/code&gt;&lt;/a&gt;、&lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewFontScale?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;@PreviewFontScale&lt;/code&gt;&lt;/a&gt; 和 &lt;a href=&quot;https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewLightDark?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;@PreviewLightDark&lt;/code&gt;&lt;/a&gt; 等注释，让您能够以各种配置查看可组合项内容。您甚至可以与预览互动。&lt;/p&gt;

&lt;p&gt;Android Studio 还会在预览中突出显示常见的易用性问题，例如过宽的按钮或文本字段。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/develop/ui/compose/tooling/previews?hl=zh-cn&quot;&gt;使用可组合项预览功能预览界面&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;emulators&quot; tabindex=&quot;-1&quot;&gt;模拟器&lt;/h3&gt;

&lt;p&gt;Android Studio 提供了各种模拟器，可用于测试不同的布局尺寸：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;可调整大小的模拟器：可模拟手机、平板电脑或可折叠设备，并让您在这些设备之间即时切换&lt;/li&gt;
&lt;li&gt;Pixel Fold 模拟器：模拟 Pixel Fold 大屏可折叠手机&lt;/li&gt;
&lt;li&gt;Pixel Tablet 模拟器：模拟 Pixel Tablet 大屏设备&lt;/li&gt;
&lt;li&gt;桌面模拟器：可用于测试自由调整窗口大小、鼠标悬停和键盘快捷键&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;remote_device_streaming&quot; tabindex=&quot;-1&quot;&gt;远程设备在线播放&lt;/h3&gt;

&lt;p&gt;安全地连接到 Google 数据中心内托管的远程 Android 设备，并在最新的 Pixel 和 Samsung 设备上运行您的应用。安装和调试应用、运行 ADB 命令，以及旋转和折叠设备，以验证应用在各种真机设备上都能正常运行。&lt;/p&gt;

&lt;p&gt;远程设备串流功能已集成到 Android Studio 中。如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/studio/run/android-device-streaming?hl=zh-cn&quot;&gt;由 Firebase 提供支持的 Android 设备串流&lt;/a&gt;。&lt;/p&gt;

&lt;h2 id=&quot;additional_resources&quot; tabindex=&quot;-1&quot;&gt;其他资源&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I/O 大会演讲：&lt;a href=&quot;https://io.google/2024/explore/d16737ba-e336-4b68-8928-24692a88e644/?hl=zh-cn&quot;&gt;构建自适应 Android 应用&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  
  

  
    &lt;devsite-hats-survey class=&quot;nocontent&quot; data-nosnippet
      hats-id=&quot;m71UDKaJT0kxBYCLVTd0U6CJGcqa&quot;
      listnr-id=&quot;5207477&quot;&gt;&lt;/devsite-hats-survey&gt;
  
&lt;/div&gt;
    &lt;div class=&quot;devsite-steps&quot;&gt;
  
  &lt;div class=&quot;steps-previous steps-direction&quot;&gt;
    &lt;a href=&quot;https://developer.android.com/develop/ui/compose/layouts/adaptive/flexbox/item-behavior?hl=zh-cn&quot;
       class=&quot;steps-link gc-analytics-event&quot;
      
      
      &gt;
      
      &lt;div class=&quot;steps-link-direction&quot;&gt;上一页&lt;/div&gt;
      &lt;span class=&quot;steps-link-arrow steps-link-arrow-left material-icons&quot; aria-hidden=&quot;true&quot;&gt;
        arrow_back
      &lt;/span&gt;
      &lt;span class=&quot;steps-link-title-previous steps-link-title&quot;&gt;
        设置商品行为
      &lt;/span&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  
  
  &lt;div class=&quot;steps-next steps-direction&quot;&gt;
    &lt;a href=&quot;https://developer.android.com/develop/ui/compose/layouts/adaptive/app-orientation-aspect-ratio-resizability?hl=zh-cn&quot;
       class=&quot;steps-link gc-analytics-event&quot;
      
      
      &gt;
      
      &lt;div class=&quot;steps-link-direction&quot;&gt;下一页&lt;/div&gt;
      &lt;span class=&quot;steps-link-title-next steps-link-title&quot;&gt;
        应用屏幕方向、宽高比和尺寸调整
      &lt;/span&gt;
      &lt;span class=&quot;steps-link-arrow steps-link-arrow-right material-icons&quot; aria-hidden=&quot;true&quot;&gt;
        arrow_forward
      &lt;/span&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  
&lt;/div&gt;
  

  
    
      &lt;devsite-recommendations display=&quot;in-page&quot; hidden yield&gt;
      &lt;/devsite-recommendations&gt;
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
    
    
      &lt;devsite-recommendations id=&quot;recommendations-link&quot; yield&gt;&lt;/devsite-recommendations&gt;
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:09:00 +0800</pubDate></item><item><title>全文转载：Android 17 功能和 API</title><link>https://suwenclub.cn/?id=38</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Android 17 功能和 API&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Android Developers / Android Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/about/versions/17/features?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://developer.android.com/about/versions/17/features?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/license?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Android Developers Content License&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Android Developers 官方中文文档，页面内容和代码示例受 Android Developers 内容许可约束。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;&lt;/p&gt;



&lt;p&gt;Android 17 面向开发者引入了一些出色的新功能和 API。以下各部分总结了这些功能，可帮助您开始使用相关 API。&lt;/p&gt;

&lt;p&gt;如需查看新增、修改和移除的 API 的详细列表，请参阅 &lt;a href=&quot;https://developer.android.com/sdk/api_diff/c-beta2/changes?hl=zh-cn&quot;&gt;API 差异报告&lt;/a&gt;。如需详细了解新的 API，请访问 &lt;a href=&quot;https://developer.android.com/reference?hl=zh-cn&quot;&gt;Android API 参考文档&lt;/a&gt;，新 API 会突出显示以方便查看。&lt;/p&gt;

&lt;p&gt;您还应查看平台变更可能会在哪些方面影响您的应用。如需了解详情，请参阅以下页面：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn&quot;&gt;当应用以 Android 17 为目标平台时会受到影响的行为变更&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn&quot;&gt;影响所有应用（无论 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;targetSdkVersion&lt;/code&gt; 为何）的行为变更&lt;/a&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 此页面列出了一些比较重要的新功能。如需了解更多详细信息，请参阅 &lt;a href=&quot;https://developer.android.com/about/versions/17/release-notes?hl=zh-cn&quot;&gt;Android 17 版本说明&lt;/a&gt;。&lt;/span&gt;&lt;/aside&gt;
&lt;h2 id=&quot;core&quot; tabindex=&quot;-1&quot;&gt;核心功能&lt;/h2&gt;

&lt;p&gt;Android 17 添加了以下与核心 Android 功能相关的新功能。&lt;/p&gt;

&lt;h3 id=&quot;profilingmanager-new-triggers&quot; tabindex=&quot;-1&quot;&gt;新的 ProfilingManager 触发器&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 向 &lt;a href=&quot;https://developer.android.com/topic/performance/tracing/profiling-manager/overview?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ProfilingManager&lt;/code&gt;&lt;/a&gt; 添加了多个新的系统触发器，以
帮助您收集深入数据来调试性能问题。&lt;/p&gt;

&lt;p&gt;新触发器包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/os/ProfilingTrigger?hl=zh-cn#TRIGGER_TYPE_COLD_START&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_COLD_START&lt;/code&gt;&lt;/a&gt;：在应用冷启动期间触发。它在响应中同时提供调用堆栈样本和系统跟踪记录。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/os/ProfilingTrigger?hl=zh-cn#TRIGGER_TYPE_OOM&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_OOM&lt;/code&gt;&lt;/a&gt;：当应用抛出
&lt;a href=&quot;https://developer.android.com/reference/java/lang/OutOfMemoryError?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;OutOfMemoryError&lt;/code&gt;&lt;/a&gt;时触发，并在响应中提供 Java 堆转储。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/os/ProfilingTrigger?hl=zh-cn#TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE&lt;/code&gt;&lt;/a&gt;：当应用因 CPU 使用异常且过高而被终止时触发，并在响应中提供调用堆栈样本。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/os/ProfilingTrigger?hl=zh-cn#TRIGGER_TYPE_ANOMALY&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_ANOMALY&lt;/code&gt;&lt;/a&gt;：检测系统性能异常，例如 binder 调用过多和内存用量过高。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如需了解如何设置系统触发器，请参阅有关
&lt;a href=&quot;https://developer.android.com/topic/performance/tracing/profiling-manager/trigger-based-capture?hl=zh-cn&quot;&gt;基于触发器的性能分析&lt;/a&gt;的文档以及有关如何&lt;a href=&quot;https://developer.android.com/topic/performance/tracing/profiling-manager/retrieve-and-analyze?hl=zh-cn&quot;&gt;检索和分析性能分析数据
的文档&lt;/a&gt;。&lt;/p&gt;

&lt;h4 id=&quot;anomaly-profiling-trigger&quot; tabindex=&quot;-1&quot;&gt;应用异常的性能分析触发器&lt;/h4&gt;

&lt;p&gt;Android 17 引入了一项设备端异常检测服务，用于监控资源密集型行为和潜在的兼容性回归。此服务与&lt;a href=&quot;https://developer.android.com/topic/performance/tracing/profiling-manager/overview?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ProfilingManager&lt;/code&gt;&lt;/a&gt;集成，可让您的应用接收由特定系统检测到的事件触发的性能分析工件。&lt;/p&gt;

&lt;p&gt;使用 &lt;a href=&quot;https://developer.android.com/reference/android/os/ProfilingTrigger?hl=zh-cn#TRIGGER_TYPE_ANOMALY&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_ANOMALY&lt;/code&gt;&lt;/a&gt; 触发器检测系统性能问题
例如 binder 调用过多和内存用量过高。当应用违反操作系统定义的内存限制时，异常触发器允许开发者接收特定于应用的堆转储，以帮助识别和修复内存问题。此外，对于 binder 垃圾内容过多，异常触发器会提供有关 binder 事务的堆栈抽样分析报告。&lt;/p&gt;

&lt;p&gt;此 API 回调发生在系统强制执行任何操作之前。例如，它可以帮助开发者在应用因超出内存限制而被系统终止之前收集调试数据。&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;profilingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;applicationContext&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ProfilingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;triggers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ArrayList&amp;lt;ProfilingTrigger&amp;gt;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;triggers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ProfilingTrigger&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ProfilingTrigger&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;TRIGGER_TYPE_ANOMALY&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;mainExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executors&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;resultCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Consumer&amp;lt;ProfilingResult&amp;gt;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;profilingResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;-&lt;/span&gt;&amp;gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;profilingResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;errorCode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ProfilingResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;ERROR_NONE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// upload profile result to server for further analysis&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;setupProfileUploadWorker&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;profilingResult&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;resultFilePath&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;profilingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;registerForAllProfilingResults&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;mainExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                                                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;resultCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;profilingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;addProfilingTriggers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;triggers&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;

  

&lt;h3 id=&quot;job-debug-info&quot; tabindex=&quot;-1&quot;&gt;JobDebugInfo API&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 引入了新的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;JobDebugInfo&lt;/code&gt; API，可帮助开发者调试其 JobScheduler 作业，了解作业未运行的原因、运行时长以及其他汇总信息。&lt;/p&gt;

&lt;p&gt;扩展后的 JobDebugInfo API 的第一个方法是 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getPendingJobReasonStats()&lt;/code&gt;，该方法会返回一个映射，其中包含&lt;a href=&quot;https://developer.android.com/reference/android/app/job/JobScheduler?hl=zh-cn#constants_1&quot;&gt;作业处于待执行状态的原因&lt;/a&gt;及其各自的累计待执行时长。此方法将 &lt;a href=&quot;https://developer.android.com/reference/android/app/job/JobScheduler?hl=zh-cn#getPendingJobReasonsHistory(int)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getPendingJobReasonsHistory()&lt;/code&gt;&lt;/a&gt; 和 &lt;a href=&quot;https://developer.android.com/reference/android/app/job/JobScheduler?hl=zh-cn#getPendingJobReasons(int)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getPendingJobReasons()&lt;/code&gt;&lt;/a&gt; 方法联接在一起，可让您了解预定作业未按预期运行的原因，但通过在单个方法中同时提供时长和作业原因，简化了信息检索。&lt;/p&gt;

&lt;p&gt;例如，对于指定的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;jobId&lt;/code&gt;，该方法可能会返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;PENDING_JOB_REASON_CONSTRAINT_CHARGING&lt;/code&gt; 和 60000 毫秒的时长，表示作业因未满足充电约束而处于等待状态 60000 毫秒。&lt;/p&gt;

  

&lt;h3 id=&quot;allow-while-idle-alarms&quot; tabindex=&quot;-1&quot;&gt;通过为允许空闲时运行的闹钟提供监听器支持，减少唤醒锁定&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17
引入了 &lt;a href=&quot;https://developer.android.com/reference/android/app/AlarmManager?hl=zh-cn#setExactAndAllowWhileIdle(int,%20long,%20java.lang.String,%20java.util.concurrent.Executor,%20android.app.AlarmManager.OnAlarmListener)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AlarmManager.setExactAndAllowWhileIdle&lt;/code&gt;&lt;/a&gt; 的新变体，该变体
接受 &lt;a href=&quot;https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;OnAlarmListener&lt;/code&gt;&lt;/a&gt; 而不是 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;PendingIntent&lt;/code&gt;。这种基于回调的新机制非常适合目前依赖于连续唤醒锁来执行定期任务的应用，例如维护套接字连接的消息传递应用。&lt;/p&gt;

  

&lt;h2 id=&quot;privacy&quot; tabindex=&quot;-1&quot;&gt;隐私权&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下新功能，可提升用户隐私保护。&lt;/p&gt;

&lt;h3 id=&quot;ech-platform-support&quot; tabindex=&quot;-1&quot;&gt;加密客户端 Hello (ECH) 平台支持&lt;/h3&gt;


    
&lt;p&gt;Android 17 引入了对加密客户端 Hello (ECH) 的平台支持，这是对网络通信的一项重大隐私增强功能。ECH 是一项 TLS 1.3 扩展，可在初始 TLS 握手期间加密服务器名称指示 (SNI)。这种加密有助于保护用户隐私，因为它可以让网络中介更难识别应用连接到的特定网域。&lt;/p&gt;

&lt;p&gt;该平台现在包含网络库实现 ECH 所需的 API。这包括 &lt;a href=&quot;https://developer.android.com/reference/android/net/DnsResolver?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DnsResolver&lt;/code&gt;&lt;/a&gt; 中的新功能，用于查询包含 ECH 配置的 HTTPS DNS 记录；以及 Conscrypt 的 SSLEngine 和 SSLSocket 中的新方法，用于在连接到网域时传入这些配置来启用 ECH。开发者可以通过网络安全配置文件中的新 &lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#domainEncryption&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;lt;domainEncryption&amp;gt;&lt;/code&gt;&lt;/a&gt; 元素来配置 ECH 偏好设置，例如机会性地启用 ECH 或强制使用 ECH，这些设置可全局应用，也可按网域应用。&lt;/p&gt;

&lt;p&gt;预计 HttpEngine、WebView 和 OkHttp 等热门联网库将在未来的更新中集成这些平台 API，从而使应用能够更轻松地采用 ECH 并增强用户隐私保护。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#EncryptedClientHelloSummary&quot;&gt;加密的客户端 Hello&lt;/a&gt; 文档。&lt;/p&gt;

  

&lt;h3 id=&quot;contact-picker&quot; tabindex=&quot;-1&quot;&gt;Android 联系人选择器&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 联系人选择工具是一个标准化的可浏览界面，供用户与您的应用分享联系人。该选择工具适用于搭载 Android 17（API 级别 37）或更高版本的设备，可提供一种可保护隐私的替代方案，以取代广泛的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;READ_CONTACTS&lt;/code&gt; 权限。您的应用无需请求访问用户的整个地址簿，而是指定所需的数据字段（例如电话号码或电子邮件地址），然后用户选择要分享的特定联系人。这样，您的应用便只能读取所选数据，从而确保精细控制，同时提供一致的用户体验，并具有内置搜索、个人资料切换和多选功能，而无需构建或维护界面。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/about/versions/17/features/contact-picker?hl=zh-cn&quot;&gt;联系人选择工具文档&lt;/a&gt;。&lt;/p&gt;

  

&lt;h2 id=&quot;security&quot; tabindex=&quot;-1&quot;&gt;安全&lt;/h2&gt;

&lt;p&gt;Android 17 添加了以下新功能，以提升设备和应用安全性。&lt;/p&gt;

&lt;h3 id=&quot;advanced-protection-mode&quot; tabindex=&quot;-1&quot;&gt;Android 高级保护模式 (AAPM)&lt;/h3&gt;


    
&lt;p&gt;Android 高级保护模式为 Android 用户提供了一套强大的新安全功能，标志着在保护用户（尤其是面临较高风险的用户）免遭复杂攻击方面迈出了重要一步。AAPM 是一项选择启用功能，只需进行一项配置设置即可激活。用户可以随时启用该功能，以应用一套主观的安全保护措施。&lt;/p&gt;

&lt;p&gt;这些核心配置包括：禁止安装未知来源的应用（旁加载）、限制 USB 数据信号传输，以及强制执行 Google Play 保护机制扫描，从而显著减小设备的攻击面。
开发者可以使用 &lt;a href=&quot;https://developer.android.com/reference/android/security/advancedprotection/AdvancedProtectionManager?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AdvancedProtectionManager&lt;/code&gt;&lt;/a&gt; API 与此功能集成，以检测模式的状态，从而使应用能够在用户选择启用此模式时自动采用强化型安全姿态或限制高风险功能。&lt;/p&gt;

  

&lt;h3 id=&quot;pqc-apk-signing&quot; tabindex=&quot;-1&quot;&gt;PQC APK 签名&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 现在支持混合 APK 签名方案，以保护应用的签名身份免受利用量子计算的攻击的潜在威胁。此功能引入了一种新的 APK 签名方案，可让您将经典签名密钥（例如 RSA 或 EC）与新的后量子加密 (PQC) 算法 (ML-DSA) 配对。&lt;/p&gt;

&lt;p&gt;这种混合方法可确保您的应用在未来免受量子攻击，同时与依赖于经典签名验证的旧版 Android 和设备保持完全的向后兼容性。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 您需要创建新的经典签名密钥，以便与 PQC 密钥配对。您无法重复使用混合模式之前的经典签名密钥。&lt;/span&gt;&lt;/aside&gt;
&lt;h4 id=&quot;impact_on_developers&quot; tabindex=&quot;-1&quot;&gt;对开发者的影响&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;使用 Play 应用签名的应用&lt;/strong&gt;：如果您使用 Play 应用签名，可以等待 Google Play 为您提供使用 Google Play 生成的 PQC 密钥升级混合签名的选项，从而确保您的应用受到保护，而无需手动管理密钥。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;使用自行管理的密钥的应用&lt;/strong&gt;：自行管理签名密钥的开发者可以利用更新后的 Android build 工具（例如 apksigner）轮换到混合身份，将 PQC 密钥与新的经典密钥相结合。（您必须创建新的经典密钥，无法重复使用旧密钥。）&lt;/li&gt;
&lt;/ul&gt;

  

&lt;h2 id=&quot;connectivity&quot; tabindex=&quot;-1&quot;&gt;连接&lt;/h2&gt;

&lt;p&gt;Android 17 添加了以下功能，以改进设备和应用连接。&lt;/p&gt;

&lt;h3 id=&quot;satellite&quot; tabindex=&quot;-1&quot;&gt;受限卫星网络&lt;/h3&gt;


    
&lt;p&gt;实现优化，使应用能够在低带宽卫星网络上有效运行。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 此功能已随 Android 16 QPR2 季度版本正式发布。如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/develop/connectivity/satellite/constrained-networks?hl=zh-cn&quot;&gt;针对受限卫星网络进行开发&lt;/a&gt;。&lt;/span&gt;&lt;/aside&gt;

  

&lt;h2 id=&quot;ux-sysui&quot; tabindex=&quot;-1&quot;&gt;用户体验和系统界面&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，旨在提升用户体验。&lt;/p&gt;

&lt;h3 id=&quot;assistant-volume&quot; tabindex=&quot;-1&quot;&gt;专用 Google 助理音量音频流&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 为 Google 助理应用引入了专用的 Google 助理音量流，
以便使用 &lt;a href=&quot;https://developer.android.com/reference/android/media/AudioAttributes?hl=zh-cn#USAGE_ASSISTANT&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;USAGE_ASSISTANT&lt;/code&gt;&lt;/a&gt; 进行播放。此项更改将 Google 助理音频与标准媒体流分离，让用户可以单独控制这两个音量。这样便可实现以下场景：将媒体播放静音，同时保持 Google 助理响应的可听性，反之亦然。&lt;/p&gt;

&lt;p&gt;有权访问新的 &lt;a href=&quot;https://developer.android.com/reference/android/media/AudioManager?hl=zh-cn#MODE_ASSISTANT_CONVERSATION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;MODE_ASSISTANT_CONVERSATION&lt;/code&gt;&lt;/a&gt; 音频模式的 Google 助理应用可以进一步提高音量控制的一致性。Google 助理应用可以使用此模式向系统提供有关活跃 Google 助理会话的提示，确保可以在活跃 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;USAGE_ASSISTANT&lt;/code&gt; 播放之外或使用连接的蓝牙外设控制 Google 助理流。&lt;/p&gt;

  

&lt;h3 id=&quot;handoff&quot; tabindex=&quot;-1&quot;&gt;Handoff&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;切换是 Android 17 中新增的一项功能和 API，应用开发者可以将其集成到应用中，以便为用户提供跨设备连续性。它允许用户在一个 Android 设备上启动应用 activity，然后将其转移到另一个 Android 设备。Handoff 在用户设备的后台运行，并通过各种入口点（例如接收设备上的启动器和任务栏）显示用户附近其他设备上的可用活动。&lt;/p&gt;

&lt;p&gt;应用可以指定 Handoff 来启动相同的原生 Android 应用（如果该应用已安装在接收设备上且可供使用）。在此应用到应用流程中，用户通过深层链接跳转到指定 activity。或者，应用到网站切换功能可以作为后备选项提供，也可以通过网址切换功能直接实现。&lt;/p&gt;

&lt;p&gt;切换支持是按 activity 实现的。如需启用 Handoff，请针对 activity 调用 &lt;a href=&quot;https://developer.android.com/reference/android/app/Activity?hl=zh-cn#setHandoffEnabled(boolean,%20android.app.HandoffActivityParams)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;setHandoffEnabled()&lt;/code&gt;&lt;/a&gt; 方法。可能需要随切换传递其他数据，以便接收设备上重新创建的 activity 可以恢复适当的状态。实现 &lt;a href=&quot;https://developer.android.com/reference/android/app/Activity?hl=zh-cn#onHandoffActivityDataRequested(android.app.HandoffActivityDataRequestInfo)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;onHandoffActivityDataRequested()&lt;/code&gt;&lt;/a&gt; 回调以返回 &lt;a href=&quot;https://developer.android.com/reference/android/app/HandoffActivityData?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;HandoffActivityData&lt;/code&gt;&lt;/a&gt; 对象，该对象包含用于指定 Handoff 应如何处理并在接收设备上重新创建 activity 的详细信息。&lt;/p&gt;

  

&lt;h3 id=&quot;live-update&quot; tabindex=&quot;-1&quot;&gt;实时更新 - 语义颜色 API&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;在 Android 17 中，&lt;a href=&quot;https://developer.android.com/develop/ui/views/notifications/live-update?hl=zh-cn&quot;&gt;实时更新&lt;/a&gt;启动了语义着色 API，以支持具有通用含义的颜色。&lt;/p&gt;

&lt;p&gt;以下类支持语义着色：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/partners/android-17/features/semantic-coloring/reference/Notification?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Notification&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/partners/android-17/features/semantic-coloring/reference/Notification.Metric?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Notification.Metric&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/partners/android-17/features/semantic-coloring/reference/Notification.ProgressStyle.Point?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Notification.ProgressStyle.Point&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/partners/android-17/features/semantic-coloring/reference/Notification.ProgressStyle.Segment?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Notification.ProgressStyle.Segment&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;coloring&quot; tabindex=&quot;-1&quot;&gt;填色游戏&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color:green&quot;&gt;绿色&lt;/span&gt;：与安全相关。此颜色应在以下情况下使用：让别人知道您处于安全状态。&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color:black;color:orange&quot;&gt;橙色&lt;/span&gt;：用于表示警告和标记物理危险。在用户需要注意以设置更好的保护设置的情况下，应使用此颜色。&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color:red&quot;&gt;红色&lt;/span&gt;：通常表示危险、停止。它应在需要人们紧急关注的情况下显示。&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color:blue&quot;&gt;蓝色&lt;/span&gt;：中性颜色，适用于信息性内容，应与其他内容区分开来。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下示例展示了如何将语义样式应用于通知中的文本：&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;ssb&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SpannableStringBuilder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Colors: &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;NONE&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createSemanticStyleAnnotation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SEMANTIC_STYLE_UNSPECIFIED&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;INFO&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createSemanticStyleAnnotation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SEMANTIC_STYLE_INFO&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;SAFE&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createSemanticStyleAnnotation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SEMANTIC_STYLE_SAFE&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;CAUTION&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createSemanticStyleAnnotation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SEMANTIC_STYLE_CAUTION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;DANGER&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createSemanticStyleAnnotation&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SEMANTIC_STYLE_DANGER&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;channelId&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSmallIcon&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;drawable&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;ic_icon&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setContentTitle&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setContentText&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ssb&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setOngoing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRequestPromotedOngoing&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;

  

&lt;h3 id=&quot;dl-tdoa-api-android-17&quot; tabindex=&quot;-1&quot;&gt;适用于 Android 17 的 UWB 下行链路 TDoA API&lt;/h3&gt;

通过下行链路到达时间差 (DL-TDoA) 测距，设备可以通过测量信号的相对到达时间来确定其相对于多个锚点的位置。&lt;p&gt;&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 如需使用 DL-TDoA 测距，调用应用必须请求并获得位置信息权限（例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Manifest.permission.ACCESS_FINE_LOCATION&lt;/code&gt; 和 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Manifest.permission.ACCESS_BACKGROUND_LOCATION&lt;/code&gt;，如果需要在应用处于后台状态时进行测距）。如需详细了解如何请求位置权限，请参阅&lt;a href=&quot;https://developer.android.com/develop/sensors-and-location/location/permissions?hl=zh-cn&quot;&gt;请求位置权限&lt;/a&gt;。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;以下代码段演示了如何初始化 [测距管理器][ranging-manager-ref]、验证设备功能并启动 DL-TDoA 会话：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;kotlin&quot; tabindex=&quot;-1&quot;&gt;Kotlin&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;RangingApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;initDlTdoa&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Initialize the Ranging Manager&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Register for device capabilities&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;capabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;RangingCapabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;override&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;onRangingCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Make sure Dl-TDoA is supported before starting the session&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;uwbCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;uwbCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!!&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;isDlTdoaSupported&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;startDlTDoASession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;registerCapabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executors&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;startDlTDoASession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Initialize the Ranging Manager&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create session and configure parameters&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executors&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createRangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingSessionCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;byteArrayOf&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;ByteArray&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;byteArrayOf&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// OOB config data&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createFromFiraConfigPacket&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;rawTagDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawRangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setDlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;dtTagConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawDtTagRangingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rawTagDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;preference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingPreference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DEVICE_ROLE_DT_TAG&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;dtTagConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSessionConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SessionConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Start the ranging session&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;preference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-kd&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nc&quot;&gt;RangingSessionCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;override&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;onDlTdoaResults&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;measurement&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaMeasurement&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Process measurement results here&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;RangingApp&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;initDlTdoa&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Initialize the Ranging Manager&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Register for device capabilities&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;CapabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;RangingCapabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nd&quot;&gt;@Override&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;onRangingCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Make sure Dl-TDoA is supported before starting the session&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getUwbCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getUwbCapabilities&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;isDlTdoaSupported&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;startDlTDoASession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;registerCapabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executors&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;capabilitiesCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;startDlTDoASession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Create session and configure parameters&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Executors&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingManager&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createRangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;executor&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingSessionCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// OOB config data&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;createFromFiraConfigPacket&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawRangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rawTagDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawRangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setDlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawDtTagRangingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;dtTagConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RawDtTagRangingConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rawTagDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingPreference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;preference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingPreference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DEVICE_ROLE_DT_TAG&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;dtTagConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSessionConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;SessionConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Start the ranging session&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;rangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;preference&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;devsite-syntax-nc&quot;&gt;RangingSessionCallback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;implements&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingSession&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nd&quot;&gt;@Override&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nf&quot;&gt;onDlTdoaResults&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;RangingDevice&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaMeasurement&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;measurement&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Process measurement results here&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;h3 id=&quot;oob-configurations&quot; tabindex=&quot;-1&quot;&gt;带外 (OOB) 配置&lt;/h3&gt;

&lt;p&gt;以下代码段提供了 Wi-Fi 和 BLE 的 DL-TDoA OOB 配置数据示例：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;java_1&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Wifi Configuration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;wifiConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xDD&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x2D&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x5A&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x18&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xFF&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Header&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x5F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x19&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// FiRa Sub-Element&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Profile ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x06&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// MAC Address&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x14&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x0C&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Preamble Index&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x27&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x07&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Vendor ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x28&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x06&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xCA&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xC8&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xA6&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xF7&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x6F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Static STS IV&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x60&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x09&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Slot Duration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x1B&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x0A&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Slots per RR&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x09&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xE8&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x03&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Duration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x9F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x67&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x45&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x23&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Session ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// BLE Configuration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;bleConfig&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x2D&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x16&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xF4&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xFF&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Header&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x5F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x19&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// FiRa Sub-Element&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Profile ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x06&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// MAC Address&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x14&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x0C&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Preamble Index&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x27&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x07&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Vendor ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x28&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x06&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xCA&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xC8&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xA6&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xF7&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x6F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Static STS IV&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x08&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x60&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x09&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Slot Duration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x1B&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x0A&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Slots per RR&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x09&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0xE8&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x03&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Duration&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x9F&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x67&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x45&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x23&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;devsite-syntax-c1&quot;&gt;// Session ID&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p&gt;如果您无法使用 OOB 配置（因为该配置缺失），或者需要更改不在 OOB 配置中的默认值，则可以使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DlTdoaRangingParams.Builder&lt;/code&gt; 构建参数，如以下代码段所示。您可以使用这些参数来代替 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;DlTdoaRangingParams.createFromFiraConfigPacket()&lt;/code&gt;：&lt;/p&gt;
&lt;div&gt;&lt;devsite-selector&gt;
&lt;section&gt;&lt;h3 id=&quot;kotlin_1&quot; tabindex=&quot;-1&quot;&gt;Kotlin&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;dlTdoaParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setComplexChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;UwbComplexChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setPreambleIndex&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setDeviceAddress&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;deviceAddress&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSessionKeyInfo&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;byteArrayOf&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x03&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingIntervalMillis&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSlotDuration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;UwbRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;DURATION_2_MS&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSlotsPerRangingRound&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;byteArrayOf&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;x05&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;section&gt;&lt;h3 id=&quot;java_2&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;dlTdoaParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;DlTdoaRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setComplexChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;UwbComplexChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setChannel&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setPreambleIndex&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setDeviceAddress&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;deviceAddress&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSessionKeyInfo&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x02&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x03&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x04&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingIntervalMillis&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSlotDuration&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;UwbRangingParams&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;DURATION_2_MS&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setSlotsPerRangingRound&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setRangingRoundIndexes&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x01&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-mh&quot;&gt;0x05&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;&lt;/section&gt;
&lt;/devsite-selector&gt;&lt;/div&gt;
&lt;p id=&quot;ranging-manager&quot;&gt;[ranging-manager-ref]：/reference/android/ranging/RangingManager&lt;/p&gt;

  

  
  

  
&lt;/div&gt;

  
    
      &lt;devsite-recommendations display=&quot;in-page&quot; hidden yield&gt;
      &lt;/devsite-recommendations&gt;
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
    
    
      &lt;devsite-recommendations id=&quot;recommendations-link&quot; yield&gt;&lt;/devsite-recommendations&gt;
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:06:00 +0800</pubDate></item><item><title>全文转载：Android 17 行为变更：以 Android 17 或更高版本为目标平台的应用</title><link>https://suwenclub.cn/?id=37</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Android 17 行为变更：以 Android 17 或更高版本为目标平台的应用&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Android Developers / Android Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/license?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Android Developers Content License&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Android Developers 官方中文文档，页面内容和代码示例受 Android Developers 内容许可约束。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;&lt;/p&gt;



&lt;p&gt;与之前的版本一样，Android 17 包含一些可能会影响应用的行为变更。以下行为变更仅影响以 Android 17 或更高版本为目标平台的应用。如果您的应用以 Android 17 或更高版本为目标平台，则应根据情况修改应用，以支持这些行为。&lt;/p&gt;

&lt;p&gt;无论应用的 &lt;a href=&quot;https://developer.android.com/guide/topics/manifest/uses-sdk-element?hl=zh-cn#target&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;targetSdkVersion&lt;/code&gt;&lt;/a&gt; 为何，都请务必查看&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn&quot;&gt;对 Android 17 上运行的所有应用都有影响的行为变更&lt;/a&gt;列表。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 本页列出了一些比较重要的变更。如需了解更多详细信息，请参阅 &lt;a href=&quot;https://developer.android.com/about/versions/17/release-notes?hl=zh-cn&quot;&gt;Android 17 版本说明&lt;/a&gt;。&lt;/span&gt;&lt;/aside&gt;
&lt;h2 id=&quot;core&quot; tabindex=&quot;-1&quot;&gt;核心功能&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，这些变更会修改或扩展 Android 系统的各种核心功能。&lt;/p&gt;

&lt;h3 id=&quot;lock-free-messagequeue&quot; tabindex=&quot;-1&quot;&gt;MessageQueue 的新无锁实现&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，以 Android 17（API 级别 37）
或更高版本为目标平台的应用会收到
&lt;a href=&quot;https://developer.android.com/reference/android/os/MessageQueue?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;android.os.MessageQueue&lt;/code&gt;&lt;/a&gt; 的新无锁实现。新实现可提升性能并减少丢帧，但可能会破坏反映 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;MessageQueue&lt;/code&gt; 私有字段和方法的客户端。&lt;/p&gt;

&lt;p&gt;如需了解详情（包括缓解措施），请参阅 &lt;a href=&quot;https://developer.android.com/about/versions/17/changes/messagequeue?hl=zh-cn&quot;&gt;MessageQueue 行为变更指南&lt;/a&gt;。&lt;/p&gt;

  

&lt;h3 id=&quot;static-final-fields&quot; tabindex=&quot;-1&quot;&gt;静态 final 字段现在不可修改&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;在以 Android 17（API 级别 37）或更高版本为目标平台的 Android 17 或更高版本上运行的应用无法更改 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;static final&lt;/code&gt; 字段。如果应用尝试使用反射更改 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;static final&lt;/code&gt; 字段，则会导致 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;IllegalAccessException&lt;/code&gt;。尝试通过 JNI API（例如 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;SetStaticLongField()&lt;/code&gt;）修改其中一个字段会导致应用崩溃。&lt;/p&gt;

  

&lt;h2 id=&quot;accessibility&quot; tabindex=&quot;-1&quot;&gt;无障碍&lt;/h2&gt;

&lt;p&gt;Android 17 进行了以下变更，以改进无障碍功能。&lt;/p&gt;

&lt;h3 id=&quot;a11y-ime-pk&quot; tabindex=&quot;-1&quot;&gt;复杂 IME 实体键盘输入的无障碍支持&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;此功能引入了新的 &lt;a href=&quot;https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AccessibilityEvent&lt;/code&gt;&lt;/a&gt; 和 &lt;a href=&quot;https://developer.android.com/reference/android/view/inputmethod/TextAttribute?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextAttribute&lt;/code&gt;&lt;/a&gt; API，以增强屏幕阅读器针对 CJKV 语言输入的语音反馈。CJKV IME 应用现在可以指示在文本撰写期间是否已选择文本转换候选内容。具有编辑字段的应用可以在发送文本更改无障碍事件时指定&lt;em&gt;文本更改类型&lt;/em&gt;。例如，应用可以指定在文本撰写期间发生了文本更改，或者文本更改是由提交导致的。这样做可让屏幕阅读器等无障碍服务根据文本修改的性质提供更精确的反馈。&lt;/p&gt;

&lt;h4 id=&quot;app_adoption&quot; tabindex=&quot;-1&quot;&gt;应用采用量&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IME 应用&lt;/strong&gt;：在编辑字段中设置正在撰写的文本时，IME 可以使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextAttribute.Builder.setTextSuggestionSelected()&lt;/code&gt; 来指明是否选择了特定的转换候选对象。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;具有“编辑字段”权限的应用&lt;/strong&gt;：维护自定义 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;InputConnection&lt;/code&gt; 的应用可以通过调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextAttribute.isTextSuggestionSelected()&lt;/code&gt; 来检索候选选择数据。然后，这些应用在调度 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TYPE_VIEW_TEXT_CHANGED&lt;/code&gt; 事件时应调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AccessibilityEvent.setTextChangeTypes()&lt;/code&gt;。如果应用以 Android 17（API 级别 37）为目标平台，并使用标准 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextView&lt;/code&gt;，则默认启用此功能。（也就是说，&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TextView&lt;/code&gt; 将负责从 IME 检索数据，并在向无障碍服务发送事件时设置文本更改类型）。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;无障碍服务&lt;/strong&gt;：处理 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TYPE_VIEW_TEXT_CHANGED&lt;/code&gt; 事件的无障碍服务可以调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AccessibilityEvent.getTextChangeTypes()&lt;/code&gt; 来识别修改的性质，并相应地调整其反馈策略。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

  

&lt;h2 id=&quot;privacy&quot; tabindex=&quot;-1&quot;&gt;隐私权&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，旨在提升用户隐私保护。&lt;/p&gt;

&lt;h3 id=&quot;ech-by-default&quot; tabindex=&quot;-1&quot;&gt;已启用 ECH（加密客户端 Hello）&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 引入了对加密客户端问候 (ECH) 的平台支持。ECH 是一种 TLS 扩展，可通过加密 TLS 握手中的服务器名称指示
(SNI) 来增强用户隐私保护。这种加密有助于防止网络观察者轻松识别您的应用所连接的特定网域。&lt;/p&gt;

&lt;p&gt;对于以 Android 17（API 级别 37）或更高版本为目标平台的应用，ECH 用于 TLS 连接。只有当应用使用的网络库（例如
HttpEngine、WebView 或 OkHttp）已集成 ECH 支持，并且远程服务器也支持 ECH 协议时，ECH 才会处于活跃状态。如果无法协商
ECH，客户端会发送一个包含随机内容的 ECH 扩展（一种称为 ECH GREASE 的机制）。如需详细了解 ECH GREASE 的工作原理，请参阅 &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc9849.html#name-grease-ech&quot;&gt;RFC 9849&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;为了让应用能够自定义此行为，Android 17 向网络安全配置文件添加了一个新的
&lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#domainEncryption&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;lt;domainEncryption&amp;gt;&lt;/code&gt;&lt;/a&gt; 元素。
开发者可以在 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;lt;base-config&amp;gt;&lt;/code&gt; 或
&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;lt;domain-config&amp;gt;&lt;/code&gt; 标记中使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;lt;domainEncryption&amp;gt;&lt;/code&gt;，以全局或按网域的方式选择 ECH 模式（例如
&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;quot;enabled&amp;quot;&lt;/code&gt; 或 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;quot;disabled&amp;quot;&lt;/code&gt;）。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#EncryptedClientHelloSummary&quot;&gt;加密客户端问候&lt;/a&gt;文档。&lt;/p&gt;

  

&lt;h3 id=&quot;local-network-protection-permission&quot; tabindex=&quot;-1&quot;&gt;以 Android 17 为目标平台的应用需要本地网络权限&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 引入了 &lt;a href=&quot;https://developer.android.com/reference/android/Manifest.permission?hl=zh-cn#ACCESS_LOCAL_NETWORK&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACCESS_LOCAL_NETWORK&lt;/code&gt;&lt;/a&gt; 运行时权限，以保护用户免遭未经授权的本地网络访问。由于此权限属于现有的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;NEARBY_DEVICES&lt;/code&gt; 权限组，因此系统不会再次提示已授予其他 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;NEARBY_DEVICES&lt;/code&gt; 权限的用户。这项新要求可防止恶意应用利用不受限制的本地网络访问权限进行隐秘的用户跟踪和指纹识别。通过声明和请求此权限，您的应用可以发现并连接到局域网 (LAN) 中的设备，例如智能家居设备或投屏接收器。&lt;/p&gt;

&lt;p&gt;以 Android 17（API 级别 37）或更高版本为目标平台的应用现在可以通过两种方式与 LAN 设备保持通信：采用系统介导的、可保护隐私的设备选择器来跳过权限提示，或者在运行时明确请求此新权限以保持本地网络通信。&lt;/p&gt;

&lt;p&gt;如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/privacy-and-security/local-network-permission?hl=zh-cn&quot;&gt;本地网络权限&lt;/a&gt;文档。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 在 Android 16 中，应用可以选择启用本地网络权限。
自 Android 17 起，以 Android 17（API 级别 37）或更高版本为目标平台的应用必须强制执行此项检查。&lt;/span&gt;&lt;/aside&gt;

  

&lt;h3 id=&quot;hide-pwd-kbd&quot; tabindex=&quot;-1&quot;&gt;在实体设备上隐藏密码&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;如果应用以 Android 17（API 级别 37）或更高版本为目标平台，并且用户使用的是实体输入设备（例如外接键盘），Android
操作系统会对密码字段中的所有字符应用新的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;show_passwords_physical&lt;/code&gt; 设置。默认情况下，该设置会隐藏所有密码字符。&lt;/p&gt;

&lt;p&gt;Android 系统会显示用户最后输入的密码字符，以帮助用户查看是否输错了密码。不过，对于较大的外接键盘，此功能就没那么必要了。此外，配备外接键盘的设备通常具有较大的显示屏，这会增加他人看到输入密码的风险。&lt;/p&gt;

&lt;p&gt;如果用户使用的是设备触摸屏，系统会应用新的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;show_passwords_touch&lt;/code&gt; 设置。&lt;/p&gt;

  

&lt;h3 id=&quot;sms-otp-protection&quot; tabindex=&quot;-1&quot;&gt;针对标准短信的 OTP 保护&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，Android 将扩展其短信验证码保护功能，以适用于标准短信（包含验证码但不使用 WebOTP 或 SMS Retriever 格式的短信）。对于以 Android 17（API 级别 37）或更高版本为目标平台的应用，这些短信在收到后三小时内不会提供。此延迟旨在帮助防止动态密码劫持。在这三小时的延迟期间，系统会保留
&lt;a href=&quot;https://developer.android.com/reference/android/provider/Telephony.Sms.Intents?hl=zh-cn#SMS_RECEIVED_ACTION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;SMS_RECEIVED_ACTION&lt;/code&gt;&lt;/a&gt;广播，并过滤
&lt;a href=&quot;https://developer.android.com/reference/android/provider/Telephony.Sms?hl=zh-cn&quot;&gt;短信提供商&lt;/a&gt;数据库查询。延迟结束后，这些应用即可使用短信。&lt;/p&gt;

&lt;p&gt;某些应用（例如默认短信助理应用、已连接的设备配套应用等）不受此延迟限制。所有依赖于读取短信
来提取动态密码的应用都应改用 &lt;a href=&quot;https://developer.android.com/identity/sms-retriever?hl=zh-cn&quot;&gt;SMS Retriever&lt;/a&gt; 或 &lt;a href=&quot;https://developers.google.com/identity/sms-retriever/user-consent/overview?hl=zh-cn&quot;&gt;SMS
User Consent&lt;/a&gt; API，以确保功能持续可用。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 针对 WebOTP 和 SMS Retriever 格式的
消息的其他短信动态密码保护措施适用于所有应用，无论其目标 API 级别如何。如需了解详情，请参阅&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn#sms-otp-all-apps&quot;&gt;短信动态密码保护&lt;/a&gt;在&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn&quot;&gt;针对所有
应用的行为变更&lt;/a&gt;文档中。&lt;/span&gt;&lt;/aside&gt;

&lt;h2 id=&quot;security&quot; tabindex=&quot;-1&quot;&gt;安全&lt;/h2&gt;

&lt;p&gt;Android 17 对设备和应用安全性进行了以下改进。&lt;/p&gt;

&lt;h3 id=&quot;activity-security&quot; tabindex=&quot;-1&quot;&gt;活动安全性&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;在 Android 17 中，平台继续向“默认安全”架构转变，引入了一系列旨在缓解网络钓鱼、互动劫持和混淆代理攻击等高严重性漏洞的增强功能。此更新要求开发者明确选择启用新的安全标准，以保持应用兼容性和用户保护。&lt;/p&gt;

&lt;p&gt;对开发者的主要影响包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;BAL 安全加固和改进的选择启用&lt;/strong&gt;： 我们正在优化后台活动启动 (BAL) 限制，方法是将保护范围扩展到 &lt;a href=&quot;https://developer.android.com/reference/android/content/IntentSender?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;IntentSender&lt;/code&gt;&lt;/a&gt;。开发者必须从旧版
&lt;a href=&quot;https://developer.android.com/reference/android/app/ActivityOptions?hl=zh-cn#MODE_BACKGROUND_ACTIVITY_START_ALLOWED&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;MODE_BACKGROUND_ACTIVITY_START_ALLOWED&lt;/code&gt;&lt;/a&gt; 常量迁移。相反，您应
采用精细控制，例如
&lt;a href=&quot;https://developer.android.com/reference/android/app/ActivityOptions?hl=zh-cn#MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE&lt;/code&gt;&lt;/a&gt;，它将
活动启动限制为调用应用可见的场景，从而显著
缩小攻击面。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;采用工具&lt;/strong&gt;： 开发者应利用严格模式和更新后的 lint 检查来识别旧版模式，并确保为未来的目标 SDK 要求做好准备。&lt;/li&gt;
&lt;/ul&gt;

  

&lt;h3 id=&quot;ct-default&quot; tabindex=&quot;-1&quot;&gt;默认启用 CT&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;如果应用以 Android 17（API 级别 37）或更高版本为目标平台，则默认启用&lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#CertificateTransparencySummary&quot;&gt;证书透明度 (CT)&lt;/a&gt;。（在 Android 16 上，CT 可用，但应用必须&lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn#certificateTransparency&quot;&gt;选择启用&lt;/a&gt;。）&lt;/p&gt;

  

&lt;h3 id=&quot;safer-dcl&quot; tabindex=&quot;-1&quot;&gt;更安全的原生 DCL - C&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;如果您的应用以 Android 17（API 级别 37）或更高版本为目标平台，则 Android 14 中针对 DEX 和 JAR 文件引入的更安全的动态代码加载 (DCL) 保护功能现在也适用于原生库。&lt;/p&gt;

&lt;p&gt;使用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;System.load()&lt;/code&gt; 加载的所有原生文件都必须标记为只读。否则，系统会抛出 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;UnsatisfiedLinkError&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;我们建议应用尽可能避免动态加载代码，因为这样做会大大增加应用因代码注入或代码篡改而遭到入侵的风险。&lt;/p&gt;

  

&lt;h3 id=&quot;restrict-pii-fields-cp2-data-view&quot; tabindex=&quot;-1&quot;&gt;限制 CP2 数据视图中的 PII 字段&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;对于以 Android 17（API 级别 Android 17（API 级别 37））及更高版本为目标平台的应用，联系人提供程序 2 (CP2)
会限制数据视图中包含某些个人身份信息 (PII) 的列。启用此变更后，这些列将从数据视图中移除，以增强用户隐私保护。
受限列包括：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.SyncColumns?hl=zh-cn#ACCOUNT_NAME&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACCOUNT_NAME&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.SyncColumns?hl=zh-cn#ACCOUNT_TYPE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACCOUNT_TYPE&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.RawContactsColumns?hl=zh-cn#ACCOUNT_TYPE_AND_DATA_SET&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACCOUNT_TYPE_AND_DATA_SET&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如果应用正在使用 &lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.Data?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ContactsContract.Data&lt;/code&gt;&lt;/a&gt;
 中的这些列，则可以通过与 &lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.DataColumns?hl=zh-cn#RAW_CONTACT_ID&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;RAW_CONTACT_ID&lt;/code&gt;&lt;/a&gt; 联接，改为从 &lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.RawContacts?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ContactsContract.RawContacts&lt;/code&gt;&lt;/a&gt;
 中提取这些列。&lt;/p&gt;

  

&lt;h3 id=&quot;enforce-strict-sql-checks&quot; tabindex=&quot;-1&quot;&gt;在 CP2 中强制执行严格的 SQL 检查&lt;/h3&gt;

























































































































 





























 














&lt;p&gt;For apps targeting Android 17 (API level Android&amp;nbsp;17 (API level&amp;nbsp;37)) and
higher, Contacts Provider 2 (CP2) enforces strict SQL query validation when
the &lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.Data?hl=zh-cn&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;ContactsContract.Data&lt;/code&gt;&lt;/a&gt; table is accessed without
&lt;a href=&quot;https://developer.android.com/reference/android/Manifest.permission?hl=zh-cn#READ_CONTACTS&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;READ_CONTACTS&lt;/code&gt;&lt;/a&gt; permission.&lt;/p&gt;

&lt;p&gt;With this change, if an app doesn&amp;#39;t have &lt;a href=&quot;https://developer.android.com/reference/android/Manifest.permission?hl=zh-cn#READ_CONTACTS&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;READ_CONTACTS&lt;/code&gt;&lt;/a&gt;
permission, &lt;a href=&quot;https://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder?hl=zh-cn#setStrictColumns(boolean)&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;StrictColumns&lt;/code&gt;&lt;/a&gt; and
&lt;a href=&quot;https://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder?hl=zh-cn#setStrictGrammar(boolean)&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;StrictGrammar&lt;/code&gt;&lt;/a&gt; options are set when querying
the &lt;a href=&quot;https://developer.android.com/reference/android/provider/ContactsContract.Data?hl=zh-cn&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;ContactsContract.Data&lt;/code&gt;&lt;/a&gt; table. If a query
uses a pattern that isn&amp;#39;t compatible with these, it will be
rejected and cause an exception to be thrown.&lt;/p&gt;

&lt;h2 id=&quot;media&quot; tabindex=&quot;-1&quot;&gt;媒体&lt;/h2&gt;

&lt;p&gt;Android 17 针对媒体行为做了以下更改。&lt;/p&gt;

&lt;h3 id=&quot;bg-audio&quot; tabindex=&quot;-1&quot;&gt;后台音频安全加固&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，音频框架对后台音频互动（包括音频播放、音频焦点请求和音量更改 API）强制执行限制，以确保这些更改是由用户有意启动的。&lt;/p&gt;

&lt;p&gt;部分音频限制适用于所有应用。不过，如果应用以 Android 17（API 级别 37）为目标平台，则限制会更加严格。如果这些应用在后台运行时与音频互动，则必须有前台服务正在运行。此外，应用还必须满足以下一项或两项要求：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;前台服务必须具有仅在使用时授予的权限 (WIU)。&lt;/li&gt;
&lt;li&gt;应用必须具有&lt;a href=&quot;https://developer.android.com/develop/background-work/services/alarms?hl=zh-cn#exact&quot;&gt;精确闹钟&lt;/a&gt;权限，并且正在与 &lt;a href=&quot;https://developer.android.com/reference/android/media/AudioAttributes?hl=zh-cn#USAGE_ALARM&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;USAGE_ALARM&lt;/code&gt;&lt;/a&gt; 音频流互动。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如需了解详情（包括缓解措施），请参阅&lt;a href=&quot;https://developer.android.com/about/versions/17/changes/bg-audio?hl=zh-cn&quot;&gt;后台音频安全加固&lt;/a&gt;。&lt;/p&gt;

  

&lt;h2 id=&quot;device-form-factors&quot; tabindex=&quot;-1&quot;&gt;设备规格&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，可改善各种尺寸和外形规格的设备上的用户体验。&lt;/p&gt;

&lt;h3 id=&quot;large-screen-ignore-constraints&quot; tabindex=&quot;-1&quot;&gt;平台 API 变更，用于忽略大屏设备 (sw&amp;gt;=600dp) 上的屏幕方向、尺寸调整能力和宽高比限制&lt;/h3&gt;

























































































































 





























 














&lt;p&gt;We introduced Platform API changes in Android&amp;nbsp;16 to &lt;a href=&quot;https://developer.android.com/about/versions/16/behavior-changes-16?hl=zh-cn#ignore-orientation&quot;&gt;ignore orientation,
aspect ratio, and resizability restrictions on large screens (sw &amp;gt;=
600dp)&lt;/a&gt; for apps targeting API level
36 or higher. Developers have the option to opt out of these
changes with SDK 36, but this opt-out will no longer be
available for apps that target Android&amp;nbsp;17 (API level&amp;nbsp;37) or higher.&lt;/p&gt;

&lt;p&gt;For more information, see &lt;a href=&quot;https://developer.android.com/about/versions/17/changes/ff-restrictions-ignored?hl=zh-cn&quot;&gt;Restrictions on orientation and resizability are
ignored&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;connectivity&quot; tabindex=&quot;-1&quot;&gt;连接&lt;/h2&gt;

&lt;p&gt;Android 17 引入了以下变更，以提高一致性并与蓝牙 RFCOMM 套接字的标准 Java &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;InputStream&lt;/code&gt; 行为保持一致。&lt;/p&gt;

&lt;h3 id=&quot;bluetooth-rfcomm-socket-change&quot; tabindex=&quot;-1&quot;&gt;针对 RFCOMM 的一致 BluetoothSocket read() 行为&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;对于以 Android 17（API 级别 37）为目标平台的应用，
&lt;a href=&quot;https://developer.android.com/reference/java/io/InputStream?hl=zh-cn#read(byte%5B%5D)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;read()&lt;/code&gt;&lt;/a&gt; 方法从&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;InputStream&lt;/code&gt; 获取的
基于 RFCOMM 的 &lt;a href=&quot;https://developer.android.com/reference/android/bluetooth/BluetoothSocket?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;BluetoothSocket&lt;/code&gt;&lt;/a&gt; 现在会在
套接字关闭或连接断开时返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;-1&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;此更改使 RFCOMM 套接字行为与 LE CoC 套接字保持一致，并与标准 &lt;a href=&quot;https://developer.android.com/reference/java/io/InputStream?hl=zh-cn#read(byte%5B%5D)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;InputStream.read()&lt;/code&gt;&lt;/a&gt;
文档保持一致，该文档指出，当到达流的末尾时，系统会返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;-1&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;仅依赖于捕获 IOException 以跳出读取循环的应用可能会受到此更改的影响，并且应更新 BluetoothSocket 读取循环以明确检查返回值 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;-1&lt;/code&gt;。这可确保在远程设备断开连接或套接字关闭时，循环正确终止。&lt;a href=&quot;https://developer.android.com/develop/connectivity/bluetooth/transfer-data?hl=zh-cn&quot;&gt;&lt;a href=&quot;https://developer.android.com/develop/connectivity/bluetooth/transfer-data?hl=zh-cn#example&quot;&gt;如需查看推荐的实现示例，请参阅传输蓝牙数据指南中的代码段。&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

  

  
  

  
&lt;/div&gt;

  
    
      &lt;devsite-recommendations display=&quot;in-page&quot; hidden yield&gt;
      &lt;/devsite-recommendations&gt;
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
    
    
      &lt;devsite-recommendations id=&quot;recommendations-link&quot; yield&gt;&lt;/devsite-recommendations&gt;
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:03:00 +0800</pubDate></item><item><title>全文转载：Android 17 行为变更：所有应用</title><link>https://suwenclub.cn/?id=36</link><description>&lt;p&gt;&lt;strong&gt;原文标题：&lt;/strong&gt;Android 17 行为变更：所有应用&lt;/p&gt;&lt;p&gt;&lt;strong&gt;作者/来源：&lt;/strong&gt;Android Developers / Android Developers&lt;/p&gt;&lt;p&gt;&lt;strong&gt;原文链接：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://developer.android.com/about/versions/17/behavior-changes-all?hl=zh-cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;许可证/授权：&lt;/strong&gt;&lt;a href=&quot;https://developer.android.com/license?hl=zh-cn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Android Developers Content License&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;转载声明：&lt;/strong&gt;本文完整转载自 Android Developers 官方中文文档，页面内容和代码示例受 Android Developers 内容许可约束。 本站转载仅用于技术学习与资料归档，已注明作者/来源与原文链接。如有侵权或不希望转载，请联系删除。&lt;/p&gt;&lt;!--more--&gt;&lt;p&gt;&lt;/p&gt;



&lt;p&gt;Android 17 平台包含一些可能会影响您的应用的行为变更。以下行为变更将影响在 Android 17 上运行的&lt;em&gt;&lt;/em&gt;所有应用，无论采用哪种 &lt;a href=&quot;https://developer.android.com/guide/topics/manifest/uses-sdk-element?hl=zh-cn#target&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;targetSdkVersion&lt;/code&gt;&lt;/a&gt; 都不例外。您应该测试您的应用，然后根据需要酌情修改，以便支持这些变更。&lt;/p&gt;

&lt;p&gt;此外，请务必查看&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn&quot;&gt;仅影响以 Android 17 为目标平台的应用的行为变更&lt;/a&gt;列表。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 本页列出了一些比较重要的变更。如需了解更多详细信息，请参阅 &lt;a href=&quot;https://developer.android.com/about/versions/17/release-notes?hl=zh-cn&quot;&gt;Android 17 版本说明&lt;/a&gt;。&lt;/span&gt;&lt;/aside&gt;
&lt;h2 id=&quot;core&quot; tabindex=&quot;-1&quot;&gt;核心功能&lt;/h2&gt;

&lt;p&gt;Android 17（API 级别 37）包含以下变更，这些变更会修改或扩展 Android 系统的各种核心功能。&lt;/p&gt;

&lt;h3 id=&quot;app-memory-limits&quot; tabindex=&quot;-1&quot;&gt;应用内存限制&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 引入了基于设备总 RAM 的应用内存限制，以便为您的应用和 Android 用户打造更稳定、更确定的环境。在 Android 17 中，系统会保守地设置限制，以建立系统基准，在极端内存泄漏和其他异常情况导致系统范围内的不稳定（导致界面卡顿、耗电过快和应用被终止）之前，针对这些情况采取措施。虽然我们预计此变化对绝大多数应用会话的影响微乎其微，但我们建议您遵循&lt;a href=&quot;https://developer.android.com/topic/performance/memory?hl=zh-cn&quot;&gt;以下内存最佳实践&lt;/a&gt;，包括建立内存基准。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;span&gt; 内存限制仅适用于部分 Android 设备。&lt;/span&gt;&lt;/aside&gt;
&lt;p&gt;您可以通过在 &lt;a href=&quot;https://developer.android.com/reference/android/app/ApplicationExitInfo?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ApplicationExitInfo&lt;/code&gt;&lt;/a&gt; 中调用 &lt;a href=&quot;https://developer.android.com/reference/android/app/ApplicationExitInfo?hl=zh-cn#getDescription()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getDescription&lt;/code&gt;&lt;/a&gt; 来确定应用会话是否受到影响；如果应用受到影响，退出原因将为 &lt;a href=&quot;https://developer.android.com/reference/android/app/ApplicationExitInfo?hl=zh-cn#REASON_OTHER&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;REASON_OTHER&lt;/code&gt;&lt;/a&gt;，说明将包含字符串 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;&amp;quot;MemoryLimiter:AnonSwap&amp;quot;&lt;/code&gt; 以及其他信息。您还可以将 &lt;a href=&quot;https://developer.android.com/about/versions/17/features?hl=zh-cn#anomaly-profiling-trigger&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;TRIGGER_TYPE_ANOMALY&lt;/code&gt;&lt;/a&gt; 与&lt;a href=&quot;https://developer.android.com/topic/performance/tracing/profiling-manager/trigger-based-capture?hl=zh-cn&quot;&gt;基于触发器的分析&lt;/a&gt;搭配使用，以获取在达到内存限制时收集的堆转储。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://developer.android.com/topic/performance/memory?hl=zh-cn&quot;&gt;管理应用的内存&lt;/a&gt;文档提供的信息可帮助您诊断应用的内存问题并优化其资源消耗。&lt;/p&gt;

&lt;h4 id=&quot;mem-limit-test&quot; tabindex=&quot;-1&quot;&gt;在内存受限的情况下测试应用的运行情况&lt;/h4&gt;

&lt;p&gt;您可以使用 &lt;a href=&quot;https://developer.android.com/tools/adb?hl=zh-cn&quot;&gt;Android 调试桥 (&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;adb&lt;/code&gt;)&lt;/a&gt; 调整或停用任何施加内存限制的设备上的内存限制。shell 命令 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am&lt;/code&gt; 提供了三个用于调整内存限制的子命令。（这些命令对未施加内存限制的设备没有影响。）&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am memory-limiter ignore &amp;lt;uid&amp;gt;|none|all&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am memory-limiter manual &amp;lt;pid&amp;gt; &amp;lt;limit&amp;gt;|max|none&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am memory-limiter status&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;dl&gt;
&lt;dt&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ignore&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;指示内存限制器忽略部分或全部进程。传递 &lt;a href=&quot;https://developer.android.com/tools/dumpsys?hl=zh-cn#uid_stats&quot;&gt;UID（Android 用户 ID）&lt;/a&gt;会指示内存限制器忽略对与该 UID 相关联的所有进程的强制执行。您还可以传递 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;all&lt;/code&gt;（忽略所有应用）或 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;none&lt;/code&gt;（不忽略任何应用）。传递 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;none&lt;/code&gt; 会替换之前对 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am memory-limiter ignore&lt;/code&gt; 的任何调用。&lt;/p&gt;&lt;/dd&gt;
&lt;dd&gt;&lt;p&gt;如果您指示内存限制器忽略某个 UID，您仍然可以通过调用 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;am memory-limiter manual&lt;/code&gt; 为应用内的进程应用手动内存限制。&lt;/p&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;manual&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;指示系统对具有指定 PID（进程 ID）的进程施加内存限制。内存限制以整数形式的 MB 数指定；例如，传递 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;30&lt;/code&gt; 指定进程的内存限制为 30 MB。传递 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;max&lt;/code&gt; 会移除相应进程的所有内存限制。
传递 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;none&lt;/code&gt; 会移除对进程设置的所有手动限制，从而恢复系统的默认限制（如果有）。&lt;/p&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;status&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;报告内存限制器的当前状态。该状态包括对可见进程和非可见进程施加的内存限制。&lt;/p&gt;&lt;/dd&gt;
&lt;/dl&gt;

  

&lt;h2 id=&quot;privacy&quot; tabindex=&quot;-1&quot;&gt;隐私权&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，旨在提升用户隐私保护。&lt;/p&gt;

&lt;h3 id=&quot;sms-otp-all-apps&quot; tabindex=&quot;-1&quot;&gt;动态短信密码保护&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，Android 将扩大对包含一次性密码 (OTP) 的短信的保护范围。&lt;/p&gt;

&lt;p&gt;在之前的 Android 版本中，此保护主要侧重于 SMS Retriever 格式。对于大多数应用，包含 SMS Retriever 哈希的消息的递送延迟了 3
小时。不过，某些应用（例如默认短信处理程序）不受此延迟的影响，拥有哈希的应用也不受此延迟的影响。&lt;/p&gt;

&lt;p&gt;从 Android 17 开始，此保护也适用于 WebOTP 格式的消息。如果应用有权读取短信，但不是 WebOTP
消息的预期接收者（由网域验证确定），则该应用在收到消息后 3 小时内无法访问该消息。此变更旨在提高用户安全性，确保只有与消息中提及的网域关联的应用才能以编程方式读取验证码。&lt;/p&gt;

&lt;p&gt;在这 3 小时的延迟期间，系统会保留 &lt;a href=&quot;https://developer.android.com/reference/android/provider/Telephony.Sms.Intents?hl=zh-cn#SMS_RECEIVED_ACTION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;SMS_RECEIVED_ACTION&lt;/code&gt;&lt;/a&gt; 广播，并过滤 &lt;a href=&quot;https://developer.android.com/reference/android/provider/Telephony.Sms?hl=zh-cn&quot;&gt;短信提供商&lt;/a&gt; 数据库查询。延迟结束后，这些应用即可使用短信。此变更适用于
&lt;strong&gt;所有应用&lt;/strong&gt;，无论其目标 API 级别如何。&lt;/p&gt;

&lt;p&gt;某些应用（例如默认短信助理应用、关联设备配套应用等）不受此延迟的影响。所有依赖于读取短信
来提取 OTP 的应用都应过渡到使用 &lt;a href=&quot;https://developer.android.com/identity/sms-retriever?hl=zh-cn&quot;&gt;SMS Retriever&lt;/a&gt; 或 &lt;a href=&quot;https://developers.google.com/identity/sms-retriever/user-consent/overview?hl=zh-cn&quot;&gt;SMS
User Consent&lt;/a&gt; API，以确保功能持续可用。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;注意&lt;/strong&gt;&lt;span&gt; ：如果您的应用以 Android 17（API 级别 37）或更高版本为目标平台，此
保护也会扩展到标准短信。如需了解详情，请参阅
&lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn#sms-otp-protection&quot;&gt;标准短信的 OTP 保护&lt;/a&gt;在 &lt;a href=&quot;https://developer.android.com/about/versions/17/behavior-changes-17?hl=zh-cn&quot;&gt;行为变更：
以 Android 17 为目标平台的应用&lt;/a&gt;文档中。&lt;/span&gt;&lt;/aside&gt;

  

&lt;h2 id=&quot;security&quot; tabindex=&quot;-1&quot;&gt;安全&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下设备和应用安全方面的改进。&lt;/p&gt;

&lt;h3 id=&quot;uses-clear-traffic-deprecation&quot; tabindex=&quot;-1&quot;&gt;usesClearTraffic 弃用计划&lt;/h3&gt;

























































































































 





























 














&lt;p&gt;In a future release, we plan to deprecate the &lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;usesCleartextTraffic&lt;/code&gt; element.
Apps that need to make unencrypted (HTTP) connections should migrate to
using a &lt;a href=&quot;https://developer.android.com/privacy-and-security/security-config?hl=zh-cn&quot;&gt;network security configuration&lt;/a&gt; file, which lets you
specify which domains your app needs to make cleartext connections to.&lt;/p&gt;

&lt;p&gt;Be aware that network security configuration files are only supported on API
levels 24 and higher. If your app has a minimum API level lower than 24, you
should do &lt;em&gt;both&lt;/em&gt; of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set the &lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;usesCleartextTraffic&lt;/code&gt; attribute to &lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use a network configuration file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your app&amp;#39;s minimum API level is 24 or higher, you can use a network
configuration file and you don&amp;#39;t need to set &lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;usesCleartextTraffic&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;restrict-implicit-uri-grants&quot; tabindex=&quot;-1&quot;&gt;限制隐式 URI 授权&lt;/h3&gt;


    























































































































 





























 



























&lt;p&gt;目前，如果应用启动的 intent 具有 URI，且该 URI 具有操作
&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#ACTION_SEND&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_SEND&lt;/code&gt;&lt;/a&gt;、&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#ACTION_SEND_MULTIPLE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_SEND_MULTIPLE&lt;/code&gt;&lt;/a&gt;或
&lt;a href=&quot;https://developer.android.com/reference/android/provider/MediaStore?hl=zh-cn#ACTION_IMAGE_CAPTURE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_IMAGE_CAPTURE&lt;/code&gt;&lt;/a&gt;，则系统会自动向目标应用授予读取和
写入 URI 权限。从 Android 18 开始，系统将
不再自动授予这些权限。因此，我们建议应用明确授予相关 URI 权限，而不是依赖系统授予这些权限。&lt;/p&gt;

&lt;p&gt;如需检测应用中这些 intent 的使用情况，请将 &lt;a href=&quot;https://developer.android.com/reference/android/os/StrictMode?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;StrictMode&lt;/code&gt;&lt;/a&gt; 与
&lt;a href=&quot;https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder?hl=zh-cn#detectImplicitUriPermissionGrant()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;detectImplicitUriPermissionGrant()&lt;/code&gt;&lt;/a&gt; 结合使用，以触发违规行为：&lt;/p&gt;

&lt;div&gt;
&lt;div class=&quot;ds-selector-tabs&quot;&gt;&lt;section&gt;&lt;h3 id=&quot;kotlin&quot; tabindex=&quot;-1&quot;&gt;Kotlin&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;span class=&quot;devsite-syntax-kd&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-nv&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;StrictMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;VmPolicy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;detectImplicitUriPermissionGrant&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;penaltyLog&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;StrictMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setVmPolicy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;section&gt;&lt;h3 id=&quot;java&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;StrictMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;VmPolicy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;StrictMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;VmPolicy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;detectImplicitUriPermissionGrant&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;penaltyLog&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;devsite-syntax-n&quot;&gt;StrictMode&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;setVmPolicy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;或者，您也可以监控包含消息 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;Please set the grant explicitly in the app&lt;/code&gt; 的已记录异常，该消息会在系统隐式设置授予时显示。您可以使用以下 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;adb&lt;/code&gt; 命令监控这些日志：&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Bash&quot;&gt;&lt;code translate=&quot;no&quot; dir=&quot;ltr&quot;&gt;adb&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;logcat&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;grep&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-s2&quot;&gt;&quot;Please set the grant explicitly in the app&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;p&gt;如需明确授予必要的权限，请将
&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#FLAG_GRANT_READ_URI_PERMISSION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/code&gt;&lt;/a&gt;标志添加到&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#ACTION_SEND&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_SEND&lt;/code&gt;&lt;/a&gt;和
&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#ACTION_SEND_MULTIPLE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_SEND_MULTIPLE&lt;/code&gt;&lt;/a&gt;intent：&lt;/p&gt;

&lt;div&gt;
&lt;div class=&quot;ds-selector-tabs&quot;&gt;&lt;section&gt;&lt;h3 id=&quot;kotlin&quot; tabindex=&quot;-1&quot;&gt;Kotlin&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;addFlags&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;section&gt;&lt;h3 id=&quot;java&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;addFlags&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;对于
&lt;a href=&quot;https://developer.android.com/reference/android/provider/MediaStore?hl=zh-cn#ACTION_IMAGE_CAPTURE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_IMAGE_CAPTURE&lt;/code&gt;&lt;/a&gt; intent，请同时添加&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#FLAG_GRANT_READ_URI_PERMISSION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/code&gt;&lt;/a&gt; 和
&lt;a href=&quot;https://developer.android.com/reference/android/content/Intent?hl=zh-cn#FLAG_GRANT_WRITE_URI_PERMISSION&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;FLAG_GRANT_WRITE_URI_PERMISSION&lt;/code&gt;&lt;/a&gt; 标志：&lt;/p&gt;

&lt;div&gt;
&lt;div class=&quot;ds-selector-tabs&quot;&gt;&lt;section&gt;&lt;h3 id=&quot;kotlin&quot; tabindex=&quot;-1&quot;&gt;Kotlin&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Kotlin&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;addFlags&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;or&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_WRITE_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;section&gt;&lt;h3 id=&quot;java&quot; tabindex=&quot;-1&quot;&gt;Java&lt;/h3&gt;
&lt;div&gt;&lt;/div&gt;&lt;devsite-code&gt;&lt;pre class=&quot;devsite-click-to-copy&quot; translate=&quot;no&quot; dir=&quot;ltr&quot; is-upgraded syntax=&quot;Java&quot;&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;addFlags&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;devsite-syntax-w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;devsite-syntax-n&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;devsite-syntax-na&quot;&gt;FLAG_GRANT_WRITE_URI_PERMISSION&lt;/span&gt;&lt;span class=&quot;devsite-syntax-p&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/devsite-code&gt;
&lt;/section&gt;&lt;/div&gt;
&lt;/div&gt;

  

&lt;h3 id=&quot;per-app-keystore-limits&quot; tabindex=&quot;-1&quot;&gt;每个应用的密钥库限制&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;应用应避免在 Android 密钥库中创建过多的密钥，因为它是设备上所有应用的共享资源。从 Android 17 开始，系统会强制限制应用可拥有的密钥数量。对于以 Android 17（API 级别 37）或更高版本为目标平台的非系统应用，密钥数量上限为 50,000 个；对于所有其他应用，密钥数量上限为 200,000 个。无论系统应用以哪个 API 级别为目标，其密钥数量上限均为 20 万。&lt;/p&gt;

&lt;p&gt;如果应用尝试创建超出限制的密钥，则创建会失败并显示 &lt;a href=&quot;https://developer.android.com/reference/java/security/KeyStoreException?hl=zh-cn&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;KeyStoreException&lt;/code&gt;&lt;/a&gt;。异常的消息字符串包含有关密钥限制的信息。如果应用针对异常调用 &lt;a href=&quot;https://developer.android.com/reference/android/security/KeyStoreException?hl=zh-cn#getNumericErrorCode()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getNumericErrorCode()&lt;/code&gt;&lt;/a&gt;，则返回值取决于应用的目标 API 级别：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;如果应用以 Android 17（API 级别 37）或更高版本为目标平台，&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getNumericErrorCode()&lt;/code&gt; 会返回新的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ERROR_TOO_MANY_KEYS&lt;/code&gt; 值。&lt;/li&gt;
&lt;li&gt;所有其他应用：&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;getNumericErrorCode()&lt;/code&gt; 返回 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ERROR_INCORRECT_USAGE&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;

  

&lt;h3 id=&quot;block-cross-profile-loopback&quot; tabindex=&quot;-1&quot;&gt;阻止跨资料环回流量&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，默认情况下不再允许跨个人资料环回流量。同一个人资料内的环回流量不受影响。
此项变更适用于在
Android 17 或更高版本上运行的所有应用，无论应用以哪个 API 级别为目标平台。&lt;/p&gt;

  

&lt;h2 id=&quot;ux-sysui&quot; tabindex=&quot;-1&quot;&gt;用户体验和系统界面&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，旨在打造更一致、更直观的用户体验。&lt;/p&gt;

&lt;h3 id=&quot;ime-rotate&quot; tabindex=&quot;-1&quot;&gt;在旋转后恢复默认 IME 可见性&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，当设备的配置发生变化（例如，通过旋转）且应用本身未处理此变化时，系统不会恢复之前的 IME 可见性。&lt;/p&gt;

&lt;p&gt;如果应用经历了它无法处理的配置更改，并且应用需要在更改后显示键盘，您必须明确请求此行为。您可以通过以下方式之一提出此要求：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;将 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;android:windowSoftInputMode&lt;/code&gt; 属性设置为 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;stateAlwaysVisible&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;在 activity 的 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;onCreate()&lt;/code&gt; 方法中以编程方式请求显示软键盘，或添加 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;onConfigurationChanged()&lt;/code&gt; 方法。&lt;/li&gt;
&lt;/ul&gt;

  

&lt;h2 id=&quot;human-input&quot; tabindex=&quot;-1&quot;&gt;人工输入&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，这些变更会影响应用与键盘和触控板等人工输入设备的互动方式。&lt;/p&gt;

&lt;h3 id=&quot;touchpad-pointer-capture&quot; tabindex=&quot;-1&quot;&gt;在指针捕获期间，触控板默认传递相对事件&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，如果应用使用 &lt;a href=&quot;https://developer.android.com/reference/android/view/View?hl=zh-cn#requestPointerCapture()&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;View.requestPointerCapture()&lt;/code&gt;&lt;/a&gt; 请求捕获指针，并且用户使用触控板，系统会识别用户触摸操作产生的指针移动和滚动手势，并以与捕获的鼠标产生的指针和滚轮移动相同的方式将这些信息报告给应用。在大多数情况下，这使得支持捕获鼠标的应用无需为触控板添加特殊的处理逻辑。如需了解详情，请参阅 &lt;a href=&quot;https://developer.android.com/reference/android/view/View?hl=zh-cn#POINTER_CAPTURE_MODE_RELATIVE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;View.POINTER_CAPTURE_MODE_RELATIVE&lt;/code&gt;&lt;/a&gt; 的文档。&lt;/p&gt;

&lt;p&gt;之前，系统不会尝试识别触控板的手势，而是以类似于触摸屏触摸的格式将原始的绝对手指位置传递给应用。如果应用仍需要此绝对数据，则应改为使用 &lt;a href=&quot;https://developer.android.com/reference/android/view/View?hl=zh-cn#POINTER_CAPTURE_MODE_ABSOLUTE&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;View.POINTER_CAPTURE_MODE_ABSOLUTE&lt;/code&gt;&lt;/a&gt; 调用新的 &lt;a href=&quot;https://developer.android.com/reference/android/view/View?hl=zh-cn#requestPointerCapture(int)&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;View.requestPointerCapture(int)&lt;/code&gt;&lt;/a&gt; 方法。&lt;/p&gt;

  

&lt;h2 id=&quot;media&quot; tabindex=&quot;-1&quot;&gt;媒体&lt;/h2&gt;

&lt;p&gt;Android 17 针对媒体行为做了以下更改。&lt;/p&gt;

&lt;h3 id=&quot;bg-audio&quot; tabindex=&quot;-1&quot;&gt;后台音频安全加固&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;从 Android 17 开始，音频框架会对后台音频互动（包括音频播放、音频焦点请求和音量更改 API）强制执行限制，以确保这些更改是由用户有意发起的。&lt;/p&gt;

&lt;p&gt;如果应用尝试在应用未处于有效生命周期时调用音频 API，则音频播放和音量更改 API 会以静默方式失败，而不会抛出异常或提供失败消息。音频焦点 API 会失败，并返回结果代码 &lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;AUDIOFOCUS_REQUEST_FAILED&lt;/code&gt;。&lt;/p&gt;
&lt;aside class=&quot;note&quot;&gt;&lt;strong&gt;**注意**&lt;/strong&gt;：&lt;span&gt; 如果应用以
Android 17（API 级别 37）为目标平台，则限制会更加严格。对于这些应用，前台服务必须具有
“使用时”功能，除非应用具有&lt;a href=&quot;https://developer.android.com/develop/background-work/services/alarms?hl=zh-cn#exact&quot;&gt;精确闹钟&lt;/a&gt;
权限并且正在与 &lt;a href=&quot;https://developer.android.com/reference/android/media/AudioAttributes?hl=zh-cn#USAGE_ALARM&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;USAGE_ALARM&lt;/code&gt;&lt;/a&gt; 音频流互动。&lt;/span&gt;&lt;/aside&gt;&lt;p&gt;如需了解详情（包括缓解措施），请参阅&lt;a href=&quot;https://developer.android.com/about/versions/17/changes/bg-audio?hl=zh-cn&quot;&gt;后台音频安全加固&lt;/a&gt;。&lt;/p&gt;

  

&lt;h2 id=&quot;connectivity&quot; tabindex=&quot;-1&quot;&gt;连接&lt;/h2&gt;

&lt;p&gt;Android 17 包含以下变更，以增强设备连接性。&lt;/p&gt;

&lt;h3 id=&quot;autonomous-repairing&quot; tabindex=&quot;-1&quot;&gt;针对蓝牙绑定丢失的自主重新配对&lt;/h3&gt;


    























































































































 





























 














&lt;p&gt;Android 17 引入了自主重新配对功能，这是一项系统级增强功能，旨在自动解决蓝牙配对信息丢失问题。&lt;/p&gt;

&lt;p&gt;以前，如果配对信息丢失，用户必须手动前往“设置”取消配对，然后重新配对外围设备。此功能以 Android 16 的安全改进为基础，允许系统在后台重新建立配对信息，而无需用户手动前往“设置”取消配对并重新配对外围设备。&lt;/p&gt;

&lt;p&gt;虽然大多数应用不需要更改代码，但开发者应注意蓝牙堆栈中的以下行为变更：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;新的配对上下文&lt;/strong&gt;： &lt;a href=&quot;https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=zh-cn#ACTION_PAIRING_REQUEST&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_PAIRING_REQUEST&lt;/code&gt;&lt;/a&gt; 现在包含
&lt;a href=&quot;https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=zh-cn#EXTRA_PAIRING_CONTEXT&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;EXTRA_PAIRING_CONTEXT&lt;/code&gt;&lt;/a&gt; extra，允许应用区分
标准配对请求和自主系统发起的重新配对尝试。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;有条件的密钥更新&lt;/strong&gt;：只有在重新配对成功且新连接达到或超过之前配对信息的安全级别时，才会替换现有安全密钥。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;修改后的 intent 时间&lt;/strong&gt;：现在，只有在自主重新配对尝试失败时，才会广播 &lt;a href=&quot;https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=zh-cn#ACTION_KEY_MISSING&quot;&gt;&lt;code dir=&quot;ltr&quot; translate=&quot;no&quot;&gt;ACTION_KEY_MISSING&lt;/code&gt;&lt;/a&gt; intent。如果系统在后台成功恢复配对信息，则可以减少应用中不必要的错误处理。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;用户通知&lt;/strong&gt;：系统通过新的界面通知和对话框管理重新配对。系统会提示用户确认重新配对尝试，以确保用户了解重新连接。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;外围设备制造商和配套应用开发者应验证硬件和应用是否能妥善处理配对信息转换。如需测试此行为，请使用以下任一方法模拟远程配对信息丢失：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;从外围设备中手动移除配对信息&lt;/li&gt;
&lt;li&gt;在“设置”&gt;“已连接的设备”中手动取消配对设备&lt;/li&gt;
&lt;/ul&gt;

  

  
  

  
&lt;/div&gt;

  
    
      &lt;devsite-recommendations display=&quot;in-page&quot; hidden yield&gt;
      &lt;/devsite-recommendations&gt;
    
    
      
    &lt;devsite-thumb-rating position=&quot;footer&quot;&gt;
    &lt;/devsite-thumb-rating&gt;
  
       
    
    
      &lt;devsite-recommendations id=&quot;recommendations-link&quot; yield&gt;&lt;/devsite-recommendations&gt;
    
  

  &lt;div class=&quot;devsite-floating-action-buttons&quot;&gt;&lt;/div&gt;&lt;/article&gt;</description><pubDate>Wed, 17 Jun 2026 12:00:00 +0800</pubDate></item></channel></rss>