<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by tanabee on Medium]]></title>
        <description><![CDATA[Stories by tanabee on Medium]]></description>
        <link>https://medium.com/@tanabee?source=rss-3cebc6128b6e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fyjdtNf3PTwOt8BFNAG8nw.jpeg</url>
            <title>Stories by tanabee on Medium</title>
            <link>https://medium.com/@tanabee?source=rss-3cebc6128b6e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:50:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanabee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Introducing awake: a tiny CLI that keeps your Mac awake with the lid closed]]></title>
            <link>https://medium.com/@tanabee/introducing-awake-a-tiny-cli-that-keeps-your-mac-awake-with-the-lid-closed-013c4c1155b0?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/013c4c1155b0</guid>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[google-antigravity]]></category>
            <category><![CDATA[ai-coding]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 10:21:13 GMT</pubDate>
            <atom:updated>2026-09-08T13:34:35.991Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcsSA5P5dYUES_fC_45Oag.png" /></figure><p>AI-driven development has become part of my daily workflow, and I often want my Mac to keep running without sleeping — for long jobs, or so I can open the lid briefly during a commute, hand a task to an AI, and let it keep working after I close the lid. You can already do this by combining pmset and caffeinate, but I got tired of remembering the commands, so I wrote a thin wrapper.</p><p><a href="https://github.com/tanabee/awake">GitHub - tanabee/awake</a></p><ul><li>Install:</li></ul><pre>git clone https://github.com/tanabee/awake.git ~/.local/share/awake<br>ln -s ~/.local/share/awake/bin/awake ~/.local/bin/awake</pre><p><strong>TL;DR:</strong> A single awake command does the equivalent of sudo pmset -a disablesleep 1 + caffeinate -is, and reliably undoes it on Ctrl+C or awake stop. It can also auto-stop after a fixed time (-t 8h) or when the battery gets low (-b 20). Background, status, and stop subcommands included. The whole thing is about 700 lines of bash.</p><h3>Why I built it</h3><p>caffeinate alone <strong>does not prevent clamshell (lid-closed) sleep</strong>. To stop clamshell sleep you need pmset disablesleep 1, which requires sudo and — crucially — <strong>persists until you explicitly set it back to 0</strong>.</p><p>Typing two commands every time and remembering to clean up got old, so I wrapped it in a script that always runs the cleanup itself.</p><h3>Usage</h3><h4>Foreground (recommended)</h4><pre>awake</pre><p>You’ll be prompted for your sudo password. Once the running message appears, you can close the lid. When you&#39;re done, Ctrl+C automatically runs pmset -a disablesleep 0 and restores the original state. The password prompt happens only once, at startup — never at exit.</p><pre>awake: disabling sleep (sudo may ask for your password — once; exit never prompts)<br>Password:<br>awake: running (PID=12345, caffeinate PID=12346)<br>awake: the Mac will stay awake with the lid closed. Press Ctrl+C to release and exit.<br>^C<br>awake: restoring sleep settings (root helper; no sudo prompt)<br>awake: sleep settings restored (pmset -a disablesleep 0)</pre><h4>Background</h4><p>For when you don’t want a terminal window tied up. Just remember to stop it.</p><pre>awake start      # run in the background<br>awake status     # check state<br>awake stop       # stop (pmset is restored automatically)</pre><p>awake status output:</p><pre>awake: running (background)<br>  pid:                39189<br>  started:            2026-05-24 13:24:59 JST<br>  uptime:             1h 03m 12s<br>  pmset disablesleep: 1<br>  log:                /Users/yuki.tanabe/.local/state/awake/awake.log</pre><h4>Auto-stop after a time limit (-t / --timeout)</h4><p>For the “run this for 8 hours, then let the Mac sleep normally again” case. Pass a duration to -t and, once it elapses, awake exits through the same path as awake stop / Ctrl+C, restoring pmset along the way.</p><pre>awake -t 1h            # foreground, auto-stop after 1 hour<br>awake -t 30m           # 30 minutes<br>awake -t 1h30m         # combine h / m / s<br>awake -t 3600          # a bare integer is seconds (== 1h)</pre><pre>awake start -t 8h      # background, auto-stop after 8 hours</pre><p>No sudo password prompt appears when the timer fires, so you can run awake -t 8h, walk away, and trust that the sleep settings will be back to normal when the time is up (more on how below).</p><p>The foreground startup message shows the timeout too.</p><pre>awake: running (PID=12345, caffeinate PID=12346, timeout=1h 00m 00s)</pre><h4>Auto-stop on low battery (-b / --battery)</h4><p>If you close the lid and let something run while on the move, it’s easy to come back to a dead battery. Pass an integer from 1 to 99 to -b and awake stops as soon as the battery level drops to or below that value.</p><pre>awake -b 20            # foreground, stop when battery &lt;= 20%<br>awake start -b 15      # background, stop when battery &lt;= 15%<br>awake -t 8h -b 20      # combine: stop after 8 hours OR at &lt;= 20%, whichever comes first</pre><ul><li>Checks the battery level and power source every 60 seconds via pmset -g batt</li><li><strong>Skipped while on AC power</strong>, so charging never triggers an unwanted stop</li><li>When the threshold is hit, it sends itself SIGTERM and goes through the normal cleanup path, same as -t</li></ul><p>If you awake start with -t / -b, awake status shows the remaining time, the threshold, the current battery level, and the power source.</p><pre>Auto-stop when the Mac gets hot (-s / --safe)<br>Closing the lid traps heat in the chassis, and someone rightly pointed this out after I first posted about awake. Pass -s to auto-stop when macOS reports thermal pressure at &quot;serious&quot; or worse for 3 minutes straight.<br>awake -s                # foreground, stop if the Mac stays hot for 3 minutes<br>awake start -s          # background, same idea<br>awake -t 8h -b 20 -s    # combine: whichever condition fires first stops awake<br>Reads NSProcessInfo.thermalState (nominal / fair / serious / critical) through osascript, so it needs no extra tools and no sudo, on both Apple Silicon and IntelChecks every 60 seconds; a short spike that cools back down resets the 3-minute windowLike -t and -b, it goes through the normal cleanup path, so sleep settings are restored<br>awake status shows safe mode: on along with the current thermal state.<br>To be clear about what this does and doesn&#39;t do: macOS already throttles the CPU and protects the hardware on its own. -s doesn&#39;t add hardware protection. It stops keeping the Mac awake once it&#39;s too hot to do useful work anyway, which is the state you actually want to notice when the machine is sitting closed in a bag.awake: running (background)<br>  pid:                39189<br>  started:            2026-05-24 13:24:59 JST<br>  uptime:             1h 03m 12s<br>  auto-stop at:       2026-05-24 21:24:59 JST<br>  remaining:          6h 56m 48s<br>  battery threshold:  20% (now 63%, source: battery)<br>  pmset disablesleep: 1<br>  log:                /Users/yuki.tanabe/.local/state/awake/awake.log</pre><h4>Auto-stop when the Mac gets hot (-s / — safe)</h4><p>Closing the lid traps heat in the chassis, and someone rightly pointed this out after I first posted about awake. Pass -s to auto-stop when macOS reports <strong>thermal pressure at “serious” or worse for 3 minutes straight</strong>.</p><pre>awake -s # foreground, stop if the Mac stays hot for 3 minutes<br>awake start -s # background, same idea<br>awake -t 8h -b 20 -s # combine: whichever condition fires first stops awake</pre><ul><li>Reads NSProcessInfo.thermalState (nominal / fair / serious / critical) through osascript, so it needs no extra tools and no sudo, on both Apple Silicon and Intel</li><li>Checks every 60 seconds; a short spike that cools back down resets the 3-minute window</li><li>Like -t and -b, it goes through the normal cleanup path, so sleep settings are restored</li></ul><p>awake statusshows safe mode: on along with the current thermal state.</p><p>To be clear about what this does and doesn’t do: macOS already throttles the CPU and protects the hardware on its own. -s doesn’t add hardware protection. It stops keeping the Mac awake once it’s too hot to do useful work anyway, which is the state you actually want to notice when the machine is sitting closed in a bag.</p><h3>How it works</h3><ol><li>Disable clamshell sleep — sudo pmset -a disablesleep 1 (via a root helper)</li><li>Also prevent system idle sleep — caffeinate -is (background process)</li><li>Always restore on exit — the root helper runs pmset -a disablesleep 0</li></ol><p>Step 3 is the important one. The first version used a bash trap on INT TERM HUP EXIT and ran sudo pmset -a disablesleep 0 inside the cleanup. The problem is that <strong>sudo may prompt for a password again at exit</strong> (its credential cache expires after 5 minutes by default). That defeats the whole point of -t 8h: an auto-stop that hangs on a password prompt 8 hours later is useless.</p><p>So instead, the single sudo at startup launches a <strong>root helper</strong> process, and that helper owns the restore step.</p><pre># A FIFO whose write end is held only by the main awake process<br>mkfifo -m 600 &quot;$HELPER_FIFO&quot;<br>exec 9&lt;&gt;&quot;$HELPER_FIFO&quot;</pre><pre>sudo bash -c &#39;<br>  fifo=&quot;$1&quot;<br>  trap &quot;&quot; INT TERM HUP          # ignore Ctrl+C etc. aimed at the main process<br>  exec 0&lt;&quot;$fifo&quot;<br>  pmset -a disablesleep 1<br>  while read -r line; do :; done   # block until EOF (= main awake process exited)<br>  pmset -a disablesleep 0<br>&#39; _ &quot;$HELPER_FIFO&quot; 9&gt;&amp;- &amp;</pre><p>The helper just blocks reading the FIFO. When the main awake process exits and the write end closes, the helper gets EOF and runs pmset -a disablesleep 0 with the root privileges it already holds. The main process&#39;s cleanup is still a trap on INT TERM HUP EXIT, but all it does now is kill the caffeinate / timer / battery-monitor children and close fd 9.</p><pre>cleanup() {<br>  trap - INT TERM HUP EXIT<br>  # kill the timer / battery monitor / caffeinate children<br>  ...<br>  exec 9&gt;&amp;-   # close the FIFO -&gt; helper sees EOF and restores disablesleep 0<br>  wait &quot;$HELPER_PID&quot;<br>}</pre><pre>trap cleanup INT TERM HUP EXIT</pre><p>A nice side effect: even if awake is killed with kill -9, the OS closes its file descriptors, the helper sees EOF, and pmset is restored. The trap-only version couldn&#39;t handle SIGKILL, so this was a welcome bonus.</p><p>If the OS crashes outright, the helper dies too and pmset -a disablesleep 1 is left behind. awake status detects this case and warns you.</p><pre>awake: not running (background)<br>  pmset disablesleep: 1<br>  warning: disablesleep is 1 but no awake process is tracked.<br>  another tool may hold it, or a prior awake was force-killed.<br>  inspect with: pmset -g assertions<br>  restore with: sudo pmset -a disablesleep 0</pre><h3>Limitations</h3><ul><li><strong>macOS only.</strong> It depends on pmset and caffeinate.</li><li><strong>sudo required.</strong> pmset disablesleep needs root (only once, at startup).</li><li><strong>Heat.</strong> Closing the lid traps heat in the chassis. Avoid sustained heavy CPU/GPU loads in clamshell mode.</li><li><strong>Battery.</strong> The Mac won’t sleep with the lid closed, so on battery it just keeps draining. For long sessions, plug in or set a floor with -b.</li></ul><h3>Give it a try</h3><p>If you want to do AI-driven development on the move, or let a local AI keep working without your Mac going to sleep, give it a try.</p><p>It’s brand new, so if you hit bugs please file them on <a href="https://github.com/tanabee/awake/issues">GitHub Issues</a>.</p><h3>References</h3><ul><li><a href="https://ss64.com/osx/pmset.html">pmset man page</a></li><li><a href="https://ss64.com/osx/caffeinate.html">caffeinate man page</a></li><li><a href="https://github.com/tanabee/awake">tanabee/awake (GitHub)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=013c4c1155b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kickstart AI Agents with Genkit]]></title>
            <link>https://medium.com/firebase-developers/kickstart-ai-agents-with-genkit-3775e5525777?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3775e5525777</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[mcp-server]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Fri, 13 Jun 2025 23:15:30 GMT</pubDate>
            <atom:updated>2025-06-13T23:15:30.719Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Genkit is an OSS framework that enables rapid development of AI orchestration. Developed by the Firebase team, it currently supports Node.js, Go, and Python.</p><p>This article introduces how to kickstart Genkit AI agents using Node.js.</p><h3>Getting Started</h3><p>I developed a command called <strong>create-genkitx</strong> that allows you to kickstart Genkit project boilerplate setup.</p><p><a href="https://www.npmjs.com/package/create-genkitx">create-genkitx</a></p><p>This command can be executed as follows:</p><pre>npm create genkitx</pre><p>Then, you’ll see the following options, so select MCP:</p><pre>? Select template › - Use arrow-keys. Return to submit.<br> Minimal<br> VertexAI<br>❯ MCP - This is a MCP template<br> Firebase</pre><p>Next, enter your project name:</p><pre>✔ Select template › MCP<br>? Enter your project name › genkit-mcp-sample</pre><p>This will set up a GitHub boilerplate in your local environment. By following the written commands, you can run a sample AI agent that connects to GitHub MCP.</p><p>Create your GITHUB_PERSONAL_ACCESS_TOKEN <a href="https://github.com/settings/personal-access-tokens">here</a>.</p><pre>✅ Project &quot;genkit-mcp-sample&quot; has been successfully generated<br>You can start your project with the following commands:<br>cd genkit-mcp-sample<br>echo &quot;GEMINI_API_KEY=&lt;your-api-key&gt;&quot; &gt; .env<br>echo &quot;GITHUB_PERSONAL_ACCESS_TOKEN=&lt;your-github-personal-access-token&gt;&quot; &gt;&gt; .env<br>npm start<br>Enjoy building with Genkit!</pre><h3>Source Code</h3><p>The source code can be found in src/index.ts. The entire code is about 40 lines, showing how simple it is to develop. Let me walk through the key points.</p><p>Use the mcpClient function to define which MCP to use:</p><pre>const githubClient = mcpClient({<br>  name: &#39;github&#39;,<br>  serverProcess: {<br>  command: &#39;npx&#39;,<br>  args: [&#39;-y&#39;, &#39;@modelcontextprotocol/server-github&#39;],<br>  env: process.env as Record&lt;string, string&gt;,<br>  },<br>})</pre><p>Set the previously defined githubClient in the plugins parameter of the genkit function:</p><pre>const ai = genkit({<br>  plugins: [<br>    githubClient,<br>    googleAI(),<br>  ],<br>  model: gemini25FlashPreview0417,<br>})</pre><p>In the section that requests generative AI with the ai.generate function, make the GitHub MCP’s search_repositories tool available:</p><pre>const mainFlow = ai.defineFlow({<br>  name: &#39;mainFlow&#39;,<br>  inputSchema: z.string(),<br>}, async (prompt) =&gt; {<br>  const { text } = await ai.generate({<br>    prompt,<br>    tools: [&#39;github/search_repositories&#39;]<br>  })<br>  return text<br>})</pre><h3>Testing</h3><p>Genkit’s Developer Tools launch at <a href="http://localhost:4000">http://localhost:4000</a> when running npm start. Select mainFlow from the Flows menu and make a request like Tell me the top 10 GitHub repositories related to Genkit to execute the GitHub MCP’s search_repositories tool and receive a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCzHb9lf3mIx_a1V1wypKA.png" /></figure><p>By selecting the <strong>View trace</strong> menu, you can confirm that search_repositories was actually used. While generative AI hallucination is a well-known issue, being able to verify MCP tools in Developer Tools during development provides significant value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LnuC1s8jR1MHD2YM9yEuA.png" /></figure><h3>Conclusion</h3><p>This sample demonstrated setup using GitHub MCP, but you can easily switch to other MCPs. Please give it a try.</p><p>I recommend searching for MCP servers from the officially maintained repository:</p><p><a href="https://github.com/modelcontextprotocol/servers">GitHub - modelcontextprotocol/servers: Model Context Protocol Servers</a></p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3775e5525777" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/kickstart-ai-agents-with-genkit-3775e5525777">Kickstart AI Agents with Genkit</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[internal AI: A Genkit-Based Internal AI Chat Released as Open Source!]]></title>
            <link>https://medium.com/firebase-developers/internal-ai-a-genkit-based-internal-ai-chat-released-as-open-source-37795896a106?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/37795896a106</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Mon, 17 Feb 2025 05:24:01 GMT</pubDate>
            <atom:updated>2025-03-23T06:26:40.362Z</atom:updated>
            <content:encoded><![CDATA[<h3>internal AI: An open-source Genkit-based internal AI chat implementation</h3><p>I have released <strong>internal AI</strong>, an AI chat solution you can easily and cost-effectively run internally, under an open-source license!</p><p>Recently, <a href="https://firebase.blog/posts/2025/02/announcing-genkit">Firebase Genkit reached version 1.0</a> and became stable for production use. With Genkit, you can quickly build applications that leverage generative AI. However, Genkit itself does not include a user interface. As a use case for an internal AI chat, I decided to make <strong>internal AI</strong> available as open source.</p><p>Because <strong>internal AI</strong> uses a pay-as-you-go model instead of charging per user, you can optimize costs by only paying for the amount of usage. Moreover, thanks to Genkit’s extensibility, you can combine <a href="https://firebase.google.com/docs/genkit/rag">RAG</a> (Retrieval-Augmented Generation) and <a href="https://firebase.google.com/docs/genkit/tool-calling">Function Calling</a> to tailor AI features to your organization’s needs. This opens the door to more practical AI applications, such as specialized internal information retrieval or automated workflow processes!</p><p><a href="https://github.com/tanabee/internal-ai">GitHub - tanabee/internal-ai</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCz6uCYuM3HrrjtC3ZnYnA.gif" /><figcaption>internal AI — Chat</figcaption></figure><h3>Key Features</h3><ul><li><strong>Open-source</strong> project, allowing customization to fit your organization’s needs</li><li><strong>Abstracted interface</strong> with generative AI via Genkit</li><li><strong>Deployable on Firebase</strong></li><li><strong>Firebase AI Monitoring</strong> for monitoring requests to generative AI</li><li><strong>Restricting Usage</strong> to Specific Domains</li><li><strong>Usage-based pricing</strong>, independent of the number of users</li></ul><h3>Open-source project, allowing customization to fit your organization’s needs</h3><p><strong>internal AI</strong> is provided as a boilerplate, which you can freely fork and customize according to your organization’s requirements.</p><p>Genkit can be extended in many ways, such as using RAG for accessing internal data or utilizing Google Search for grounding. To keep things simple for initial adoption, this example just communicates with Gemini 2.0.</p><pre>const ai = genkit({<br> // …<br> model: gemini20Flash001,<br>})<br>export const chatFlow = ai.defineFlow(<br> // …<br> async (messages) =&gt; {<br> const response = await ai.generate({ messages })<br> return response.messages<br> },<br>)</pre><p><a href="https://github.com/tanabee/internal-ai/blob/main/functions/src/genkit/chatFlow.ts">internal-ai/functions/src/genkit/chatFlow.ts at main · tanabee/internal-ai</a></p><h3>Abstracted interface with generative AI via Genkit</h3><p>In this project, I’m using Vertex AI via Genkit, but you can change the backend or model based on your needs.</p><p>Genkit follows a policy of community plugins named in the format “genkitx-*”. If you need a model not provided by the official plugins, you might find it by searching npm.</p><p><a href="https://www.npmjs.com/search?q=genkitx-">genkitx- - npm search</a></p><h3>Deployable on Firebase</h3><p>I designed this project to be deployed on Firebase. The following Firebase services are used, all of which can be managed through the Firebase Console. In addition, you can run everything locally with the Firebase Emulator, making it possible to verify all behaviors in a local environment.</p><ul><li><strong>Firestore</strong>: Used as the database, storing chat histories and user information</li><li><strong>Cloud Functions for Firebase</strong>: Server-side execution environment</li><li><strong>Firebase Authentication</strong>: Authentication layer</li><li><strong>Firebase Hosting</strong>: Hosts the web application</li><li><strong>Firebase Genkit</strong>: Interface to generative AI and monitoring of AI requests</li></ul><h3>Firebase AI Monitoring for monitoring requests to generative AI</h3><p>You can monitor requests to generative AI made through Genkit. This lets you see metrics like success rates and token consumption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgzEMwT1hpNJeQKnf1PCIQ.png" /><figcaption>Firebase AI Monitoring</figcaption></figure><h3>Restricting Usage to Specific Domains</h3><p>To limit usage to your organization, you can use Firebase Authentication Blocking Functions to set email domain restrictions. You’re also free to modify the restriction logic in the source code. For instance, you could allow multiple domains or grant access only to specific users for personal use — whatever suits your needs.</p><pre>export const beforeusercreated = beforeUserCreated(async (event) =&gt; {<br>  // TODO: Replace with your company domain<br>  const domain = &#39;@tanabee.dev&#39;<br>  if (!user?.email?.includes(domain)) {<br>    throw new HttpsError(&#39;permission-denied&#39;, &#39;Unauthorized email&#39;)<br>  }<br>})</pre><p>Additionally, there’s an Admin console accessible only by administrators, where you can add more menu options as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W9zQcYXzyydPtNSmtbTC4Q.png" /><figcaption>internal AI — Admin Console</figcaption></figure><h3>Usage-based pricing, independent of the number of users</h3><p><strong>internal AI</strong> is billed based on usage rather than the number of users, so you only pay for what you actually use. For most organizations, this can significantly reduce costs.</p><p>There are also additional Firebase charges, but for smaller organizations, you may well operate within the free tier, making it extremely cost-effective to adopt.</p><p>Because it uses Vertex AI for LLM connections, all billing is tied to your GCP project, which allows you to manage costs centrally.</p><h3>Special Thanks for the Design</h3><p>The UI design for <strong>internal AI</strong> was created by <a href="https://x.com/hikarutayama">Hikaru Tayama</a>! Thanks to the simple and intuitive design, it’s easy to use. I truly appreciate this excellent work, which has helped <strong>internal AI</strong> become a project that many can enjoy comfortably.</p><h3>Conclusion</h3><p>If you’re interested, I’ve prepared an <a href="https://github.com/tanabee/internal-ai/blob/main/docs/installation-guide.md">installation guide</a>. Feel free to fork it and try it out within your company.</p><p><a href="https://github.com/tanabee/internal-ai/blob/main/docs/installation-guide.md">internal-ai/docs/installation-guide.md at main · tanabee/internal-ai</a></p><h3>Related Posts</h3><ul><li><a href="https://medium.com/firebase-developers/implementing-function-calling-using-genkit-0c03f6cb9179">Implementing Function Calling using Genkit</a></li><li><a href="https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693">High-Precision Responses with Genkit’s Google Search Integration</a></li><li><a href="https://medium.com/firebase-developers/how-to-develop-using-the-gemma2-model-in-genkit-085f22ce68f3">Master Gemma2 and Genkit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37795896a106" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/internal-ai-a-genkit-based-internal-ai-chat-released-as-open-source-37795896a106">internal AI: A Genkit-Based Internal AI Chat Released as Open Source!</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing an Offline Translation Tool with Genkit and Gemma2]]></title>
            <link>https://medium.com/firebase-developers/implementing-an-offline-translation-tool-with-genkit-and-gemma2-4bda310ff074?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bda310ff074</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[gemma]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[translation]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 22:20:35 GMT</pubDate>
            <atom:updated>2025-03-23T06:30:10.506Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Recently, I wrote an article about using Genkit and Gemma2 for a local LLM, which led me to create a simple offline translation tool. This article covers how it was done.</p><h3>Implementation</h3><p>First, set up Genkit and Gemma2 as described in the following article:</p><p><a href="https://medium.com/firebase-developers/how-to-develop-using-the-gemma2-model-in-genkit-085f22ce68f3">Master Gemma2 and Genkit</a></p><p>After that, it’s just a matter of modifying the prompt.</p><h4>Key Changes</h4><ul><li>Set the flow name to translationFlow</li><li>Modify the prompt passed to the generate method to instruct the model to translate the user-provided text into both English and Japanese</li></ul><pre>const translationFlow = ai.defineFlow(<br>  {<br>    name: &#39;translationFlow&#39;,<br>    inputSchema: z.string(),<br>  },<br>  async input =&gt; {<br>    const prompt = `Translate the following text into both English and Japanese.\n\n## Text:\n${input}\n\n## English:`<br>    const { text } = await ai.generate(prompt)<br>    return text<br>  }<br>)</pre><h3>Actual Behavior</h3><p>Genkit has a tool called Developer Tools, which allows for local testing. I used this UI as-is.</p><p>When I asked, “What advantages does Genkit have over other OSS?” in Kazakh, the following results were generated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iU2k0AhBha13U8ziy3PV4A.png" /><figcaption><strong>Translating Kazakh with Genkit x Gemma2</strong></figcaption></figure><p>The answer in Japanese to the above question is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkpGkfpBt44STw2-_6e8rw.png" /><figcaption><strong>Translating Japanese with Genkit x Gemma2</strong></figcaption></figure><p>This meets my needs, so I consider it complete at this level. If your needs differ, feel free to try prompt engineering.</p><h3>Source Code</h3><p>The source code is available on GitHub, so feel free to use it as you like.</p><p><a href="https://github.com/tanabee/offline-translator">GitHub - tanabee/offline-translator</a></p><h3>Related Posts</h3><ul><li><a href="https://medium.com/firebase-developers/internal-ai-a-genkit-based-internal-ai-chat-released-as-open-source-37795896a106">internal AI: A Genkit-Based Internal AI Chat Released as Open Source!</a></li><li><a href="https://medium.com/firebase-developers/implementing-function-calling-using-genkit-0c03f6cb9179">Implementing Function Calling using Genkit</a></li><li><a href="https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693">High-Precision Responses with Genkit’s Google Search Integration</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bda310ff074" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/implementing-an-offline-translation-tool-with-genkit-and-gemma2-4bda310ff074">Implementing an Offline Translation Tool with Genkit and Gemma2</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[High-Precision Responses with Genkit’s Google Search Integration]]></title>
            <link>https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f142f5c9693</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[grounding]]></category>
            <category><![CDATA[google-search]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 18:37:56 GMT</pubDate>
            <atom:updated>2024-11-17T23:58:40.092Z</atom:updated>
            <content:encoded><![CDATA[<h4>aGenkit</h4><p>With the release of Genkit version 0.5.9, it is now possible to leverage Google Search directly through Genkit. By using Google Search, Genkit can access the latest information, including niche details from specific domains, leading to more accurate responses.</p><p>This article explains how to set up Google Search integration for Genkit.</p><h3>Enabling Vertex AI</h3><p>To use the Google Search feature, you need a Google Cloud project with Vertex AI enabled. Follow these steps to enable Vertex AI and link your local environment with Google Cloud:</p><p>1. In the Cloud console, Enable the Vertex AI API for your project.</p><p>2. Set environment variables:</p><pre>export GCLOUD_PROJECT=&lt;your project ID&gt;<br>export GCLOUD_LOCATION=us-central1</pre><p>3. Authenticate with gcloud:</p><pre>gcloud auth application-default login</pre><h3>Initializing a Genkit Project</h3><p>Next, initialize your Genkit project.</p><pre>% npm init -y<br>% npm i -D genkit-cli<br>% npm i genkit @genkit-ai/googleai @genkit-ai/vertexai<br>% mkdir src &amp;&amp; touch src/index.ts</pre><p>Paste the following initialization code into the src/index.ts file.</p><pre>import { genkit, z } from &#39;genkit&#39;;<br>import { vertexAI } from &#39;@genkit-ai/vertexai&#39;;<br>import { gemini15Flash } from &#39;@genkit-ai/vertexai&#39;;<br><br>const ai = genkit({<br>  model: gemini15Flash,<br>  plugins: [vertexAI({ location: &#39;us-central1&#39; })],<br>});<br><br>export const mainFlow = ai.defineFlow(<br>  {<br>    name: &#39;mainFlow&#39;,<br>    inputSchema: z.string(),<br>    outputSchema: z.string(),<br>  },<br>  async (prompt) =&gt; {<br>    const { text } = await ai.generate(prompt);<br>    return text;<br>  }<br>);<br><br>ai.startFlowServer({ flows: [mainFlow] });</pre><h3>Enabling Google Search</h3><p>To enable Google Search, specify `googleSearchRetrieval` with `withConfig` for the `gemini15Flash` model, as shown in the following code.</p><pre>const ai = genkit({<br>  model: gemini15Flash.withConfig({ googleSearchRetrieval: {}}),<br>  plugins: [vertexAI({ location: &#39;us-central1&#39; })],<br>});</pre><h3>Run locally</h3><p>Launch the Genkit Developer UI with the following command:</p><pre>% npx genkit start -- npx tsx --watch src/index.ts</pre><p>Try asking about the current weather in Tokyo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZX-L83SRDc_9kQaScdjCzQ.png" /><figcaption>Ask about Tokyo’s weather using Genkit x Google Search — Flow</figcaption></figure><p>A response will be returned. Clicking the “View Trace” button reveals that Google Search was used with the phrase “weather in Tokyo today”, and the response was generated based on the search results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gl-cBGFz4Z8aSxIH9dZkOg.png" /><figcaption>Ask about Tokyo’s weather using Genkit x Google Search — View Trace</figcaption></figure><h3>Summary</h3><p>Enabling Google Search integration in Genkit is as easy as adding one line of code. You can find the sample code on GitHub, so feel free to try it out.</p><p><a href="https://github.com/tanabee/genkit-google-search-sample">GitHub - tanabee/genkit-google-search-sample</a></p><h3>References</h3><ul><li><a href="https://github.com/firebase/genkit/releases/tag/0.5.9">Release Genkit JS 0.5.9 · firebase/genkit</a></li><li><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview">Grounding overview | Generative AI on Vertex AI | Google Cloud</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FTjxJnQQCS_A%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTjxJnQQCS_A&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTjxJnQQCS_A%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/79db4375c95e6f10cf4f8ddbf78c15e2/href">https://medium.com/media/79db4375c95e6f10cf4f8ddbf78c15e2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f142f5c9693" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693">High-Precision Responses with Genkit’s Google Search Integration</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the power of code execution in Genkit]]></title>
            <link>https://medium.com/firebase-developers/getting-started-with-code-execution-in-genkit-c5391b45b321?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5391b45b321</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[code-execution]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 14:57:44 GMT</pubDate>
            <atom:updated>2025-05-10T03:12:10.278Z</atom:updated>
            <content:encoded><![CDATA[<h4>Genkit</h4><p>Learn how to seamlessly integrate Python code within your Genkit workflows for enhanced output generation and automation.</p><p>Code execution, introduced in Genkit 0.5.8, enables the execution of Python code during output generation. Let’s take a look at how this works.</p><h3>Initializing a Genkit Project</h3><p>Let’s first initialize a Genkit project.</p><pre>$ npm create genkitx<br><br>? Select template › - Use arrow-keys. Return to submit.<br>❯   Minimal - This is a Minimal template<br>    MCP<br><br>? Enter your project name › hello-genkit<br><br>✅ Project &quot;hello-genkit&quot; has been successfully generated<br><br>$ cd hello-genkit<br>$ export GEMINI_API_KEY=&lt;your-api-key&gt;</pre><p>Let’s check the file src/index.ts. This code represents the actual implementation of a generative AI request using Genkit, which can be written in about 20 lines.</p><pre>import { genkit, z } from &#39;genkit&#39;<br>import { googleAI, gemini15Flash } from &#39;@genkit-ai/googleai&#39;<br>import { logger } from &#39;genkit/logging&#39;<br>logger.setLogLevel(&#39;debug&#39;)<br><br>const ai = genkit({<br>  plugins: [googleAI()],<br>  model: gemini15Flash,<br>})<br><br>const mainFlow = ai.defineFlow({<br>  name: &#39;mainFlow&#39;,<br>  inputSchema: z.string(),<br>}, async (input) =&gt; {<br>  const { text } = await ai.generate(input)<br>  return text<br>})<br><br>ai.startFlowServer({ flows: [mainFlow] })</pre><h3>Enabling Code Execution</h3><p>You can enable it simply by adding .withConfig({ codeExecution: true }) to the part where the Genkit function&#39;s argument specifies the generative AI model.</p><pre>-  model: gemini15Flash,<br>+  model: gemini15Flash.withConfig({ codeExecution: true }),</pre><h3>Actual Behavior</h3><p>Run the following to launch the Genkit Developer UI.</p><pre>% npx genkit start -o -- npx tsx --watch src/index.ts</pre><p>Select the implemented flow from the <em>Flow</em> menu.</p><p>First, let’s try requesting the following prompt:<br>“Simulate the ratio of heads to tails after flipping a coin 100,000 times.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqyeDF60_GE2Y_ntPRjiXw.png" /></figure><p>By selecting <em>View trace</em>, you can see that the code has actually been executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaSGnWP_oqb1BqwcKqT-FQ.png" /></figure><p>Next, let’s try a more direct request:<br>“Execute the following code in Python: print(‘Hello World’)”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pA1v6q9eZsjaR81tunACEQ.png" /></figure><p>As with the previous request, selecting View trace shows that the code has been executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqJn741yiEKkgvxNGmccfw.png" /></figure><p>Finally, let’s try a general request unrelated to code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vysgv83KHrKqMcJDRnqzmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v5rRRb8XVE3W5iTyqn9C_w.png" /></figure><p>You can see that no code was executed. This is because code execution is specified as one of the tool options, and the generative AI only uses code execution when necessary.</p><h3>Summary</h3><p>With just one additional line, we were able to use code execution in our Genkit flows. This expands the possibilities of what can be done with Genkit. Please give it a try.</p><p>Here is the code on GitHub.</p><p><a href="https://github.com/tanabee/genkit-code-execution-sample">GitHub - tanabee/genkit-code-execution-sample</a></p><h3>References</h3><ul><li><a href="https://ai.google.dev/gemini-api/docs/code-execution?lang=node">Code execution | Gemini API | Google AI for Developers</a></li><li><a href="https://github.com/firebase/genkit/releases/tag/0.5.8">Release Genkit JS 0.5.8 · firebase/genkit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5391b45b321" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/getting-started-with-code-execution-in-genkit-c5391b45b321">Unlocking the power of code execution in Genkit</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master Gemma2 and Genkit]]></title>
            <link>https://medium.com/firebase-developers/how-to-develop-using-the-gemma2-model-in-genkit-085f22ce68f3?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/085f22ce68f3</guid>
            <category><![CDATA[gemma2]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[ai-orchestration]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 21:41:52 GMT</pubDate>
            <atom:updated>2025-03-23T06:29:08.437Z</atom:updated>
            <content:encoded><![CDATA[<h4>Local LLM Development Made Easy</h4><p>Google introduced Gemma2, an open-source LLM, in June 2024. This article introduces how to make requests to Gemma2 using Firebase Genkit.</p><h3>Step 1. Installing Ollama Gemma2</h3><p>Using Ollama allows you to run Gemma2 as a local LLM.</p><p>First, install Ollama by following the <a href="https://github.com/ollama/ollama">official guide</a>.</p><p>Next, install Gemma2 using Ollama.</p><pre>ollama run gemma2</pre><p>Currently, Gemma2 is available in three different sizes. However, the 16GB version of Gemma2 was very slow on my Mac, so I used the 5.5GB version. Please install the version that suits your environment when you try it.</p><ul><li>Gemma2 (1.6GB): ollama run gemma2:2b</li><li>Gemma2 (5.5GB): ollama run gemma2</li><li>Gemma2 (16GB): ollama run gemma2:27b</li></ul><p>Once the installation is successful, you can prompt Gemma2 from the command line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y1klproYsxL4iTJoH4EmnA.png" /><figcaption>Ollama CLI</figcaption></figure><h3>Step 2. Creating a Genkit Project</h3><p>Run the following commands to create a Genkit project. Choose Ollama when asked for the <em>model provider</em>.</p><pre>% npm init -y<br>% npm i -D genkit-cli<br>% npm i genkit @genkit-ai/googleai genkitx-ollama<br>% mkdir src &amp;&amp; touch src/index.ts</pre><p>Create a file called src/index.ts and paste the following code:</p><pre>import { genkit, z } from &#39;genkit&#39;<br>import { ollama } from &#39;genkitx-ollama&#39;<br><br>const ai = genkit({<br>  plugins: [<br>    ollama({<br>      models: [{ name: &#39;gemma2&#39; }],<br>      serverAddress: &#39;http://127.0.0.1:11434&#39;,<br>    }),<br>  ],<br>  model: &#39;ollama/gemma2&#39;,<br>})<br><br>const mainFlow = ai.defineFlow(<br>  {<br>    name: &#39;mainFlow&#39;,<br>    inputSchema: z.string(),<br>  },<br>  async input =&gt; {<br>    const { text } = await ai.generate(input)<br>    return text<br>  }<br>)<br><br>ai.startFlowServer({ flows: [mainFlow] })</pre><h3>Step 3. Run locally</h3><p>Start Genkit. The browser will launch when you run the following command.</p><pre>% npx genkit start -- npx tsx --watch src/index.ts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYosOlOmvek4cxMzzr4RiQ.png" /><figcaption>Firebase Genkit Developer tools</figcaption></figure><h3>Conclusion</h3><p>With Genkit and Gemma2, we were able to create a development platform using a local LLM. It’s impressive that this can be achieved in about 30 lines of code with Genkit. I encourage everyone to give it a try.</p><p>The source code is available on GitHub at the following link:</p><p><a href="https://github.com/tanabee/genkit-gemma2-sample">GitHub - tanabee/genkit-gemma2-sample</a></p><h3>Related Posts</h3><ul><li><a href="https://medium.com/firebase-developers/internal-ai-a-genkit-based-internal-ai-chat-released-as-open-source-37795896a106">internal AI: A Genkit-Based Internal AI Chat Released as Open Source!</a></li><li><a href="https://medium.com/firebase-developers/implementing-function-calling-using-genkit-0c03f6cb9179">Implementing Function Calling using Genkit</a></li><li><a href="https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693">High-Precision Responses with Genkit’s Google Search Integration</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=085f22ce68f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/how-to-develop-using-the-gemma2-model-in-genkit-085f22ce68f3">Master Gemma2 and Genkit</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Function Calling using Genkit]]></title>
            <link>https://medium.com/firebase-developers/implementing-function-calling-using-genkit-0c03f6cb9179?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c03f6cb9179</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Tue, 14 May 2024 23:06:12 GMT</pubDate>
            <atom:updated>2025-03-23T06:28:12.574Z</atom:updated>
            <content:encoded><![CDATA[<h4>Genkit Tutorial</h4><h3>Unleash the Power of Function Calling with Genkit</h3><p><a href="https://firebase.google.com/docs/genkit">Genkit</a> was announced at <a href="https://io.google/2024/">Google I/O 2024</a>. In this article, I will show you how to implement Function Calling using Genkit.</p><h3>What is Genkit?</h3><p>Genkit is an open-source framework designed to assist in the development of applications equipped with generative AI features. For those familiar with LangChain, you can think of Genkit as a framework that provides one interface for multiple generative AI models, much like LangChain.</p><p>Genkit is developed by the Firebase team, and its framework interface is user-friendly for Firebase users and other JavaScript / TypeScript developers.</p><p>The programming languages supported are JavaScript, TypeScript, and Go.</p><h3>What are the advantages of using Genkit?</h3><p>One of the biggest advantages of using Genkit is that it allows us to use developer tools locally. By running the following command:</p><pre>npx genkit start -- npx tsx --watch src/index.ts</pre><p>then, the Genkit Developer UI will launch on localhost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZpYWXkBMHS-H-rDeWrMzYg.png" /><figcaption>Genkit local emulator</figcaption></figure><p>Developing generative AI features currently requires significant focus on the AI orchestration. Using developer tools makes the development the AI orchestration much more faster.</p><p>Genkit is developed by the Firebase team, so it is designed to integrate easily with Firebase services. You can easily implement things like Firebase Authentication and the newly announced <a href="https://firebase.google.com/docs/firestore/vector-search">vector search feature in Firestore</a> for implementing RAG.</p><h3>Implementing Function Calling</h3><p>I implemented a feature to scrape web pages and summarize content in Japanese. Although the entire code is presented below, it can be implemented in about 50 lines of code. I will explain each key part below.</p><h4>Full Source Code</h4><pre>import { genkit, z } from &#39;genkit&#39;<br>import { googleAI, gemini15Flash } from &#39;@genkit-ai/googleai&#39;<br>import * as cheerio from &#39;cheerio&#39;<br>import { logger } from &#39;genkit/logging&#39;<br>logger.setLogLevel(&#39;debug&#39;)<br><br>const ai = genkit({<br>  plugins: [googleAI()],<br>  model: gemini15Flash,<br>})<br><br>const webLoader = ai.defineTool(<br>  {<br>    name: &quot;webLoader&quot;,<br>    description:<br>      &quot;When a URL is received, it accesses the URL and retrieves the content inside.&quot;,<br>    inputSchema: z.object({ url: z.string() }),<br>    outputSchema: z.string(),<br>  },<br>  async ({ url }) =&gt; {<br>    const res = await fetch(url)<br>    const html = await res.text()<br>    const $ = cheerio.load(html)<br>    $(&quot;script, style, noscript&quot;).remove()<br>    if ($(&quot;article&quot;)) {<br>      return $(&quot;article&quot;).text()<br>    }<br>    return $(&quot;body&quot;).text()<br>  },<br>)<br><br>const mainFlow = ai.defineFlow({<br>  name: &#39;mainFlow&#39;,<br>  inputSchema: z.string(),<br>}, async (input) =&gt; {<br>  const { text } = await ai.generate({<br>    prompt: `First fetch the content of the URL: ${input}. Next, summarize the content in under 200 words.`,<br>    tools: [webLoader],<br>  })<br>  return text<br>})<br><br>ai.startFlowServer({ flows: [mainFlow] })</pre><h4>defineTool</h4><p>Define the function used for Function Calling with defineTool. Genkit allows for specifying the types of input (inputSchema) and output (outputSchema) values using zod. In this case, cheerio is used to parse web content.</p><pre>const webLoader = ai.defineTool(<br>  {<br>    name: &quot;webLoader&quot;,<br>    description:<br>      &quot;When a URL is received, it accesses the URL and retrieves the content inside.&quot;,<br>    inputSchema: z.object({ url: z.string() }),<br>    outputSchema: z.string(),<br>  },<br>  async ({ url }) =&gt; {<br>    const res = await fetch(url);<br>    const html = await res.text();<br>    const $ = cheerio.load(html);<br>    $(&quot;script, style, noscript&quot;).remove();<br>    if ($(&quot;article&quot;)) {<br>      return $(&quot;article&quot;).text();<br>    }<br>    return $(&quot;body&quot;).text();<br>  },<br>)</pre><p>The functions implemented with defineTool can be shown in the Tools menu, as shown in the screenshot below, allowing for the individual testing of each tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3w7yibZanKU5ZK8qpTV2g.png" /><figcaption>Genkit Tools menu</figcaption></figure><h4>defineFlow</h4><p>In Genkit development, callable functions are implemented as Flows. They are callable in both local and remote environments such as Firebase.</p><pre>const mainFlow = ai.defineFlow({<br>  name: &#39;mainFlow&#39;,<br>  inputSchema: z.string(),<br>}, async (input) =&gt; {<br>  const { text } = await ai.generate({<br>    prompt: `First fetch the content of the URL: ${input}. Next, summarize the content in under 200 words.`,<br>    tools: [webLoader],<br>  })<br>  return text<br>})</pre><p>The functions implemented with defineFlow can be accessed from the Flows menu, as shown in the screenshot below, allowing for local execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3U1I96RuusSRV2Mz6DmQQ.png" /><figcaption>Genkit Flows menu</figcaption></figure><h3>Demo</h3><p>Here is a clip of the flow in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3M5jIe8JNqEawcJxG4iyXQ.gif" /></figure><p>You can follow the execution process of the flow in detail from the inspect tab. This allows for detailed debugging to see if Function Calling was executed correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4E4k462zD8JUe2y5_IBKg.png" /><figcaption>Genkit inspect tab</figcaption></figure><h3>Summary</h3><p>Using Genkit, it was straightforward to implement Function Calling. The ability to implement this in about 50 lines and easily deploy to Cloud Functions for Firebase is very appealing.</p><p>The source code can be accessed from the following link for your reference.</p><p><a href="https://github.com/tanabee/genkit-summarize-webpage/">GitHub - tanabee/genkit-summarize-webpage</a></p><h3>Related Posts</h3><ul><li><a href="https://medium.com/firebase-developers/internal-ai-a-genkit-based-internal-ai-chat-released-as-open-source-37795896a106">internal AI: A Genkit-Based Internal AI Chat Released as Open Source!</a></li><li><a href="https://medium.com/firebase-developers/high-precision-responses-with-genkits-google-search-integration-7f142f5c9693">High-Precision Responses with Genkit’s Google Search Integration</a></li><li><a href="https://medium.com/firebase-developers/how-to-develop-using-the-gemma2-model-in-genkit-085f22ce68f3">Master Gemma2 and Genkit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c03f6cb9179" width="1" height="1" alt=""><hr><p><a href="https://medium.com/firebase-developers/implementing-function-calling-using-genkit-0c03f6cb9179">Implementing Function Calling using Genkit</a> was originally published in <a href="https://medium.com/firebase-developers">Firebase Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 30 Useful Google Apps Script Snippets]]></title>
            <link>https://medium.com/google-developer-experts/top-30-useful-google-apps-script-snippets-8ad13077530f?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ad13077530f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google-workspace]]></category>
            <category><![CDATA[apps-script]]></category>
            <category><![CDATA[spreadsheets]]></category>
            <category><![CDATA[google-apps-script]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Mon, 19 Oct 2020 14:24:44 GMT</pubDate>
            <atom:updated>2020-10-21T15:03:19.064Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMZrVUrgB7QzaP46TLPxhw.png" /></figure><p><em>Here are my favorite 30 Google Apps Script snippets. These snippets will save your time.</em></p><h3>SpreadsheetApp</h3><h4>Access to Spreadsheet ( standalone scripts )</h4><pre>const spreadsheet = SpreadsheetApp.openById(&quot;Spreadsheet ID&quot;)</pre><p><em>Spreadsheet ID</em> can be obtained from the spreadsheet URL</p><p>https://docs.google.com/spreadsheets/d/[ <em>Spreadsheet ID</em> ]/edit</p><h4>Access to Spreadsheet ( Container-bound scripts )</h4><pre>const spreadsheet = SpreadsheetApp.getActive()</pre><h4>Get values</h4><pre>const values = spreadsheet<br>  .getSheetByName(&#39;sheet name&#39;)<br>  .getDataRange()<br>  .getValues()</pre><h4>Set values</h4><pre>spreadsheet<br>  .getRange(range)<br>  .setValues(values)</pre><h4>Add custom menu</h4><pre>const onOpen = () =&gt; {<br>  SpreadsheetApp<br>    .getActiveSpreadsheet()<br>    .addMenu(&#39;Menu name&#39;, [<br>      {name: &#39;sub menu name 1&#39;, functionName: &#39;functionName1&#39;},<br>      {name: &#39;sub menu name 2&#39;, functionName: &#39;functionName2&#39;},<br>    ])<br>}</pre><h4>onEdit trigger</h4><pre>const onEdit = e =&gt; {<br>  const { range, oldValue, value } = e<br>}</pre><h4>onSelectionChange trigger</h4><pre>const onSelectionChange = e =&gt; {<br>  const { range, user } = e<br>}</pre><h3>Google Calendar</h3><h4>Create event</h4><pre>CalendarApp.getDefaultCalendar().createEvent(title, start, end)</pre><h4>Get events</h4><pre>const events = CalendarApp<br>  .getDefaultCalendar()<br>  .getEvents(start, end)<br>  .map(event =&gt; ({<br>    title: event.getTitle(),<br>    description: event.getDescription(),<br>    start: event.getStartTime(),<br>    end: event.getEndTime()<br>  }))</pre><p>You can get other properties from <a href="https://developers.google.com/apps-script/reference/calendar/calendar-event">CalendarEvent</a> class</p><h4>Access to not default calendar</h4><pre>const calendar = CalendarApp.getCalendarById(&#39;Calendar ID&#39;)</pre><h3>Gmail</h3><h4>Send Email</h4><pre>GmailApp.sendEmail(&#39;tanabee@example.com&#39;, &#39;subject&#39;, &#39;body&#39;)</pre><h4>Search threads</h4><p>If you’d like to get 10 latest threads,</p><pre>const threads = GmailApp.search(&#39;&#39;, 0, 10)</pre><p>You can set <a href="https://support.google.com/mail/answer/7190?hl=en">search operators</a> as the first argument.</p><h4>Get messages</h4><pre>const messages = GmailApp.search(&#39;&#39;, 0, 10).flatMap(thread =&gt; <br>  thread.getMessages().map(message =&gt; ({<br>    subject: message.getSubject(),<br>    body: message.getBody(),<br>    date: message.getDate(),<br>    from: message.getFrom(),<br>    to: message.getTo(),<br>  }))<br>)</pre><p>You can get other properties from <a href="https://developers.google.com/apps-script/reference/gmail/gmail-message">GmailMessage</a> class</p><h3>Google Drive</h3><h4>Get folders and files in the specific folder</h4><pre>const folder = DriveApp.getFolderById(&#39;Folder ID&#39;)</pre><pre>const files = folder.getFiles()<br>while (files.hasNext()) {<br>  let file = files.next()<br>  console.log(&#39;file: &#39;, file.getName())<br>}</pre><pre>const folders = folder.getFolders()<br>while (folders.hasNext()) {<br>  let folder = folders.next()<br>  console.log(&#39;folder: &#39;, folder.getName())<br>}</pre><h3>Google Form</h3><h3>Get input values</h3><pre>const onSubmit = event =&gt; {<br>  const answer = event.response<br>    .getItemResponses()<br>    .map(itemResponse =&gt; ({<br>      item: itemResponse.getItem().getTitle(),<br>      response: itemResponse.getResponse()<br>    }))<br>}</pre><p>You need to add form submit trigger.</p><h3>Google Document</h3><h4>Access to Google Document ( standalone scripts )</h4><pre>const doc = DocumentApp.openById(&#39;Document ID&#39;)</pre><p><em>Document ID</em> can be obtained from the spreadsheet URL</p><p>https://docs.google.com/document/d/[ <em>Document ID</em> ]/edit</p><h4>Access to Google Document ( Container-bound scripts )</h4><pre>const doc = DocumentApp.getActiveDocument()</pre><h4>Add custom menu</h4><pre>const onOpen = () =&gt; {<br>  DocumentApp<br>    .getUi()<br>    .createMenu(&#39;menu name&#39;)<br>    .addItem(&#39;item name&#39;, &#39;functionName&#39;)<br>    .addToUi()<br>}</pre><h3>Utilities</h3><h4>Format date</h4><pre>const date = Utilities.formatDate(new Date(), &#39;Asia/Tokyo&#39;, &#39;YYYY-MM-dd HH:mm:ss&#39;)</pre><h4>sleep</h4><p>If you want the script to sleep for 1 second</p><pre>Utilities.sleep(1000)</pre><h4>Generate UUID</h4><pre>const uuid = Utilities.getUuid()</pre><h3>Trigger</h3><h4>Execute a function after 1 minute</h4><p>Google Apps Script has a <a href="https://developers.google.com/apps-script/guides/services/quotas#current_limitations">limitation</a> of script runtime. If you want the script to work more than the limit, you can schedule the next execution in advance.</p><pre>const date = new Date()<br>date.setMinutes(date.getMinutes() + 1);// after 1 min<br>ScriptApp.newTrigger(&#39;functionName&#39;).timeBased().at(date).create();</pre><h3>PropertiesService</h3><h4>Get property</h4><pre>const value = PropertiesService.getScriptProperties().getProperty(key)</pre><h4>Set property</h4><pre>PropertiesService.getScriptProperties().setProperty(key, value)</pre><h3>LanguageApp</h3><h4>translation</h4><pre>const text = LanguageApp.translate(&#39;Hello World&#39;, &#39;en&#39;, &#39;ja&#39;)</pre><h3>Web Apps</h3><h4>Website ( no HTML template )</h4><pre>const doGet = e =&gt; {<br>  const params = JSON.stringify(e.parameter)<br>  return HtmlService.createHtmlOutput(params)<br>}</pre><h4>Website ( with HTML template )</h4><pre>const doGet = e =&gt; {<br>  return HtmlService.createHtmlOutputFromFile(&#39;index&#39;)<br>}</pre><p>You need to create index.html file.</p><h4>GET API</h4><p>You can get query string with accessing e.parameter.</p><pre>const doGet = e =&gt; {<br>  const params = JSON.stringify(e.parameter)<br>  return ContentService<br>    .createTextOutput(params)<br>    .setMimeType(MimeType.JSON)<br>}</pre><h4>POST API</h4><p>You can get request body with accessing e.postData.contents.</p><pre>const doPost = e =&gt;  {<br>  const body = e.postData.contents<br>  return ContentService<br>    .createTextOutput(body)<br>    .setMimeType(ContentService.MimeType.JSON)<br>}</pre><h3>UrlFetchApp</h3><p>You can access other resources when using UrlFetchApp class.</p><h4>GET API request</h4><pre>const content = UrlFetchApp.fetch(url).getContentText()</pre><h4>POST API request</h4><pre>const res = UrlFetchApp.fetch(url, {<br>  method: &#39;POST&#39;,<br>  headers: { &quot;Content-Type&quot;: &#39;application/json&#39; },<br>  payload: JSON.stringify(data)<br>})</pre><p>Thank you for reading this article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ad13077530f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-developer-experts/top-30-useful-google-apps-script-snippets-8ad13077530f">Top 30 Useful Google Apps Script Snippets</a> was originally published in <a href="https://medium.com/google-developer-experts">Google Developer Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[G Suite x Zendesk API で問い合わせの分析・可視化ツールを作ってみた]]></title>
            <link>https://medium.com/google-cloud-jp/g-suite-x-zendesk-api-%E3%81%A7%E5%95%8F%E3%81%84%E5%90%88%E3%82%8F%E3%81%9B%E3%81%AE%E5%88%86%E6%9E%90-%E5%8F%AF%E8%A6%96%E5%8C%96%E3%83%84%E3%83%BC%E3%83%AB%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F-9aa831c1bf0e?source=rss-3cebc6128b6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aa831c1bf0e</guid>
            <category><![CDATA[data-studio]]></category>
            <category><![CDATA[g-suite]]></category>
            <category><![CDATA[google-apps-script]]></category>
            <dc:creator><![CDATA[tanabee]]></dc:creator>
            <pubDate>Wed, 17 Jul 2019 12:40:26 GMT</pubDate>
            <atom:updated>2019-07-17T12:40:26.488Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*h0BopqaYA2vAumAdaBf_nw.jpeg" /><figcaption>システムの全体像</figcaption></figure><h3>はじめに</h3><p>Zendesk はヘルプページを作ったりユーザーからの問い合わせにメールやチャットベースで答えられるカスタマーサポートのためのサービスです。</p><p>弊社では Zendesk を利用しており、サービス改善のために問い合わせの内容を閲覧・分析しています。カスタマーサポートを業務で行わないが、プロダクト改善をしたい社内メンバー向けに、Zendesk API をたたいて可視化・分析する仕組みを G Suite で作ってみました。</p><p>Zendesk に限らず、外部サービスで API が用意されているものでしたら同様に可視化・分析の仕組みを作れるので参考にしてみてください。</p><h3>できたもの</h3><h4>ダッシュボード</h4><p>Weekly と Monthly の問い合わせ件数を Data Studio で可視化しています。問い合わせのタグや文言で絞り込みができます。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RoZxIAM_GHqgYjzL-XdMQw.png" /><figcaption>DataStudio によるダッシュボード</figcaption></figure><h4>問い合わせ履歴表示</h4><p>Google Apps Script で生成した Web ページで問い合わせのログを閲覧できます。最初の問い合わせ内容と、その後のユーザーとのメールのやり取りを閲覧できるようになります。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*k0Ur4s4IhGkX4Opq8kjtfw.png" /><figcaption>Google Apps Script を使った Web 表示</figcaption></figure><h3>使用技術</h3><h4>Zendesk API</h4><p>Zendesk から情報取得するために Zendesk API を叩きました。チケット一覧とコメント一覧の GET API を叩いています。</p><p><a href="https://developer.zendesk.com/rest_api/docs/support/introduction">Introduction - Support API - Zendesk Developer Portal</a></p><h4>Google Apps Script</h4><p>Google Apps Script で以下の機能をもたせています。</p><ul><li>Zendesk API をたたいて問い合わせ情報を抽出（URLFetchApp）</li><li>Spreadsheet に保存する</li><li>上記処理を日時バッヂで実行（時間主導型トリガー利用）</li><li>チケット ID を指定して、問い合わせ対応の履歴が追える Web ページ生成</li></ul><h4>Data Studio</h4><p>Spreadsheet に保存された問い合わせ情報をダッシュボード表示するために利用します。Spreadsheet を用いて集計・分析もできますが、今回は Spreadsheet をデータベース的に利用して、社内メンバーに閲覧権限のみをつけました。DataStudio を使うと、期間指定やプルダウン、文字列検索による絞り込みも直感的にできるので、エンジニア外のメンバーに渡すのに便利です。</p><h3>実装と利用方法</h3><p>実装と利用方法については GitHub にまとめています。興味のある方は使ってみてください。</p><p><a href="https://github.com/tanabee/zendesk-to-spreadsheet">tanabee/zendesk-to-spreadsheet</a></p><h3>まとめ</h3><p>G Suite の Google Apps Script と DataStudio を活用して、外部サービスのデータ可視化・分析の仕組みを作れました。 Zendesk に限らずこういったニーズはあると思いますので、皆さんも試してみてください。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aa831c1bf0e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud-jp/g-suite-x-zendesk-api-%E3%81%A7%E5%95%8F%E3%81%84%E5%90%88%E3%82%8F%E3%81%9B%E3%81%AE%E5%88%86%E6%9E%90-%E5%8F%AF%E8%A6%96%E5%8C%96%E3%83%84%E3%83%BC%E3%83%AB%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F-9aa831c1bf0e">G Suite x Zendesk API で問い合わせの分析・可視化ツールを作ってみた</a> was originally published in <a href="https://medium.com/google-cloud-jp">google-cloud-jp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>