Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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

41,182 Aufrufe • vor 1 Jahr •via X (Twitter)

10 Kommentare

Profilbild von David K 🎹
David K 🎹vor 1 Jahr

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 🚀

Profilbild von Nico Albanese
Nico Albanesevor 1 Jahr

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

Profilbild von typeofalex
typeofalexvor 1 Jahr

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

Profilbild von Matt Pocock
Matt Pocockvor 1 Jahr

Useful, thanks!

Profilbild von saurabh gaur
saurabh gaurvor 1 Jahr

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

Profilbild von Jayden Carey
Jayden Careyvor 1 Jahr

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.

Profilbild von 0xPooka
0xPookavor 1 Jahr

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!

Profilbild von Christoffer Bjelke
Christoffer Bjelkevor 1 Jahr

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

Profilbild von Masood
Masoodvor 1 Jahr

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

Profilbild von Tarek Kh
Tarek Khvor 1 Jahr

Really Nice!

Ähnliche Videos

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,720 Aufrufe • vor 1 Jahr