시작하기무료로 시작하기

Few-shot 예시 제공하기

구조화된 출력은 데이터를 어떻게 반환할지에 대해서는 정의하지만, 무엇을 반환해야 하는지에 대해서는 아직 해석의 여지가 많아요.

Field 클래스는 좋은 추출 결과가 어떤 모습인지 LLM에 알려 줄 수 있는 예시 값을 제공할 수 있게 해줘요. 이는 구조화된 출력에 대한 few-shot 프롬프트의 한 예예요.

Character 클래스를 확장하여 캐릭터를 고유하게 식별할 수 있는 id 필드를 추가하려고 해요. 모델이 참고할 수 있도록 두 가지 예시를 제공하려고 합니다: "romeo-montague""lady-capulet".

이 연습은 강의의 일부입니다

LangChain과 Neo4j로 배우는 Graph RAG

강의 보기

연습 안내

  • id 속성에 대한 예시 값을 제공할 키워드를 지정하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

class Character(BaseModel):
	id: str = Field(
		description="A unique identifer consisting of the Character's given name and their family name in slug case.", 
		# Provide example values of an ID
		____=["romeo-montague", "lady-capulet"]
	)
	name: str = Field(description="The name of the character")

chain = prompt | llm.with_structured_output(Character)

chain.invoke({"text": """JULIET.
O Romeo, Romeo, wherefore art thou Romeo? Deny thy father and refuse thy name. Or if thou wilt not, be but sworn my love, And I’ll no longer be a Capulet."""})
코드 편집 및 실행