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?

More than 3 years have passed since last update.

[翻訳] LangChainにおけるプロンプトのGetting Started

0
Posted at

Getting Started — 🦜🔗 LangChain 0.0.184の翻訳です。

本書は抄訳であり内容の正確性を保証するものではありません。正確な内容に関しては原文を参照ください。

このセクションにはプロンプトに関する全てが含まれています。プロンプトは、言語モデルに引き渡される値です。この値は、(LLM向けの)文字列あるいは(チャットモデル向けの)メッセージのリストとなります。これらのプロンプトのデータタイプは比較的シンプルですが、それらの構築はそうではありません。ここでのLangChainの訴求価値には以下があります:

  • 文字列のプロンプトとメッセージプロンプトの標準的インタフェース
  • 文字列プロンプトテンプレートとメッセージプロンプトテンプレートの(使い始めるための)標準的なインタフェース
  • サンプルセレクター: 言語モデルが従うプロンプトにサンプルを挿入する手法
  • 出力パーサー: 言語モデルが情報を出力するフォーマットとしてプロんtぷとに対する指示を埋め込む手法と、出力文字列をフォーマットにパースする手法

文字列プロンプト固有のタイプ、チャットプロンプト固有のタイプ、サンプルセレクター、出力パーサーに関する詳細なドキュメントがあります。

ここでは、シンプルなプロンプトを用いて使い始める際の標準インタフフェースのクイックスタートをカバーします。

PromptTemplates

PromptTemplatesはプロンプトの値を構築することに責任を持ちます。これらのPromptTemplatesはフォーマッティング、サンプル選択などを行うことができます。ハイレベルでは、これらは基本的にはプロンプトを構築するためのformat_promptを公開するオブジェクトです。内部ではいろいろなことが行われます。

from langchain.prompts import PromptTemplate, ChatPromptTemplate
string_prompt = PromptTemplate.from_template("tell me a joke about {subject}")
chat_prompt = ChatPromptTemplate.from_template("tell me a joke about {subject}")
string_prompt_value = string_prompt.format_prompt(subject="soccer")
chat_prompt_value = chat_prompt.format_prompt(subject="soccer")

to_string

これは、(生のテキストを期待する)LLMに値を渡す際に呼び出されます。

string_prompt_value.to_string()
'tell me a joke about soccer'
chat_prompt_value.to_string()
'Human: tell me a joke about soccer'

to_messages

これは、(メッセージのリストを期待する)チャットモデルに値を渡す際に呼び出されます。

string_prompt_value.to_messages()
[HumanMessage(content='tell me a joke about soccer', additional_kwargs={}, example=False)]
chat_prompt_value.to_messages()
[HumanMessage(content='tell me a joke about soccer', additional_kwargs={}, example=False)]
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?