BaşlayınÜcretsiz Başlayın

Creating a structured output

Structured outputs are key to extracting consistent outputs from Large Language Models, which is crucial in lots of applications.

Here, you'll use the pydantic library to define the properties that describe a Character in Romeo and Juliet via a Character class. In the next exercise, you'll use this to extract characters as structured outputs from a section of the play.

Bu egzersiz

Graph RAG with LangChain and Neo4j

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a Character class that extends from the appropriate pydantic base class.
  • Define the name property of the class.
  • Define an optional family property to account for characters whose family may be unknown.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

from pydantic import BaseModel, Field
from typing import Optional

# Inherit the correct pydantic class
class Character(____):
	# Describe the name property
	name: str = ____("The full name of the character")                
	# Set family to optional
	____: Optional[str] = Field("The name of the family they belong to")
Kodu Düzenle ve Çalıştır