Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

Messing about with getting structured outputs from an LLM. The concept of 'tools' in Vercel's 'ai' lib makes this pretty simple.

41,182 görüntüleme • 1 yıl önce •via X (Twitter)

10 Yorum

David K 🎹 profil fotoğrafı
David K 🎹1 yıl önce

Nice! Unsolicited feedback: I'd use gpt-4o-mini (more recent) and wouldn't rely too much on the confidence score, since those aren't easily quantifiable and LLMs are not that good with numbers. Another idea is to have it return "not confident", "somewhat confident", ... from an enum instead. Another idea: have a chain of prompts which first classify whether the input is a country or not, and if it is, provide the capital. Begins to look like a state machine 🚀

Nico Albanese profil fotoğrafı
Nico Albanese1 yıl önce

tools are so cool! Btw if you’re looking for pure structured output, check out the generateObject and streamObject functions

typeofalex profil fotoğrafı
typeofalex1 yıl önce

Tools exist on the original APIs, no need for Vercel’s ai libs I want to add.

Matt Pocock profil fotoğrafı
Matt Pocock1 yıl önce

Useful, thanks!

saurabh gaur profil fotoğrafı
saurabh gaur1 yıl önce

It’d be amazing to see a full totaltypescript kind of course from you on the Vercel AI SDK soon, pls pls make one!

Jayden Carey profil fotoğrafı
Jayden Carey1 yıl önce

Maybe worth checking out agentic by @transitive_bs if you're wanting to go deeper with tools. Has a good stdlib collection to play with + you can use it to write SDK agnostic tools if desired.

0xPooka profil fotoğrafı
0xPooka1 yıl önce

LOL trying to get the LLM to cooperate the same way it did previously with Djibouti was just hilarious. I haven’t seen this before though I’m excited to try it!

Christoffer Bjelke profil fotoğrafı
Christoffer Bjelke1 yıl önce

Have you looked at TypeChat? Havent digged deep yet, but seems very interesting. Maybe "outdated" with these new APIs though

Masood profil fotoğrafı
Masood1 yıl önce

That's awesome! I didn't know you could use zod with Vercel AI

Tarek Kh profil fotoğrafı
Tarek Kh1 yıl önce

Really Nice!

Benzer Videolar

New Short Course: Getting Structured LLM Output! Learn how to get structured outputs from your LLM applications in this course, built in partnership with .txt, and taught by Will Kurt, a Founding Engineer, and , Developer Relations Engineer. It's challenging for software to automatically parse through an LLM's freeform text outputs. Structured outputs—like JSON—solve this by converting natural language into consistent, clear, data that a machine can read and process. This course teaches you how to generate structured outputs while building several use cases, including a social media analysis agent. You’ll learn about structured outputs and efficient ways to generate outputs in your defined schema or format. You’ll begin by using structured output APIs, then use re-prompting libraries like “instructor” to generate structured output. Finally, you’ll learn how constrained decoding works; this is a very clever technique in which constraints are applied on each subsequent token generated, blocking any tokens that don’t fit your defined schema. In detail, you’ll: - Learn why structured outputs are important, how they allow for scalable software development, and the different approaches to generate them, including vendor-provided APIs, re-prompting libraries, and structured generation. - Build a simple social media agent using OpenAI’s structured output API, learn how to define a model's desired structured output using Pydantic, and perform basic programming with your outputs, such as importing structured data into a data frame using pandas. - Learn how to use the open-source library "instructor," which checks the structured output of the model and re-prompts the model until it validates the desired output, and explore the limitations of this approach. - Understand how structured generation by the “outlines” library works by modifying LLM logits, on a per-generated-token basis based on the desired format, to give a particular output structure. - Learn how regular expressions, which outlines works with, are represented as finite-state machines, and how they can be used to develop a range of structured outputs beyond JSON. By the end of this course, you’ll have broadened your knowledge of the approaches you can use to get structured outputs from your LLM applications. Please sign up here:

Andrew Ng

89,779 görüntüleme • 1 yıl önce