<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Lawrence Wu</title>
<link>https://lawrencewu.net/til/</link>
<atom:link href="https://lawrencewu.net/til/index.xml" rel="self" type="application/rss+xml"/>
<description>Short notes on things I picked up along the way — tools, models, Python, and the odd life admin.</description>
<generator>quarto-1.11.9</generator>
<lastBuildDate>Tue, 26 Aug 2025 00:00:00 GMT</lastBuildDate>
<item>
  <title>Exporting Hyprnote to Obsidian</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-08-26-hyprnote-and-obsidian/</link>
  <description><![CDATA[ 





<p>I started using <a href="https://github.com/fastrepl/hyprnote">Hyprnote</a> a <a href="../2025-08-05-hyprnote-transcribe-meetings/">couple weeks ago</a>. I’ve found it useful transcribing meetings so I do not need to take copius notes since I can always rely on the transcript.</p>
<p>I learned today you can export the Hyprnote AI Summary and full transcript to Obsidian.</p>
<p>To do this:</p>
<ul>
<li>Install the community plugin <a href="https://github.com/coddingtonbear/obsidian-local-rest-api">local REST API</a> for Obsidian</li>
<li>Click the checkbox to “Enable Non-Encrypted HTTP Server”, copy the API Key</li>
<li>In Hypernote –&gt; Settings –&gt; Integrations tab –&gt; paste the API Key. You can also configure the folder these notes to a specific Obsidian folder.</li>
<li>In Hypernote –&gt; From any note, you can click Share and you should see the notes exported to Obsidian.</li>
</ul>



 ]]></description>
  <category>whisper</category>
  <guid>https://lawrencewu.net/til/posts/2025-08-26-hyprnote-and-obsidian/</guid>
  <pubDate>Tue, 26 Aug 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Using Hyprnote to Transcribe Meetings</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-08-05-hyprnote-transcribe-meetings/</link>
  <description><![CDATA[ 





<p>I learned about <a href="https://github.com/fastrepl/hyprnote">Hyprnote</a>, a small application that uses local LLMs to transcribe meetings. I’ve been using it the last week or so. It’s surprisingly useful: I no longer have to go to Sharepoint to download transcripts for Teams calls (and request access for them if I was not the owner of the meeting) and I also get transcripts for non-Teams calls. Because this all runs locally, no data is leaving my Mac.</p>
<p>There are basically 4 panes:</p>
<ul>
<li>Left-hand side bar that shows the previous meetings</li>
<li>Middle bar that shows either notes you take (in Markdown) or a generated summary of the meeting</li>
<li>Right-hand side that shows the transcription (with speaker diarization)</li>
<li>You can chat with your transcript too</li>
</ul>
<p>For transcription, they are leveraging the <a href="https://github.com/openai/whisper">whisper</a> models. I’m using Large which turns out to be <code>ggml-large-v3-turbo-q8_0.bin</code>.</p>
<p>For summaries, they are leveraging a custom model called <code>hypr-llm.gguf</code> that is 1.11GB.</p>



 ]]></description>
  <category>whisper</category>
  <guid>https://lawrencewu.net/til/posts/2025-08-05-hyprnote-transcribe-meetings/</guid>
  <pubDate>Mon, 04 Aug 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>US Online Passport Renewal</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-07-07-online-passport-renewal/</link>
  <description><![CDATA[ 





<p>Based on this WSJ article, <a href="https://www.wsj.com/business/us-passport-online-renewal-e58b51d1">America Has Pulled Off the Impossible. It Made Getting a Passport Simple</a>, I learned that it’s now possible to renew your US Passport online. I thought this was too good to be true so I tried going through the process. I found out I was <a href="https://travel.state.gov/content/travel/en/passports/have-passport/renew-online.html">eligible</a>!</p>
<p>The main points of eligibility are below. Too bad you cannot do this for kids.</p>
<ul>
<li>The passport you are renewing is or was valid for 10 years, and you are age 25 or older.</li>
<li>The passport you are renewing is either expiring within one year or has expired less than five years ago.</li>
<li>You are not changing your name, sex, date of birth, or place of birth.</li>
<li>You are not traveling for at least 6 weeks from the date you will submit your application. We will only offer routine service, and the time it takes to get a passport will be the same as renewing by mail.</li>
</ul>
<p>The process was pretty easy on a phone:</p>
<ul>
<li>fill out some personal data</li>
<li>take a picture of yourself (the service will automatically crop your picture). Though it doesn’t accept HEIC images, only JPEG less than 10mb so I had to convert HEIC to JPEG and shrink it a little to upload it.</li>
</ul>
<p>The application process was relatively pain-free and I was delightfully surprised. Gone are the days of making an appointment at a post office, paying for passport pictures. Love it.</p>
<p>Timeline:</p>
<ul>
<li>2025-07-07 - Applied, Payment Pending</li>
<li>2025-07-09 - U.S. Department of State has received your application. Application Status: In Process</li>
<li>2025-07-10, 8pm - Approved</li>
<li>2025-07-10, 10:30pm - Shipped</li>
<li>2025-07-11 - Printing and preparing to give it to you. (I thought it was shipped already??)</li>
<li>2025-07-15 - Received the passport in the mail!</li>
</ul>



 ]]></description>
  <category>random</category>
  <guid>https://lawrencewu.net/til/posts/2025-07-07-online-passport-renewal/</guid>
  <pubDate>Mon, 07 Jul 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Learnings from Building Multi-Agent Systems</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-06-17-anthropic-multi-agent-systems/</link>
  <description><![CDATA[ 





<p>Some takeaways from reading Anthropic’s fantastic post on <a href="https://www.anthropic.com/engineering/built-multi-agent-research-system">How we built our multi-agent research system</a>. This is <a href="https://simonwillison.net/2025/Jun/14/multi-agent-research-system/">Simon Willison’s thoughts on the post too</a>. I can tell it’s written by someone or a team that has spent time in the trenches building and architecting this system.</p>
<p>These two diagrams were helpful. I’ve been seeing these process diagrams more. I wonder if it’s because AI can generate these diagrams easily and so developers are including them in documentation more.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2025-06-17-anthropic-multi-agent-systems/mas_high_level.png" class="img-fluid figure-img"></p>
<figcaption>High-Level Architecture</figcaption>
</figure>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2025-06-17-anthropic-multi-agent-systems/mas_process_diagram.png" class="img-fluid figure-img"></p>
<figcaption>Process Diagram</figcaption>
</figure>
</div>
<p>Some learnings:</p>
<ul>
<li>Multi-Agent Systems (MAS) are good for breadth-first search queries</li>
<li>MAS work because they spend enough tokens to solve the problem - increased token usage explained 80% of the variance</li>
<li>MAS are much more expensive: agents use 4x more tokens than chats and Multi-Agent systems us 15x more tokens than chats</li>
<li>I learned about <a href="https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#interleaved-thinking">Interleaved thinking</a> - which enables Claude to think between tool calls and make more sophisticated reasoning after receiving tool results. Google’s Gemini 2.5 models also <a href="https://ai.google.dev/gemini-api/docs/thinking">do this</a>.</li>
<li>Prompt Engineering is still massively important in creating Multi-Agent systems - prompting the orchestrator to delegate well
<ul>
<li>“Agent-tool interfaces are as critical as human-computer interfaces. Using the right tool is efficient—often, it’s strictly necessary. For instance, an agent searching the web for context that only exists in Slack is doomed from the start. With <a href="https://modelcontextprotocol.io/introduction">MCP servers</a> that give the model access to external tools, this problem compounds, as agents encounter unseen tools with descriptions of wildly varying quality. We gave our agents explicit heuristics: for example, examine all available tools first, match tool usage to user intent, search the web for broad external exploration, or prefer specialized tools over generic ones. Bad tool descriptions can send agents down completely wrong paths, so each tool needs a distinct purpose and a clear description.””</li>
<li>Thought this tool-testing agent was cool “<strong>Let agents improve themselves</strong>. We found that the Claude 4 models can be excellent prompt engineers. When given a prompt and a failure mode, they are able to diagnose why the agent is failing and suggest improvements. We even created a tool-testing agent—when given a flawed MCP tool, it attempts to use the tool and then rewrites the tool description to avoid failures. By testing the tool dozens of times, this agent found key nuances and bugs. This process for improving tool ergonomics resulted in a 40% decrease in task completion time for future agents using the new description, because they were able to avoid most mistakes.””</li>
</ul></li>
</ul>
<p>They also have a section on Evaluations that was helpful:</p>
<ul>
<li>Starting evals with small samples</li>
<li>“We experimented with multiple judges to evaluate each component, but found that a single LLM call with a single prompt outputting scores from 0.0-1.0 and a pass-fail grade was the most consistent and aligned with human judgements.””</li>
<li>Still having human evals after implementing automated LLM-as-judge evals</li>
</ul>



 ]]></description>
  <category>llms</category>
  <category>agents</category>
  <guid>https://lawrencewu.net/til/posts/2025-06-17-anthropic-multi-agent-systems/</guid>
  <pubDate>Tue, 17 Jun 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Lethal Trifecta for AI Agents</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-06-17-lethal-trifecta/</link>
  <description><![CDATA[ 





<p>Simon Willison coined a new term called the <a href="https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/">lethal trifecta</a>. As someone that uses AI every day and has been experimenting with MCP Servers in the last few months, I was surprised at the new attack vectors that MCP Servers unlock.</p>
<p>The lethal trifecta is to quote Simon:</p>
<ul>
<li><strong>Access to your private data</strong> — one of the most common purposes of tools in the first place!</li>
<li><strong>Exposure to untrusted content</strong> — any mechanism by which text (or images) controlled by a malicious attacker could become available to your LLM</li>
<li><strong>The ability to externally communicate</strong> in a way that could be used to steal your data (I often call this “exfiltration” but I’m not confident that term is widely understood.)</li>
</ul>
<p>Github’s MCP server <a href="https://simonwillison.net/2025/May/26/github-mcp-exploited/">exploit from May 2025</a> is an example of this.</p>



 ]]></description>
  <category>llms</category>
  <category>agents</category>
  <category>hacking</category>
  <guid>https://lawrencewu.net/til/posts/2025-06-17-lethal-trifecta/</guid>
  <pubDate>Tue, 17 Jun 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>OpenAI’s Responses API</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-05-22-responses-api/</link>
  <description><![CDATA[ 





<p>OpenAI’s Responses API is becoming an Agent API from Steven Heidel’s <a href="https://x.com/stevenheidel/status/1925209983073046616">tweet</a>:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2025-05-22-responses-api/responses_api_tweet.png" class="img-fluid figure-img"></p>
<figcaption>Responses API Tweet</figcaption>
</figure>
</div>
<p>Pretty interesting how OpenAI is moving up the stack where with an API call you can basically configure a tool calling <a href="https://arxiv.org/abs/2210.03629">ReAct agent</a>. Over the last year, agent framework SDKs like <a href="https://github.com/langchain-ai/langgraph">LangGraph</a> provide utilities to <a href="https://python.langchain.com/api_reference/langchain/agents/langchain.agents.react.agent.create_react_agent.html">create react agents</a>. Now with the Responses API, you can create this tool calling agent that can call remote MCP servers, code interpreter, RAG, image generation and we search tools natively.</p>
<p>Docs: <a href="https://openai.com/index/new-tools-and-features-in-the-responses-api/" class="uri">https://openai.com/index/new-tools-and-features-in-the-responses-api/</a></p>



 ]]></description>
  <category>llms</category>
  <category>apis</category>
  <guid>https://lawrencewu.net/til/posts/2025-05-22-responses-api/</guid>
  <pubDate>Wed, 21 May 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Royalty Free Music</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-05-10-royalty-free-music/</link>
  <description><![CDATA[ 





<p>YouTube really is such an amazing resource. I make home videos and sometimes need background music. This playlist called <a href="https://www.youtube.com/playlist?list=PL7pkSK1xbGD6g2_BSXgScugMC1CJkkdBW">Upbeat No Copyright Music</a> has provided some great background music for some of my videos.</p>
<p>You can use <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> to download the playlist:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">yt-dlp</span> https://www.youtube.com/playlist<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">?</span>list=PL7pkSK1xbGD6g2_BSXgScugMC1CJkkdBW</span></code></pre></div></div>
<p>But this will download the videos which are unnecessary. To download only mp3s, you can use this command:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">yt-dlp</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-f</span> bestaudio <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--extract-audio</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--audio-format</span> mp3 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--audio-quality</span> 0 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-o</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%(playlist_index)s - %(title)s.%(ext)s"</span> https://www.youtube.com/playlist<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">?</span>list=PL7pkSK1xbGD6g2_BSXgScugMC1CJkkdBW</span></code></pre></div></div>



 ]]></description>
  <category>music</category>
  <guid>https://lawrencewu.net/til/posts/2025-05-10-royalty-free-music/</guid>
  <pubDate>Sat, 10 May 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Qwen-3’s Chat Template</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-05-02-qwen3-chat-prompt-template/</link>
  <description><![CDATA[ 





<p>I didn’t realize how complicated Chat Templates have become now. This <a href="https://huggingface.co/blog/qwen-3-chat-template-deep-dive">Huggingface blogpost</a> goes through Qwen 3’s prompt template.</p>
<p>The chat template defines “how conversations between users and models are structured and formatted. The template acts as a translator, converting a human-readable conversation:”</p>
<p>For example:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb1-1">  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">[</span></span>
<span id="cb1-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hi there!"</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"assistant"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hi there, how can I help you today?"</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"I'm looking for a new pair of shoes."</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-5">  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">]</span></span></code></pre></div></div>
<p>is converted into a model friendly format by the chat template:</p>
<pre class="text"><code>&lt;|im_start|&gt;user
Hi there!&lt;|im_end|&gt;
&lt;|im_start|&gt;assistant
Hi there, how can I help you today?&lt;|im_end|&gt;
&lt;|im_start|&gt;user
I'm looking for a new pair of shoes.&lt;|im_end|&gt;
&lt;|im_start|&gt;assistant
&lt;think&gt;

&lt;/think&gt;</code></pre>
<p>For example, Qwen-3’s chat template has this feature:</p>
<ul>
<li>turning off reasoning with the <code>enable_thinking</code> flag. If this is set to false, the template inserts an empty <code>&lt;think&gt;&lt;/think&gt;</code> pair.</li>
</ul>
<pre class="text"><code>{# Qwen-3 #}
{%- if enable_thinking is defined and enable_thinking is false %}
    {{- '&lt;think&gt;\n\n&lt;/think&gt;\n\n' }}
{%- endif %}</code></pre>
<p>The templates are all available on Huggingface for open source models, e.g.&nbsp;<a href="https://huggingface.co/Qwen/Qwen3-235B-A22B?chat_template=default">Qwen3</a>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tools</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;system\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages[0].role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'system'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-4">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages[0].content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"# Tools</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">You may call one or more functions to assist with the user query.</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">You are provided with function signatures within &lt;tools&gt;&lt;/tools&gt; XML tags:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;tools&gt;"</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">for</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">in</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tools</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-9">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">|</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tojson</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endfor</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/tools&gt;</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">For each function call, return a json object with function name and arguments within &lt;tool_call&gt;&lt;/tool_call&gt; XML tags:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;tool_call&gt;</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">{</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">: &lt;function-name&gt;, </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">arguments</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">: &lt;args-json-object&gt;}</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/tool_call&gt;&lt;|im_end|&gt;</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">else</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages[0].role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'system'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-14">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;system\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages[0].content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_end|&gt;\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">ns</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">namespace(multi_step_tool=true,</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">last_query_index=messages|length</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">1)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">for</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">in</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages[</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">]</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">index</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(messages|length</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">1)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.index0</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">ns.multi_step_tool</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"user"</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">not(message.content.startswith('&lt;tool_response&gt;')</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content.endswith('&lt;/tool_response&gt;'))</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-21">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">ns.multi_step_tool</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">false</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-22">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">ns.last_query_index</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">index</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endfor</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">for</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">in</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">messages</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"user"</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"system"</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">not</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.first)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-27">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_end|&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-28">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">elif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"assistant"</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-29">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-30">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">''</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-31">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">is</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">defined</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">is</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">not</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">none</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-32">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-33">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">else</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-34">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;/think&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">in</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-35">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content.split('&lt;/think&gt;')[-1].lstrip('\n')</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-36">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">reasoning_content</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content.split('&lt;/think&gt;')[0].rstrip('\n').split('&lt;think&gt;')[-1].lstrip('\n')</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-37">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-38">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-39">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.index0</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">ns.last_query_index</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-40">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.last</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(not</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.last</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">reasoning_content)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-41">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n&lt;think&gt;\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">reasoning_content.strip('\n')</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n&lt;/think&gt;\n\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content.lstrip('\n')</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-42">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">else</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-43">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-44">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-45">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">else</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-46">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-47">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-48">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.tool_calls</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-49">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">for</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">in</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.tool_calls</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-50">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(loop.first</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">content)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(not</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.first)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-51">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-52">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-53">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call.function</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-54">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">set</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call.function</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-55">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-56">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;tool_call&gt;\n{</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"name"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"' }}</span></span>
<span id="cb4-57"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                {{- tool_call.name }}</span></span>
<span id="cb4-58"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                {{- '"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"arguments"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-59">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call.arguments</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">is</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">string</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-60">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call.arguments</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-61">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">else</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-62">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tool_call.arguments</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">|</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">tojson</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-63">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-64">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">\n&lt;/tool_call&gt;'</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}}</span></span>
<span id="cb4-65">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endfor</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-66">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-67">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_end|&gt;\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-68">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">elif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">==</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"tool"</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-69">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.first</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(messages[loop.index0</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">1].role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">!=</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"tool"</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-70">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;user'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-71">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-72">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n&lt;tool_response&gt;\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-73">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">message.content</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-74">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'\n&lt;/tool_response&gt;'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-75">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">loop.last</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(messages[loop.index0</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">+</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">1].role</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">!=</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"tool"</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">)</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-76">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_end|&gt;\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-77">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-78">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-79"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endfor</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-80"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">add_generation_prompt</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-81">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;|im_start|&gt;assistant\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-82">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">if</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">enable_thinking</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">is</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">defined</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">enable_thinking</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">is</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">false</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-83">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">{-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">'&lt;think&gt;\n\n&lt;/think&gt;\n\n'</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-84">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-85"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%-</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">endif</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">%</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div></div>



 ]]></description>
  <category>llm</category>
  <guid>https://lawrencewu.net/til/posts/2025-05-02-qwen3-chat-prompt-template/</guid>
  <pubDate>Fri, 02 May 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Deep Wiki</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-04-25-deep-wiki/</link>
  <description><![CDATA[ 





<p>From this <a href="https://x.com/cognition_labs/status/1915816544480989288?s=46&amp;t=Ze-VKnGNxPI5bjU_St2Wbg">post</a>, I learned that Cognition, the company behind Devin created <a href="https://deepwiki.com/">DeepWiki</a>. They’re calling it a “Deep Research for Github.” They created explainer-wiki style web pages for the top 30,000 most popular Github repos.</p>
<p>From Silas Alberti, he <a href="https://x.com/silasalberti/status/1915821553465626791">said</a>:</p>
<ul>
<li>30k repos already indexed</li>
<li>processed 4 billion+ lines of code</li>
<li>the indexing alone cost $300k+ in compute</li>
</ul>
<p>Some interesting points he makes in his thread:</p>
<ul>
<li>indexing a single repo costs $12 on average</li>
<li>models are very good at understanding code locally. the hard part is understanding the global structure of the codebase.</li>
<li>DeepWiki breaks down a codebase into a hierarchy of high-level systems and then generates a wiki page for every system</li>
<li>one interesting signal that we’re able to leverage is the commit history. who tends to touch which files together? you can represent this as a graph.</li>
</ul>
<p>You can also do Q&amp;A on each project after clicking into it. I looked at a handful of examples and can see how valuable this is.</p>
<p>Some ones I briefly looked at:</p>
<ul>
<li><a href="https://deepwiki.com/pandas-dev/pandas" class="uri">https://deepwiki.com/pandas-dev/pandas</a></li>
<li><a href="https://deepwiki.com/langchain-ai/langgraph" class="uri">https://deepwiki.com/langchain-ai/langgraph</a></li>
<li><a href="https://deepwiki.com/BerriAI/litellm" class="uri">https://deepwiki.com/BerriAI/litellm</a></li>
<li><a href="https://deepwiki.com/modelcontextprotocol/modelcontextprotocol" class="uri">https://deepwiki.com/modelcontextprotocol/modelcontextprotocol</a></li>
</ul>
<p>The generated diagrams are nice: <img src="https://lawrencewu.net/til/posts/2025-04-25-deep-wiki/deepwiki_mcp_diagram.png" class="img-fluid" alt="MCP Diagram"></p>
<p>A lot of MCP servers are already in the top 30k repos: <img src="https://lawrencewu.net/til/posts/2025-04-25-deep-wiki/deepwiki_mcp_repos.png" class="img-fluid" alt="MCP Repos"></p>



 ]]></description>
  <category>llm</category>
  <guid>https://lawrencewu.net/til/posts/2025-04-25-deep-wiki/</guid>
  <pubDate>Fri, 25 Apr 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>uv and Python projects</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-03-18-uv-python-projects/</link>
  <description><![CDATA[ 





<p>I learned recently you can use uv to install Python. Likely will use uv instead of <code>pyenv</code> to install and manage Python versions going forward.</p>
<p>There also seems to be a tipping point where it is moving from the tool you would use to install requirements with <code>uv pip install -r requirements.txt</code> to the all-in-one tool to install Python, manage dependencies and setup your Python project too.</p>
<p>Some project templates that look interesting:</p>
<ul>
<li><a href="https://github.com/jlevy/simple-modern-uv">simple-modern-uv</a></li>
<li><a href="https://github.com/fpgmaas/cookiecutter-uv">cookiecutter-uv</a></li>
<li><a href="https://github.com/pawamoy/copier-uv">copier-uv</a></li>
</ul>
<p>I also learned about <a href="https://github.com/copier-org/copier">copier</a> which is a format templates can follow which allows you to <a href="https://github.com/jlevy/simple-modern-uv#updating-your-project-template">pull future changes to the template</a> back into your project.</p>



 ]]></description>
  <category>python</category>
  <guid>https://lawrencewu.net/til/posts/2025-03-18-uv-python-projects/</guid>
  <pubDate>Tue, 18 Mar 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>src layout vs flat layout in Python projects</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-03-18-flat-vs-src-layouts/</link>
  <description><![CDATA[ 





<p>I haven’t seen these terms “src layout” and “flat layout” before when referring to Python project conventions that put source code in either a top level folder that is the package name or nesting it under a <code>src/</code> folder. This <a href="https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/">article</a> provides a lot of detail and actually some reasons why a <code>src/</code> layout is probably better. Also reading this <a href="https://packaging.python.org/en/latest/overview/">Overview of Python Packaging</a> was very informative too.</p>
<p>Quoting the article:</p>
<p>The “flat layout” refers to organising a project’s files in a folder or repository, such that the various configuration files and import packages are all in the top-level directory.</p>
<pre class="text"><code>.
├── README.md
├── noxfile.py
├── pyproject.toml
├── setup.py
├── awesome_package/
│   ├── __init__.py
│   └── module.py
└── tools/
    ├── generate_awesomeness.py
    └── decrease_world_suck.py</code></pre>
<p>The “src layout” deviates from the flat layout by moving the code that is intended to be importable (i.e.&nbsp;import awesome_package, also known as import packages) into a subdirectory. This subdirectory is typically named src/, hence “src layout”.</p>
<pre class="text"><code>.
├── README.md
├── noxfile.py
├── pyproject.toml
├── setup.py
├── src/
│    └── awesome_package/
│       ├── __init__.py
│       └── module.py
└── tools/
    ├── generate_awesomeness.py
    └── decrease_world_suck.py</code></pre>
<p>Here’s a breakdown of the important behaviour differences between the src layout and the flat layout:</p>
<ul>
<li>The src layout requires installation of the project to be able to run its code, and the flat layout does not.
<ul>
<li>This means that the src layout involves an additional step in the development workflow of a project (typically, an <a href="https://setuptools.pypa.io/en/latest/userguide/development_mode.html">editable installation</a> is used for development and a regular installation is used for testing).</li>
</ul></li>
<li>The src layout helps prevent accidental usage of the in-development copy of the code.
<ul>
<li>This is relevant since the Python interpreter includes the current working directory as the first item on the import path. This means that if an import package exists in the current working directory with the same name as an installed import package, the variant from the current working directory will be used. This can lead to subtle misconfiguration of the project’s packaging tooling, which could result in files not being included in a distribution.</li>
<li>The src layout helps avoid this by keeping import packages in a directory separate from the root directory of the project, ensuring that the installed copy is used.</li>
</ul></li>
<li>The src layout helps enforce that an editable installation is only able to import files that were meant to be importable.
<ul>
<li>This is especially relevant when the <a href="https://setuptools.pypa.io/en/latest/userguide/development_mode.html">editable installation</a> is implemented using a <a href="https://docs.python.org/3/library/site.html#index-2">path configuration</a> file that adds the directory to the import path.</li>
<li>The flat layout would add the other project files (eg: README.md, tox.ini) and packaging/tooling configuration files (eg: setup.py, noxfile.py) on the import path. This would make certain imports work in editable installations but not regular installations.</li>
</ul></li>
</ul>



 ]]></description>
  <category>python</category>
  <guid>https://lawrencewu.net/til/posts/2025-03-18-flat-vs-src-layouts/</guid>
  <pubDate>Tue, 18 Mar 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Claude 3.7 Sonnet via Google’s VertexAI</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-03-17-claude-via-vertex/</link>
  <description><![CDATA[ 





<p>Google and Vertex have an interesting relationship. I always wondered why Google was hosting Anthropic models in it’s VertexAI Model Garden. But there was <a href="https://techcrunch.com/2025/03/11/google-has-given-anthropic-more-funding-than-previously-known-show-new-filings/">news this last week that Google owns ~14% of Anthropic</a>.</p>
<p>I learned you can call Claude via VertexAI. This allows you to use tools that are built on Claude like Cline and Claude Code with Vertex.</p>
<p>To use Claude Code with VertexAI, if you already have your application-default credentials setup, you can just <a href="https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#connect-to-google-vertex-ai">set a few environment variables</a>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">CLAUDE_CODE_USE_VERTEX</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>1</span>
<span id="cb1-2"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">CLOUD_ML_REGION</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>us-east5</span>
<span id="cb1-3"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ANTHROPIC_VERTEX_PROJECT_ID</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>your-project-id</span></code></pre></div></div>



 ]]></description>
  <category>llm</category>
  <guid>https://lawrencewu.net/til/posts/2025-03-17-claude-via-vertex/</guid>
  <pubDate>Mon, 17 Mar 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>OpenAI Agents Release</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-03-11-openai-agents/</link>
  <description><![CDATA[ 





<p>We’ve been expecting OpenAI to release something about agents for awhile now and we finally got that <a href="https://openai.com/index/new-tools-for-building-agents/">release today</a>.</p>
<p>OpenAI enters the arena with a new Responses API and <a href="https://github.com/openai/openai-agents-python">Agents SDK</a>. They’re labeling this SDK as the production-level version of their previous framework Swarm.</p>
<p>OpenAI’s Agent Framework can work with other LLM providers <a href="https://openai.github.io/openai-agents-python/models/">using the OpenAI Chat Completions format</a> (another plus for proxies like LiteLLM).</p>
<p>Three general categories of tools they call out:</p>
<ul>
<li>Hosted tools: these run on LLM servers alongside the AI models. OpenAI offers retrieval, web search and computer use as hosted tools.</li>
<li>Function calling: these allow you to use any Python function as a tool.</li>
<li>Agents as tools: this allows you to use an agent as a tool, allowing Agents to call other agents without handing off to them.</li>
</ul>
<p>Kind of cool how they are turning Python functions into Agent tools:</p>
<ul>
<li>The Agents SDK will setup the tool automatically:</li>
<li>The name of the tool will be the name of the Python function (or you can provide a name)</li>
<li>Tool description will be taken from the docstring of the function (or you can provide a description)</li>
<li>The schema for the function inputs is automatically created from the function’s arguments</li>
<li>Descriptions for each input are taken from the docstring of the function, unless disabled</li>
<li>We use Python’s inspect module to extract the function signature, along with griffe to parse docstrings and pydantic for schema creation.</li>
</ul>
<p></p><div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/hciNKcLwSes" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div> <!-- markdownlint-disable-line MD034 --><p></p>
<p>Other notes I took from watching the above release video:</p>
<p>OpenAI has a fine-tuned version of GPT-4o that they use to review search results that are coming back from the Search tool in ChatGPT. It out performs <code>o3-mini</code> and <code>gpt-4.5</code> on SimpleQA. This model is used in the Search tool they are making available.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2025-03-11-openai-agents/simpleqa_search_preview.png" class="img-fluid figure-img"></p>
<figcaption>SimpleQA Benchmark</figcaption>
</figure>
</div>
<p>Other tools are a File Search tool and Computer Use tool (which it sounded like also has a different fine-tuned CUA model?). Actually yes, there is a computer use model. One of them is <code>computer-use-preview-2025-02-04</code> (see <a href="https://platform.openai.com/docs/models/computer-use-preview">here</a>).</p>
<p>They’re also releasing a Responses API. OpenAI released the Chat Completions API in March 2023 with gpt-3.5-turbo. It will be interesting if this Responses API becomes the de-facto standard like Chat Completions has. They will continue to support Chat Completions but Responses API will be a superset of Completions API features.</p>
<p>The Assistants API will eventually be deprecated sometime in 2026.</p>



 ]]></description>
  <category>python</category>
  <guid>https://lawrencewu.net/til/posts/2025-03-11-openai-agents/</guid>
  <pubDate>Tue, 11 Mar 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Summary of Building Agents with Model Context Protocol - Full Workshop with Mahesh Murag of Anthropic</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-03-01-mcp-talk/</link>
  <description><![CDATA[ 





<section id="building-agents-with-model-context-protocol---full-workshop-with-mahesh-murag-of-anthropic" class="level1">
<h1>Building Agents with Model Context Protocol - Full Workshop with Mahesh Murag of Anthropic</h1>
<p>Channel: AI Engineer</p>
<p></p><div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/kQmXtrmQ5Zg" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div> <!-- markdownlint-disable-line MD034 --><p></p>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<section id="what-is-mcp-00000" class="level3">
<h3 class="anchored" data-anchor-id="what-is-mcp-00000"><a href="https://youtube.com/watch?v=kQmXtrmQ5Zg&amp;t=0">What is MCP?</a> (0:00:00)</h3>
<p>Mahesh Murag from Anthropic discusses the Model Context Protocol (MCP), emphasizing its role in enhancing AI applications by standardizing how they interact with external systems. He highlights the evolution of AI models and the need for better context integration, which MCP addresses by allowing seamless connections between AI applications and various data sources. The protocol aims to reduce fragmentation in AI development, enabling more powerful and context-rich applications while facilitating collaboration across teams in enterprises. Adoption of MCP has been growing, with a significant number of community-built servers and integrations already in place.</p>
</section>
<section id="building-with-mcp-00939" class="level3">
<h3 class="anchored" data-anchor-id="building-with-mcp-00939"><a href="https://youtube.com/watch?v=kQmXtrmQ5Zg&amp;t=579">Building with MCP</a> (0:09:39)</h3>
<p>The section discusses the Model Context Protocol (MCP) and its core components, which include tools, resources, and prompts. Tools allow the client application to interact with the server, enabling the model to determine when to invoke them, while resources provide dynamic data that applications can control. Prompts are user-controlled templates for common interactions, facilitating richer engagement with the server. The MCP framework enhances the functionality of applications by providing a standardized way to integrate context and tools, complementing existing agent frameworks rather than replacing them.</p>
</section>
<section id="mcp-agents-02625" class="level3">
<h3 class="anchored" data-anchor-id="mcp-agents-02625"><a href="https://youtube.com/watch?v=kQmXtrmQ5Zg&amp;t=1585">MCP &amp; Agents</a> (0:26:25)</h3>
<p>In this section, Mahesh Murag discusses the Model Context Protocol (MCP) as a foundational framework for building AI agents that effectively manage context and enhance interactivity with various tools and data sources. He highlights the concept of augmented large language models (LLMs) that can dynamically discover and utilize capabilities, allowing for flexible agent designs that can adapt post-initialization. The MCP enables a streamlined agent-building process by abstracting server interactions, empowering developers to focus on core functionalities rather than the underlying infrastructure. Additionally, he emphasizes the importance of composability and sampling in creating intelligent agent systems that can operate efficiently across multiple layers.</p>
</section>
<section id="whats-next-for-mcp-11315" class="level3">
<h3 class="anchored" data-anchor-id="whats-next-for-mcp-11315"><a href="https://youtube.com/watch?v=kQmXtrmQ5Zg&amp;t=4395">What’s next for MCP?</a> (1:13:15)</h3>
<p>In this section, Mahesh Murag discusses the future developments of the Model Context Protocol (MCP), highlighting the introduction of remote servers and offloading capabilities, which will enhance user experience by allowing easier connections without requiring knowledge of MCP. He also mentions the creation of an official MCP registry to improve server discoverability and verification, as well as the potential for agents to become self-evolving by dynamically discovering new tools. Additionally, there are plans for innovations in stateful versus stateless connections, streaming data, and proactive server behaviors to enhance the functionality of MCP.</p>


</section>
</section>
</section>

 ]]></description>
  <category>mcp</category>
  <guid>https://lawrencewu.net/til/posts/2025-03-01-mcp-talk/</guid>
  <pubDate>Sat, 01 Mar 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>The wonders of python-dotenv</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-02-26-python-dotenv/</link>
  <description><![CDATA[ 





<p><a href="https://github.com/theskumar/python-dotenv">python-dotenv</a> is a ridiculously helpful Python library to programmatically load environment variables you have in a <code>.env</code> file into your script and Jupyter notebooks.</p>
<p>Install it:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">pip</span> install python-dotenv</span></code></pre></div></div>
<p>Put this code block at the top of scripts or notebooks:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">from</span> dotenv import load_dotenv</span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># find .env automagically by walking up directories until it's found</span></span>
<span id="cb2-3"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">dotenv_path</span> = find_dotenv<span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">)</span></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load up the entries as environment variables</span></span>
<span id="cb2-5"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">load_dotenv</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">(</span><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">dotenv_path</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">)</span></span></code></pre></div></div>
<p>If you want to load .env into your shell environment programmatically, you can run:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-a</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">source</span> .env<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span> +a</span></code></pre></div></div>
<p>This is helpful when a Streamlit app or FastAPI application needs .env variables.</p>
<p>If you want zsh to do this automatically every time a new shell session is opened, you can use this <a href="https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv">plugin</a>.</p>



 ]]></description>
  <category>python</category>
  <guid>https://lawrencewu.net/til/posts/2025-02-26-python-dotenv/</guid>
  <pubDate>Wed, 26 Feb 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Claude 3.7 Sonnet</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2025-02-24-claude-sonnet-37/</link>
  <description><![CDATA[ 





<p>Anthropic released Claude 3.7 Sonnet with a blog post <a href="https://www.anthropic.com/news/claude-3-7-sonnet">here</a>. Here’s the <a href="https://assets.anthropic.com/m/785e231869ea8b3b/original/claude-3-7-sonnet-system-card.pdf">system card</a>.</p>
<p>Some highlights:</p>
<ul>
<li>The reasoning and non-reasoning models are the same, you do have to select which one you want They’ve exposed the thinking tokens (which is different than OpenAI’s o1/o3 models)</li>
<li>I tried one of the examples in the system card to demonstrate the thinking tokens: <a href="https://claude.ai/share/919a9387-4cd0-4163-a216-6f5650c28c03" class="uri">https://claude.ai/share/919a9387-4cd0-4163-a216-6f5650c28c03</a></li>
<li>Anthropic does do a fantastic job on safety testing. They did a controlled trial on bioweapons acquisitions.</li>
</ul>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2025-02-24-claude-sonnet-37/bioweapons.png" class="img-fluid figure-img"></p>
<figcaption>Bioweapons Research</figcaption>
</figure>
</div>
<p>Some highlights from AI (<a href="https://claude.ai/share/7cef0dbc-fdba-453b-ae7d-87ac073bb62a">using Claude 3.7 Sonnet</a>):</p>
<ul>
<li>Extended thinking mode - Claude 3.7 Sonnet features a new “extended thinking” capability that allows the model to reason through complex problems step-by-step before giving a final answer, particularly valuable for mathematical problems and multi-step reasoning tasks.</li>
<li>Hybrid reasoning model - Claude 3.7 Sonnet is described as a “hybrid reasoning model” that combines standard thinking with this extended reasoning capability.</li>
<li>Improved refusal rates - The model reduces unnecessary refusals by 45% in standard thinking mode and 31% in extended thinking mode compared to Claude 3.5 Sonnet, providing more helpful responses to ambiguous queries.</li>
<li>Visible reasoning process - Anthropic has decided to make Claude’s reasoning process visible to users, enhancing transparency and allowing users to better understand how the model reaches conclusions.</li>
<li>Safety evaluations - The model underwent comprehensive testing across CBRN (Chemical, Biological, Radiological, Nuclear), cybersecurity, and autonomy risks, with ASL-2 safeguards determined appropriate.</li>
<li>Capabilities improvements - Claude 3.7 Sonnet shows improved performance across multiple domains while maintaining strong bias and safety metrics.</li>
<li>Chain-of-thought faithfulness - Research shows that while reasoning chains improve outputs, they don’t always fully reveal all factors influencing the model’s conclusions.</li>
<li>Knowledge cutoff date - Claude 3.7 Sonnet’s reliable knowledge extends through October 2024.</li>
</ul>
<p>They also released Claude Code, an AI Coding agent. More of these are coming out. It does feel like the way software development is done is changing very rapidly.</p>
<p></p><div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/AJpK3YTTKZ4" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div> <!-- markdownlint-disable-line MD034 --><p></p>



 ]]></description>
  <category>llm</category>
  <guid>https://lawrencewu.net/til/posts/2025-02-24-claude-sonnet-37/</guid>
  <pubDate>Mon, 24 Feb 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Prompt Generation &amp; Meta-Prompting</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2024-10-11-prompt-generation-metaprompt/</link>
  <description><![CDATA[ 





<p>OpenAI added a system prompt generate button that lets you generate prompts, functions and schemas from just describing the task.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2024-10-11-prompt-generation-metaprompt/openai_playground_generate.png" class="img-fluid figure-img"></p>
<figcaption>OpenAI Playground New Generate Button</figcaption>
</figure>
</div>
<p>They use “meta-prompts” and “meta-schemas” to do this.</p>
<ul>
<li>Prompts: We use meta-prompts that incorporate best practices to generate or improve prompts.</li>
<li>Schemas: We use meta-schemas that produce valid JSON and function syntax.</li>
</ul>
<p>They also say they may use more advanced techniques like DSPy and <a href="https://arxiv.org/abs/2305.03495">Gradient Descent</a>.</p>
<p>The meta prompt is quite instructive. It’s awesome they’ve open sourced this. I’ve started to use LLMs to generate prompts too. Of course I will then modify what the LLM generates for my specific use case and run some evaluations. Language models generally do a better job than I do at being comprehensive on the first pass of a use case. This is because I and other humans are forgetful and not as thorough as a well-prompted language model, this idea reminds me of a <a href="https://www.health.harvard.edu/blog/can-ai-answer-medical-questions-better-than-your-doctor-202403273028">study that said 80% of ChatGPT’s answers were better than a physician</a>. This is not to say humans will not write better prompts than a language model will. But once you’ve done a task multiple times, you may not be as thorough, rush through and not have time to do robust prompt engineering.</p>
<p>Below are two meta-prompt examples and two meta-schema examples.</p>
<section id="meta-prompt-text-out" class="level2">
<h2 class="anchored" data-anchor-id="meta-prompt-text-out">Meta-Prompt: Text-Out</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"></span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> openai <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> OpenAI</span>
<span id="cb1-3"></span>
<span id="cb1-4">client <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> OpenAI()</span>
<span id="cb1-5"></span>
<span id="cb1-6">META_PROMPT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb1-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.</span></span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Guidelines</span></span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.</span></span>
<span id="cb1-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.</span></span>
<span id="cb1-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!</span></span>
<span id="cb1-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.</span></span>
<span id="cb1-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    - Conclusion, classifications, or results should ALWAYS appear last.</span></span>
<span id="cb1-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.</span></span>
<span id="cb1-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.</span></span>
<span id="cb1-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.</span></span>
<span id="cb1-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.</span></span>
<span id="cb1-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.</span></span>
<span id="cb1-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.</span></span>
<span id="cb1-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)</span></span>
<span id="cb1-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.</span></span>
<span id="cb1-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    - JSON should never be wrapped in code blocks (```) unless explicitly requested.</span></span>
<span id="cb1-25"></span>
<span id="cb1-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")</span></span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Concise instruction describing the task - this should be the first line in the prompt, no section header]</span></span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Additional details as needed.]</span></span>
<span id="cb1-31"></span>
<span id="cb1-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Optional sections with headings or bullet points for detailed steps.]</span></span>
<span id="cb1-33"></span>
<span id="cb1-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Steps [optional]</span></span>
<span id="cb1-35"></span>
<span id="cb1-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[optional: a detailed breakdown of the steps necessary to accomplish the task]</span></span>
<span id="cb1-37"></span>
<span id="cb1-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Output Format</span></span>
<span id="cb1-39"></span>
<span id="cb1-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]</span></span>
<span id="cb1-41"></span>
<span id="cb1-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Examples [optional]</span></span>
<span id="cb1-43"></span>
<span id="cb1-44"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]</span></span>
<span id="cb1-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]</span></span>
<span id="cb1-46"></span>
<span id="cb1-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Notes [optional]</span></span>
<span id="cb1-48"></span>
<span id="cb1-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[optional: edge cases, details, and an area to call or repeat out specific important considerations]</span></span>
<span id="cb1-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>.strip()</span>
<span id="cb1-51"></span>
<span id="cb1-52"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_prompt(task_or_prompt: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>):</span>
<span id="cb1-53">    completion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> client.chat.completions.create(</span>
<span id="cb1-54">        model<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gpt-4o"</span>,</span>
<span id="cb1-55">        messages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[</span>
<span id="cb1-56">            {</span>
<span id="cb1-57">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"system"</span>,</span>
<span id="cb1-58">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: META_PROMPT,</span>
<span id="cb1-59">            },</span>
<span id="cb1-60">            {</span>
<span id="cb1-61">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span>,</span>
<span id="cb1-62">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Task, Goal, or Current Prompt:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> task_or_prompt,</span>
<span id="cb1-63">            },</span>
<span id="cb1-64">        ],</span>
<span id="cb1-65">    )</span>
<span id="cb1-66"></span>
<span id="cb1-67">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> completion.choices[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].message.content</span></code></pre></div></div>
</section>
<section id="meta-prompt-audio-out" class="level2">
<h2 class="anchored" data-anchor-id="meta-prompt-audio-out">Meta-Prompt: Audio-Out</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"></span>
<span id="cb2-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> openai <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> OpenAI</span>
<span id="cb2-3"></span>
<span id="cb2-4">client <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> OpenAI()</span>
<span id="cb2-5"></span>
<span id="cb2-6">META_PROMPT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Given a task description or existing prompt, produce a detailed system prompt to guide a realtime audio output language model in completing the task effectively.</span></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Guidelines</span></span>
<span id="cb2-10"></span>
<span id="cb2-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.</span></span>
<span id="cb2-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Tone: Make sure to specifically call out the tone. By default it should be emotive and friendly, and speak quickly to avoid keeping the user just waiting.</span></span>
<span id="cb2-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Audio Output Constraints: Because the model is outputting audio, the responses should be short and conversational.</span></span>
<span id="cb2-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.</span></span>
<span id="cb2-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.</span></span>
<span id="cb2-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.</span></span>
<span id="cb2-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  - It is very important that any examples included reflect the short, conversational output responses of the model.</span></span>
<span id="cb2-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Keep the sentences very short by default. Instead of 3 sentences in a row by the assistant, it should be split up with a back and forth with the user instead.</span></span>
<span id="cb2-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  - By default each sentence should be a few words only (5-20ish words). However, if the user specifically asks for "short" responses, then the examples should truly have 1-10 word responses max.</span></span>
<span id="cb2-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  - Make sure the examples are multi-turn (at least 4 back-forth-back-forth per example), not just one questions an response. They should reflect an organic conversation.</span></span>
<span id="cb2-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.</span></span>
<span id="cb2-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.</span></span>
<span id="cb2-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.</span></span>
<span id="cb2-24"></span>
<span id="cb2-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")</span></span>
<span id="cb2-26"></span>
<span id="cb2-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Concise instruction describing the task - this should be the first line in the prompt, no section header]</span></span>
<span id="cb2-28"></span>
<span id="cb2-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Additional details as needed.]</span></span>
<span id="cb2-30"></span>
<span id="cb2-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Optional sections with headings or bullet points for detailed steps.]</span></span>
<span id="cb2-32"></span>
<span id="cb2-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Examples [optional]</span></span>
<span id="cb2-34"></span>
<span id="cb2-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]</span></span>
<span id="cb2-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]</span></span>
<span id="cb2-37"></span>
<span id="cb2-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Notes [optional]</span></span>
<span id="cb2-39"></span>
<span id="cb2-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[optional: edge cases, details, and an area to call or repeat out specific important considerations]</span></span>
<span id="cb2-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>.strip()</span>
<span id="cb2-42"></span>
<span id="cb2-43"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_prompt(task_or_prompt: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>):</span>
<span id="cb2-44">    completion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> client.chat.completions.create(</span>
<span id="cb2-45">        model<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gpt-4o"</span>,</span>
<span id="cb2-46">        messages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[</span>
<span id="cb2-47">            {</span>
<span id="cb2-48">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"system"</span>,</span>
<span id="cb2-49">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: META_PROMPT,</span>
<span id="cb2-50">            },</span>
<span id="cb2-51">            {</span>
<span id="cb2-52">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span>,</span>
<span id="cb2-53">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Task, Goal, or Current Prompt:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> task_or_prompt,</span>
<span id="cb2-54">            },</span>
<span id="cb2-55">        ],</span>
<span id="cb2-56">    )</span>
<span id="cb2-57"></span>
<span id="cb2-58">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> completion.choices[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].message.content</span></code></pre></div></div>
</section>
<section id="meta-schema-structured-output" class="level2">
<h2 class="anchored" data-anchor-id="meta-schema-structured-output">Meta-Schema: Structured Output</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"></span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> openai <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> OpenAI</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> json</span>
<span id="cb3-4"></span>
<span id="cb3-5">client <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> OpenAI()</span>
<span id="cb3-6"></span>
<span id="cb3-7">META_SCHEMA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb3-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"metaschema"</span>,</span>
<span id="cb3-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schema"</span>: {</span>
<span id="cb3-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-12">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>: {</span>
<span id="cb3-13">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb3-14">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The name of the schema"</span></span>
<span id="cb3-15">      },</span>
<span id="cb3-16">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb3-17">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb3-18">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enum"</span>: [</span>
<span id="cb3-19">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-20">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-21">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb3-22">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number"</span>,</span>
<span id="cb3-23">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span>,</span>
<span id="cb3-24">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"null"</span></span>
<span id="cb3-25">        ]</span>
<span id="cb3-26">      },</span>
<span id="cb3-27">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-28">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-29">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb3-30">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-31">        }</span>
<span id="cb3-32">      },</span>
<span id="cb3-33">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-34">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anyOf"</span>: [</span>
<span id="cb3-35">          {</span>
<span id="cb3-36">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-37">          },</span>
<span id="cb3-38">          {</span>
<span id="cb3-39">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-40">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-41">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-42">            }</span>
<span id="cb3-43">          }</span>
<span id="cb3-44">        ]</span>
<span id="cb3-45">      },</span>
<span id="cb3-46">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: {</span>
<span id="cb3-47">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-48">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-49">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span></span>
<span id="cb3-50">        }</span>
<span id="cb3-51">      },</span>
<span id="cb3-52">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb3-53">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span></span>
<span id="cb3-54">      }</span>
<span id="cb3-55">    },</span>
<span id="cb3-56">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb3-57">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span></span>
<span id="cb3-58">    ],</span>
<span id="cb3-59">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb3-60">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"if"</span>: {</span>
<span id="cb3-61">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-62">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb3-63">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span></span>
<span id="cb3-64">        }</span>
<span id="cb3-65">      }</span>
<span id="cb3-66">    },</span>
<span id="cb3-67">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"then"</span>: {</span>
<span id="cb3-68">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb3-69">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span></span>
<span id="cb3-70">      ]</span>
<span id="cb3-71">    },</span>
<span id="cb3-72">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$defs"</span>: {</span>
<span id="cb3-73">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schema_definition"</span>: {</span>
<span id="cb3-74">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-75">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-76">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb3-77">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb3-78">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enum"</span>: [</span>
<span id="cb3-79">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-80">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-81">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb3-82">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number"</span>,</span>
<span id="cb3-83">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span>,</span>
<span id="cb3-84">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"null"</span></span>
<span id="cb3-85">            ]</span>
<span id="cb3-86">          },</span>
<span id="cb3-87">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-88">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb3-89">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb3-90">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-91">            }</span>
<span id="cb3-92">          },</span>
<span id="cb3-93">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-94">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anyOf"</span>: [</span>
<span id="cb3-95">              {</span>
<span id="cb3-96">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-97">              },</span>
<span id="cb3-98">              {</span>
<span id="cb3-99">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-100">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-101">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb3-102">                }</span>
<span id="cb3-103">              }</span>
<span id="cb3-104">            ]</span>
<span id="cb3-105">          },</span>
<span id="cb3-106">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: {</span>
<span id="cb3-107">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb3-108">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb3-109">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span></span>
<span id="cb3-110">            }</span>
<span id="cb3-111">          },</span>
<span id="cb3-112">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb3-113">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span></span>
<span id="cb3-114">          }</span>
<span id="cb3-115">        },</span>
<span id="cb3-116">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb3-117">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span></span>
<span id="cb3-118">        ],</span>
<span id="cb3-119">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb3-120">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"if"</span>: {</span>
<span id="cb3-121">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb3-122">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb3-123">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span></span>
<span id="cb3-124">            }</span>
<span id="cb3-125">          }</span>
<span id="cb3-126">        },</span>
<span id="cb3-127">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"then"</span>: {</span>
<span id="cb3-128">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb3-129">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span></span>
<span id="cb3-130">          ]</span>
<span id="cb3-131">        }</span>
<span id="cb3-132">      }</span>
<span id="cb3-133">    }</span>
<span id="cb3-134">  }</span>
<span id="cb3-135">}</span>
<span id="cb3-136"></span>
<span id="cb3-137">META_PROMPT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb3-138"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Instructions</span></span>
<span id="cb3-139"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Return a valid schema for the described JSON.</span></span>
<span id="cb3-140"></span>
<span id="cb3-141"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">You must also make sure:</span></span>
<span id="cb3-142"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- all fields in an object are set as required</span></span>
<span id="cb3-143"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- I REPEAT, ALL FIELDS MUST BE MARKED AS REQUIRED</span></span>
<span id="cb3-144"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- all objects must have additionalProperties set to false</span></span>
<span id="cb3-145"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    - because of this, some cases like "attributes" or "metadata" properties that would normally allow additional properties should instead have a fixed set of properties</span></span>
<span id="cb3-146"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- all objects must have properties defined</span></span>
<span id="cb3-147"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- field order matters. any form of "thinking" or "explanation" should come before the conclusion</span></span>
<span id="cb3-148"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- $defs must be defined under the schema param</span></span>
<span id="cb3-149"></span>
<span id="cb3-150"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Notable keywords NOT supported include:</span></span>
<span id="cb3-151"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- For strings: minLength, maxLength, pattern, format</span></span>
<span id="cb3-152"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- For numbers: minimum, maximum, multipleOf</span></span>
<span id="cb3-153"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- For objects: patternProperties, unevaluatedProperties, propertyNames, minProperties, maxProperties</span></span>
<span id="cb3-154"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- For arrays: unevaluatedItems, contains, minContains, maxContains, minItems, maxItems, uniqueItems</span></span>
<span id="cb3-155"></span>
<span id="cb3-156"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Other notes:</span></span>
<span id="cb3-157"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- definitions and recursion are supported</span></span>
<span id="cb3-158"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- only if necessary to include references e.g. "$defs", it must be inside the "schema" object</span></span>
<span id="cb3-159"></span>
<span id="cb3-160"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Examples</span></span>
<span id="cb3-161"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Generate a math reasoning schema with steps and a final answer.</span></span>
<span id="cb3-162"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb3-163"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "math_reasoning",</span></span>
<span id="cb3-164"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "type": "object",</span></span>
<span id="cb3-165"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "properties": {</span></span>
<span id="cb3-166"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "steps": {</span></span>
<span id="cb3-167"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "array",</span></span>
<span id="cb3-168"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "A sequence of steps involved in solving the math problem.",</span></span>
<span id="cb3-169"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "items": {</span></span>
<span id="cb3-170"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "object",</span></span>
<span id="cb3-171"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "properties": {</span></span>
<span id="cb3-172"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "explanation": {</span></span>
<span id="cb3-173"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "string",</span></span>
<span id="cb3-174"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "Description of the reasoning or method used in this step."</span></span>
<span id="cb3-175"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    },</span></span>
<span id="cb3-176"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "output": {</span></span>
<span id="cb3-177"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "string",</span></span>
<span id="cb3-178"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "Result or outcome of this specific step."</span></span>
<span id="cb3-179"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    }</span></span>
<span id="cb3-180"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                },</span></span>
<span id="cb3-181"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "required": [</span></span>
<span id="cb3-182"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "explanation",</span></span>
<span id="cb3-183"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "output"</span></span>
<span id="cb3-184"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                ],</span></span>
<span id="cb3-185"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "additionalProperties": false</span></span>
<span id="cb3-186"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb3-187"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        },</span></span>
<span id="cb3-188"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "final_answer": {</span></span>
<span id="cb3-189"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "string",</span></span>
<span id="cb3-190"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "The final solution or answer to the math problem."</span></span>
<span id="cb3-191"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb3-192"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    },</span></span>
<span id="cb3-193"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "required": [</span></span>
<span id="cb3-194"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "steps",</span></span>
<span id="cb3-195"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "final_answer"</span></span>
<span id="cb3-196"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ],</span></span>
<span id="cb3-197"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "additionalProperties": false</span></span>
<span id="cb3-198"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-199"></span>
<span id="cb3-200"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Give me a linked list</span></span>
<span id="cb3-201"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb3-202"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "linked_list",</span></span>
<span id="cb3-203"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "type": "object",</span></span>
<span id="cb3-204"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "properties": {</span></span>
<span id="cb3-205"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "linked_list": {</span></span>
<span id="cb3-206"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "$ref": "#/$defs/linked_list_node",</span></span>
<span id="cb3-207"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "The head node of the linked list."</span></span>
<span id="cb3-208"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb3-209"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    },</span></span>
<span id="cb3-210"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "$defs": {</span></span>
<span id="cb3-211"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "linked_list_node": {</span></span>
<span id="cb3-212"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "object",</span></span>
<span id="cb3-213"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "Defines a node in a singly linked list.",</span></span>
<span id="cb3-214"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "properties": {</span></span>
<span id="cb3-215"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "value": {</span></span>
<span id="cb3-216"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "type": "number",</span></span>
<span id="cb3-217"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "description": "The value stored in this node."</span></span>
<span id="cb3-218"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                },</span></span>
<span id="cb3-219"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "next": {</span></span>
<span id="cb3-220"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "anyOf": [</span></span>
<span id="cb3-221"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        {</span></span>
<span id="cb3-222"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "$ref": "#/$defs/linked_list_node"</span></span>
<span id="cb3-223"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        },</span></span>
<span id="cb3-224"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        {</span></span>
<span id="cb3-225"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "type": "null"</span></span>
<span id="cb3-226"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        }</span></span>
<span id="cb3-227"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    ],</span></span>
<span id="cb3-228"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "description": "Reference to the next node; null if it is the last node."</span></span>
<span id="cb3-229"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                }</span></span>
<span id="cb3-230"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb3-231"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "required": [</span></span>
<span id="cb3-232"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "value",</span></span>
<span id="cb3-233"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "next"</span></span>
<span id="cb3-234"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            ],</span></span>
<span id="cb3-235"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "additionalProperties": false</span></span>
<span id="cb3-236"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb3-237"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    },</span></span>
<span id="cb3-238"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "required": [</span></span>
<span id="cb3-239"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "linked_list"</span></span>
<span id="cb3-240"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ],</span></span>
<span id="cb3-241"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "additionalProperties": false</span></span>
<span id="cb3-242"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-243"></span>
<span id="cb3-244"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Dynamically generated UI</span></span>
<span id="cb3-245"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb3-246"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "ui",</span></span>
<span id="cb3-247"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "type": "object",</span></span>
<span id="cb3-248"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "properties": {</span></span>
<span id="cb3-249"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "type": {</span></span>
<span id="cb3-250"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "string",</span></span>
<span id="cb3-251"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "The type of the UI component",</span></span>
<span id="cb3-252"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "enum": [</span></span>
<span id="cb3-253"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "div",</span></span>
<span id="cb3-254"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "button",</span></span>
<span id="cb3-255"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "header",</span></span>
<span id="cb3-256"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "section",</span></span>
<span id="cb3-257"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "field",</span></span>
<span id="cb3-258"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "form"</span></span>
<span id="cb3-259"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            ]</span></span>
<span id="cb3-260"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        },</span></span>
<span id="cb3-261"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "label": {</span></span>
<span id="cb3-262"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "string",</span></span>
<span id="cb3-263"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "The label of the UI component, used for buttons or form fields"</span></span>
<span id="cb3-264"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        },</span></span>
<span id="cb3-265"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "children": {</span></span>
<span id="cb3-266"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "array",</span></span>
<span id="cb3-267"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "Nested UI components",</span></span>
<span id="cb3-268"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "items": {</span></span>
<span id="cb3-269"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "$ref": "#"</span></span>
<span id="cb3-270"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb3-271"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        },</span></span>
<span id="cb3-272"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "attributes": {</span></span>
<span id="cb3-273"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "type": "array",</span></span>
<span id="cb3-274"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "description": "Arbitrary attributes for the UI component, suitable for any element",</span></span>
<span id="cb3-275"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "items": {</span></span>
<span id="cb3-276"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "object",</span></span>
<span id="cb3-277"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "properties": {</span></span>
<span id="cb3-278"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "name": {</span></span>
<span id="cb3-279"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "string",</span></span>
<span id="cb3-280"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "The name of the attribute, for example onClick or className"</span></span>
<span id="cb3-281"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    },</span></span>
<span id="cb3-282"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "value": {</span></span>
<span id="cb3-283"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "string",</span></span>
<span id="cb3-284"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "The value of the attribute"</span></span>
<span id="cb3-285"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    }</span></span>
<span id="cb3-286"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                },</span></span>
<span id="cb3-287"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "required": [</span></span>
<span id="cb3-288"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "name",</span></span>
<span id="cb3-289"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "value"</span></span>
<span id="cb3-290"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                ],</span></span>
<span id="cb3-291"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "additionalProperties": false</span></span>
<span id="cb3-292"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb3-293"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb3-294"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    },</span></span>
<span id="cb3-295"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "required": [</span></span>
<span id="cb3-296"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "type",</span></span>
<span id="cb3-297"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "label",</span></span>
<span id="cb3-298"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "children",</span></span>
<span id="cb3-299"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "attributes"</span></span>
<span id="cb3-300"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ],</span></span>
<span id="cb3-301"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "additionalProperties": false</span></span>
<span id="cb3-302"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-303"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>.strip()</span>
<span id="cb3-304"></span>
<span id="cb3-305"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_schema(description: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>):</span>
<span id="cb3-306">    completion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> client.chat.completions.create(</span>
<span id="cb3-307">        model<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gpt-4o-mini"</span>,</span>
<span id="cb3-308">        response_format<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"json_schema"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"json_schema"</span>: META_SCHEMA},</span>
<span id="cb3-309">        messages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[</span>
<span id="cb3-310">            {</span>
<span id="cb3-311">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"system"</span>,</span>
<span id="cb3-312">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: META_PROMPT,</span>
<span id="cb3-313">            },</span>
<span id="cb3-314">            {</span>
<span id="cb3-315">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span>,</span>
<span id="cb3-316">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Description:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> description,</span>
<span id="cb3-317">            },</span>
<span id="cb3-318">        ],</span>
<span id="cb3-319">    )</span>
<span id="cb3-320"></span>
<span id="cb3-321">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> json.loads(completion.choices[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].message.content)</span></code></pre></div></div>
</section>
<section id="meta-schema-function-schema" class="level2">
<h2 class="anchored" data-anchor-id="meta-schema-function-schema">Meta-Schema: Function Schema</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"></span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> openai <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> OpenAI</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> json</span>
<span id="cb4-4"></span>
<span id="cb4-5">client <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> OpenAI()</span>
<span id="cb4-6"></span>
<span id="cb4-7">META_SCHEMA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb4-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"function-metaschema"</span>,</span>
<span id="cb4-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schema"</span>: {</span>
<span id="cb4-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb4-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb4-12">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>: {</span>
<span id="cb4-13">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb4-14">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The name of the function"</span></span>
<span id="cb4-15">      },</span>
<span id="cb4-16">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>: {</span>
<span id="cb4-17">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb4-18">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A description of what the function does"</span></span>
<span id="cb4-19">      },</span>
<span id="cb4-20">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parameters"</span>: {</span>
<span id="cb4-21">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span>,</span>
<span id="cb4-22">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A JSON schema that defines the function's parameters"</span></span>
<span id="cb4-23">      }</span>
<span id="cb4-24">    },</span>
<span id="cb4-25">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb4-26">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>,</span>
<span id="cb4-27">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>,</span>
<span id="cb4-28">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parameters"</span></span>
<span id="cb4-29">    ],</span>
<span id="cb4-30">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb4-31">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$defs"</span>: {</span>
<span id="cb4-32">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schema_definition"</span>: {</span>
<span id="cb4-33">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb4-34">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb4-35">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb4-36">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb4-37">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enum"</span>: [</span>
<span id="cb4-38">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb4-39">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb4-40">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>,</span>
<span id="cb4-41">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number"</span>,</span>
<span id="cb4-42">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span>,</span>
<span id="cb4-43">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"null"</span></span>
<span id="cb4-44">            ]</span>
<span id="cb4-45">          },</span>
<span id="cb4-46">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb4-47">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span>,</span>
<span id="cb4-48">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb4-49">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb4-50">            }</span>
<span id="cb4-51">          },</span>
<span id="cb4-52">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb4-53">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anyOf"</span>: [</span>
<span id="cb4-54">              {</span>
<span id="cb4-55">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb4-56">              },</span>
<span id="cb4-57">              {</span>
<span id="cb4-58">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb4-59">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb4-60">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$ref"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#/$defs/schema_definition"</span></span>
<span id="cb4-61">                }</span>
<span id="cb4-62">              }</span>
<span id="cb4-63">            ]</span>
<span id="cb4-64">          },</span>
<span id="cb4-65">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: {</span>
<span id="cb4-66">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>,</span>
<span id="cb4-67">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"items"</span>: {</span>
<span id="cb4-68">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span></span>
<span id="cb4-69">            }</span>
<span id="cb4-70">          },</span>
<span id="cb4-71">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: {</span>
<span id="cb4-72">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boolean"</span></span>
<span id="cb4-73">          }</span>
<span id="cb4-74">        },</span>
<span id="cb4-75">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb4-76">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span></span>
<span id="cb4-77">        ],</span>
<span id="cb4-78">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"additionalProperties"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb4-79">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"if"</span>: {</span>
<span id="cb4-80">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span>: {</span>
<span id="cb4-81">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: {</span>
<span id="cb4-82">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"object"</span></span>
<span id="cb4-83">            }</span>
<span id="cb4-84">          }</span>
<span id="cb4-85">        },</span>
<span id="cb4-86">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"then"</span>: {</span>
<span id="cb4-87">          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"required"</span>: [</span>
<span id="cb4-88">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"properties"</span></span>
<span id="cb4-89">          ]</span>
<span id="cb4-90">        }</span>
<span id="cb4-91">      }</span>
<span id="cb4-92">    }</span>
<span id="cb4-93">  }</span>
<span id="cb4-94">}</span>
<span id="cb4-95"></span>
<span id="cb4-96">META_PROMPT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb4-97"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Instructions</span></span>
<span id="cb4-98"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Return a valid schema for the described function.</span></span>
<span id="cb4-99"></span>
<span id="cb4-100"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Pay special attention to making sure that "required" and "type" are always at the correct level of nesting. For example, "required" should be at the same level as "properties", not inside it.</span></span>
<span id="cb4-101"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Make sure that every property, no matter how short, has a type and description correctly nested inside it.</span></span>
<span id="cb4-102"></span>
<span id="cb4-103"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"># Examples</span></span>
<span id="cb4-104"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Assign values to NN hyperparameters</span></span>
<span id="cb4-105"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb4-106"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "set_hyperparameters",</span></span>
<span id="cb4-107"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "description": "Assign values to NN hyperparameters",</span></span>
<span id="cb4-108"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "parameters": {</span></span>
<span id="cb4-109"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "type": "object",</span></span>
<span id="cb4-110"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "required": [</span></span>
<span id="cb4-111"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "learning_rate",</span></span>
<span id="cb4-112"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "epochs"</span></span>
<span id="cb4-113"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        ],</span></span>
<span id="cb4-114"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "properties": {</span></span>
<span id="cb4-115"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "epochs": {</span></span>
<span id="cb4-116"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "number",</span></span>
<span id="cb4-117"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "Number of complete passes through dataset"</span></span>
<span id="cb4-118"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb4-119"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "learning_rate": {</span></span>
<span id="cb4-120"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "number",</span></span>
<span id="cb4-121"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "Speed of model learning"</span></span>
<span id="cb4-122"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb4-123"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb4-124"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb4-125"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-126"></span>
<span id="cb4-127"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Plans a motion path for the robot</span></span>
<span id="cb4-128"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb4-129"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "plan_motion",</span></span>
<span id="cb4-130"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "description": "Plans a motion path for the robot",</span></span>
<span id="cb4-131"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "parameters": {</span></span>
<span id="cb4-132"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "type": "object",</span></span>
<span id="cb4-133"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "required": [</span></span>
<span id="cb4-134"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "start_position",</span></span>
<span id="cb4-135"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "end_position"</span></span>
<span id="cb4-136"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        ],</span></span>
<span id="cb4-137"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "properties": {</span></span>
<span id="cb4-138"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "end_position": {</span></span>
<span id="cb4-139"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "object",</span></span>
<span id="cb4-140"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "properties": {</span></span>
<span id="cb4-141"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "x": {</span></span>
<span id="cb4-142"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "number",</span></span>
<span id="cb4-143"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "End X coordinate"</span></span>
<span id="cb4-144"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    },</span></span>
<span id="cb4-145"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "y": {</span></span>
<span id="cb4-146"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "number",</span></span>
<span id="cb4-147"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "End Y coordinate"</span></span>
<span id="cb4-148"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    }</span></span>
<span id="cb4-149"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                }</span></span>
<span id="cb4-150"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb4-151"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "obstacles": {</span></span>
<span id="cb4-152"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "array",</span></span>
<span id="cb4-153"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "Array of obstacle coordinates",</span></span>
<span id="cb4-154"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "items": {</span></span>
<span id="cb4-155"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "type": "object",</span></span>
<span id="cb4-156"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "properties": {</span></span>
<span id="cb4-157"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "x": {</span></span>
<span id="cb4-158"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "type": "number",</span></span>
<span id="cb4-159"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "description": "Obstacle X coordinate"</span></span>
<span id="cb4-160"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        },</span></span>
<span id="cb4-161"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "y": {</span></span>
<span id="cb4-162"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "type": "number",</span></span>
<span id="cb4-163"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                            "description": "Obstacle Y coordinate"</span></span>
<span id="cb4-164"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        }</span></span>
<span id="cb4-165"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    }</span></span>
<span id="cb4-166"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                }</span></span>
<span id="cb4-167"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb4-168"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "start_position": {</span></span>
<span id="cb4-169"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "object",</span></span>
<span id="cb4-170"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "properties": {</span></span>
<span id="cb4-171"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "x": {</span></span>
<span id="cb4-172"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "number",</span></span>
<span id="cb4-173"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "Start X coordinate"</span></span>
<span id="cb4-174"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    },</span></span>
<span id="cb4-175"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "y": {</span></span>
<span id="cb4-176"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "type": "number",</span></span>
<span id="cb4-177"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "description": "Start Y coordinate"</span></span>
<span id="cb4-178"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    }</span></span>
<span id="cb4-179"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                }</span></span>
<span id="cb4-180"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb4-181"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb4-182"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb4-183"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-184"></span>
<span id="cb4-185"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Input: Calculates various technical indicators</span></span>
<span id="cb4-186"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Output: {</span></span>
<span id="cb4-187"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "name": "technical_indicator",</span></span>
<span id="cb4-188"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "description": "Calculates various technical indicators",</span></span>
<span id="cb4-189"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "parameters": {</span></span>
<span id="cb4-190"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "type": "object",</span></span>
<span id="cb4-191"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "required": [</span></span>
<span id="cb4-192"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "ticker",</span></span>
<span id="cb4-193"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "indicators"</span></span>
<span id="cb4-194"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        ],</span></span>
<span id="cb4-195"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        "properties": {</span></span>
<span id="cb4-196"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "indicators": {</span></span>
<span id="cb4-197"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "array",</span></span>
<span id="cb4-198"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "List of technical indicators to calculate",</span></span>
<span id="cb4-199"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "items": {</span></span>
<span id="cb4-200"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "type": "string",</span></span>
<span id="cb4-201"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "description": "Technical indicator",</span></span>
<span id="cb4-202"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    "enum": [</span></span>
<span id="cb4-203"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "RSI",</span></span>
<span id="cb4-204"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "MACD",</span></span>
<span id="cb4-205"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "Bollinger_Bands",</span></span>
<span id="cb4-206"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                        "Stochastic_Oscillator"</span></span>
<span id="cb4-207"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                    ]</span></span>
<span id="cb4-208"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                }</span></span>
<span id="cb4-209"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb4-210"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "period": {</span></span>
<span id="cb4-211"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "number",</span></span>
<span id="cb4-212"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "Time period for the analysis"</span></span>
<span id="cb4-213"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            },</span></span>
<span id="cb4-214"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            "ticker": {</span></span>
<span id="cb4-215"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "type": "string",</span></span>
<span id="cb4-216"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                "description": "Stock ticker symbol"</span></span>
<span id="cb4-217"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            }</span></span>
<span id="cb4-218"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">        }</span></span>
<span id="cb4-219"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb4-220"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-221"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>.strip()</span>
<span id="cb4-222"></span>
<span id="cb4-223"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_function_schema(description: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>):</span>
<span id="cb4-224">    completion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> client.chat.completions.create(</span>
<span id="cb4-225">        model<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gpt-4o-mini"</span>,</span>
<span id="cb4-226">        response_format<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"json_schema"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"json_schema"</span>: META_SCHEMA},</span>
<span id="cb4-227">        messages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[</span>
<span id="cb4-228">            {</span>
<span id="cb4-229">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"system"</span>,</span>
<span id="cb4-230">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: META_PROMPT,</span>
<span id="cb4-231">            },</span>
<span id="cb4-232">            {</span>
<span id="cb4-233">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span>,</span>
<span id="cb4-234">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Description:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> description,</span>
<span id="cb4-235">            },</span>
<span id="cb4-236">        ],</span>
<span id="cb4-237">    )</span>
<span id="cb4-238"></span>
<span id="cb4-239">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> json.loads(completion.choices[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].message.content)</span></code></pre></div></div>


</section>

 ]]></description>
  <category>prompt</category>
  <category>llm</category>
  <category>meta</category>
  <guid>https://lawrencewu.net/til/posts/2024-10-11-prompt-generation-metaprompt/</guid>
  <pubDate>Fri, 11 Oct 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Juan Carlos Izpisua Belmonte &amp; Yamanaka Factors</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2024-10-03-yamanaka-factors/</link>
  <description><![CDATA[ 





<p>I was watching one of the videos from the All-In Summit 2024:</p>
<p></p><div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/uUjF3RG28SQ" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div> <!-- markdownlint-disable-line MD034 --><p></p>
<p>Sometimes YouTube videos are too long so I will grab the <a href="https://lawwu.github.io/transcripts/transcript_uUjF3RG28SQ.html">transcript</a>, also possible to do <a href="https://github.com/jdepoix/youtube-transcript-api">programmatically</a> or via web tools like this <a href="https://youtubetranscript.com/">one</a>. And then I’ll drop it into ChatGPT with a prompt: “What are the main points and takeaways from this talk?”. Example <a href="https://chatgpt.com/share/66fda61a-5d8c-8011-a679-eebeb0c51d35">here</a>.</p>
<p>Aging and Disease Connection: The speaker, Juan Carlos Izpisua Belmonte, explains how age is the biggest risk factor for many diseases. As we age, cells lose their resilience or “buffer capacity,” making them more vulnerable to disease.</p>
<ul>
<li>Yamanaka Factors and Cell Reprogramming: Yamanaka’s discovery of four proteins (Yamanaka factors) that can reprogram adult cells into embryonic-like stem cells plays a crucial role. The focus now is on “partial reprogramming,” where a short pulse of these factors can rejuvenate cells without causing them to lose their identity (which could otherwise lead to cancer or malfunction).</li>
<li>Chromatin and the Epigenome: Belmonte explains how chromatin (DNA packaging) can either be open (leading to aging and disease) or closed (correlating with health and youth). Altering the chromatin to a more closed state can rejuvenate cells and potentially reverse disease.</li>
<li>Application Beyond Mice: This rejuvenation technology has been successfully tested in mice, including fixing genetic mutations and extending the lifespan of diseased mice. The next step is to apply these findings to human cells and organs, focusing on improving their resilience to disease without altering their genome.</li>
<li>Potential for Human Applications: Altos Labs aims to apply these techniques in humans, starting with ex vivo organ rejuvenation (e.g., preparing discarded organs for transplantation). The ultimate goal is to develop methods that can increase human cells’ buffer capacity, thereby extending health span and delaying or reversing aging-related diseases.</li>
<li>Future of Rejuvenation Therapies: The talk emphasizes the long-term potential of partial cell reprogramming to revolutionize human health by combating diseases linked to aging. The approach is described as a combination of cutting-edge science and industry, with billions of dollars invested in fundamental research and safe applications for human health.</li>
<li>Chamath asks whether lifestyle choices like exercise can slow the aging process or improve cellular buffer capacity. Belmonte reveals that the gene expression changes induced by exercise resemble those triggered by the short pulses of Yamanaka factors, showing that lifestyle interventions can have a significant impact on cellular health and longevity.</li>
</ul>
<p>I found it fascinating that cellular aging could be reversed. The easiest way we have access to that is through simple exercise which triggers gene expression changes induced by short pulses of Yamanka factors!</p>



 ]]></description>
  <category>aging</category>
  <category>exercise</category>
  <guid>https://lawrencewu.net/til/posts/2024-10-03-yamanaka-factors/</guid>
  <pubDate>Wed, 02 Oct 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Whisper large-v3-turbo</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2024-10-02-whisper-v3-turbo/</link>
  <description><![CDATA[ 





<p>OpenAI released a new version of their Whisper model caled <code>large-v3-turbo</code>. There is already <code>ggml</code> versions available <a href="https://huggingface.co/ggerganov/whisper.cpp/tree/main">here</a>.</p>
<ul>
<li><code>ggml-large-v3-turbo.bin</code></li>
<li><code>ggml-large-v3-turbo-q5_0.bin</code></li>
</ul>
<p>HuggingFace has a model card <a href="https://huggingface.co/openai/whisper-large-v3-turbo">here</a>. There’s a Github discussion <a href="https://github.com/openai/whisper/discussions/2363">here</a> talking about the model. It’s basically a distilled version of <code>large-v3</code>:</p>
<pre class="text"><code>We’re releasing a new Whisper model named large-v3-turbo, or turbo for short. It is an optimized version of Whisper large-v3 and has only 4 decoder layers—just like the tiny model—down from the 32 in the large series.

This work is inspired by Distil-Whisper, where the authors observed that using a smaller decoder can greatly improve transcription speed while causing minimal degradation in accuracy. Unlike Distil-Whisper, which used distillation to train a smaller model, Whisper turbo was fine-tuned for two more epochs over the same amount of multilingual transcription data used for training large-v3, i.e. excluding translation data, on which we don’t expect turbo to perform well.

Across languages, the turbo model performs similarly to large-v2, though it shows larger degradation on some languages like Thai and Cantonese. Whisper turbo performs better on FLEURS, which consists of cleaner recordings than Common Voice. The figure below shows the turbo model’s performance on the subset of languages in the Common Voice 15 and FLEURS datasets where large-v3 scored a 20% error rate or lower.</code></pre>
<p>I started using this model in my <a href="https://github.com/lawwu/transcripts/commit/4385305b1bf928e46d9f323cd1d4295dd231add8">transcripts repo</a>.</p>



 ]]></description>
  <category>whisper</category>
  <category>llm</category>
  <category>asr</category>
  <guid>https://lawrencewu.net/til/posts/2024-10-02-whisper-v3-turbo/</guid>
  <pubDate>Wed, 02 Oct 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Github Copilot Workspace</title>
  <dc:creator>Lawrence Wu</dc:creator>
  <link>https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/</link>
  <description><![CDATA[ 





<p>I was granted access to Github Copilot Workspace. It’s Github’s AI Coding Assistant built into Github.com where you can go from Github Issue to a Pull Request. I tried it, it’s pretty cool. The PR the service generated in my <a href="https://github.com/lawwu/transcripts">transcripts</a> repo is <a href="https://github.com/lawwu/transcripts/pull/3">here</a>. The workspace is viewable <a href="https://copilot-workspace.githubnext.com/lawwu/transcripts/issues/2?shareId=685875ce-8d8a-4c54-9376-f58bd34f89fe">here</a>.</p>
<p>The workflow is:</p>
<section id="create-an-issue" class="level2">
<h2 class="anchored" data-anchor-id="create-an-issue">1. Create an Issue</h2>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/0_issue.png" class="img-fluid figure-img"></p>
<figcaption>Create an Issue</figcaption>
</figure>
</div>
</section>
<section id="agent-will-create-a-spec" class="level2">
<h2 class="anchored" data-anchor-id="agent-will-create-a-spec">2. Agent will create a spec</h2>
<p>That you can edit</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/1_spec.png" class="img-fluid figure-img"></p>
<figcaption>Agent will create a specification</figcaption>
</figure>
</div>
</section>
<section id="agent-will-create-a-plan" class="level2">
<h2 class="anchored" data-anchor-id="agent-will-create-a-plan">3. Agent will create a plan</h2>
<p>The agent creates a plans of what files will be edited according to your spec.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/2_plan.png" class="img-fluid figure-img"></p>
<figcaption>Agent will create a plan</figcaption>
</figure>
</div>
</section>
<section id="agent-will-create-commits" class="level2">
<h2 class="anchored" data-anchor-id="agent-will-create-commits">4. Agent will create commits</h2>
<p>The agent then creates commits and a pull request! There’s also a chat interface to make revisions which is cool.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/3_commits_with_revise.png" class="img-fluid figure-img"></p>
<figcaption>Agent will create a PR</figcaption>
</figure>
</div>


</section>

 ]]></description>
  <category>github</category>
  <category>agent</category>
  <guid>https://lawrencewu.net/til/posts/2024-09-27-github-copilot-workspace/</guid>
  <pubDate>Fri, 27 Sep 2024 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
