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を動かしてみた結果 → ハルシネーション芸を披露してくれた

Posted at

はじめに

LangChainって名前はよく聞くけど、何なの?
まずは「Hello World」レベルで動かしてみた記録です。

結論:ちゃんと動いたけど、回答がブロックチェーン芸だった(笑)

環境構築

使用環境

  • MacBook Air (Python 3.9)
  • pip3 / venv

インストール手順

pip3 install -U langchain langchain-openai openai python-dotenv

プロジェクトフォルダ直下に .env を作成:

OPENAI_API_KEY=sk-xxxxxx...

最小構成のコード

from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)

prompt = ChatPromptTemplate.from_messages([
    ("system", "あなたは親切なアシスタントです。"),
    ("human", "{question}")
])

chain = prompt | llm

response = chain.invoke({"question": "LangChainとは何ですか?"})
print(response.content)

実行してみた結果

初回

openai.RateLimitError: insufficient_quota

→ 無料枠が切れていたので課金しました 💸

その後の出力

LangChainは、ブロックチェーン技術を活用して言語学習者とネイティブスピーカーをつなぐプラットフォームです...

ハルシネーション芸

  • LangChain ≠ ブロックチェーン
  • 正しくは「LLMアプリ開発を支援するフレームワーク」
  • LLMは時々こういう 自信満々な間違い を返します(=ハルシネーション)

動かせた達成感と、ハルシネーションに笑う体験を同時に味わえました。

学び・次のステップ

  • とりあえず 動作確認は完了 ✅
  • 今後やりたいこと
    • PDFを読み込んで質問に答える(RAG)
    • エージェントで計算や外部APIを呼ぶ
    • ハルシネーションを減らす工夫(プロンプト設計、検索統合)

最後までお読みいただきありがとうございました。

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?