0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LangChain pydanticを触ってみた

Posted at

やってみたこと

昨日、ConpassのLang Chainのイベントで登壇者が話されていた「pydantic」が
気になったので触ってみた!
ゴールはとりあえず何かしらのプロンプトの返答が返ってきたらOK!

書いてみた(いやほぼ真似してみた)

pydanticは構造化してくれるよう。。
他がまだあまり詳しくないのでメリットがわかっていない。。

from langchain_openai import ChatOpenAI
from pydantic import BaseModel

class Output(BaseModel):
    """Output Structure"""
    answer: str
    reason: str
    
model = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind(seed=0)
model = model.with_structured_output(Output)

output = model.invoke('海外で住みやすい都市を理由をつけて教えて下さい。')
print(output.answer)

!回答

バンクーバー(カナダ)
   - 理由:美しい自然環境、温暖な気候、多文化共生が魅力。教育水準が高く、医療制度も充実しているため、生活の質が高い。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?