AI Prompts as Code (APaC) を定義するためのシンプルかつエレガントなマークアップ言語。 AI エージェントが他の AI システムを自動的に要求するために使用するように構築されています。
PromptML は、プロンプト エンジニアが AI プロンプトを決定論的な方法で定義する方法を提供するために構築されています。これは、コンテキスト、目的、指示、メタデータなどのプロンプトの特性を定義するドメイン固有言語 (DSL) です。通常のプロンプトは、これらすべての側面を 1 つのエンティティに統合したものです。 PromptML はそれを複数のセクションに分割し、情報を明示します。
言語の文法はここにあります: grammar.lark
ここからpromptml-cli
をインストールします: https://github.com/narenaryan/promptml-cli で、OpenAI および Google モデルで PromptML プログラムを実行します。
言語は単純です。ブロックは@
セクション アノテーションで開始します。セクションは@end
マーカーで終了します。コメントは#
キーで始まります。プロンプト ファイルは.pml
拡張子で終わります。
@prompt
# Add task context
@context
@end
# Add task objective
@objective
# This is the final question or ask
@end
# Add one or more instructions to execute the prompt
@instructions
@step
@end
@end
# Add one or more examples
@examples
@example
@input
# Add your example input
@end
@output
# Add your example output
@end
@end
@end
# Add task constraints
@constraints
@length min: 1 max: 10 @end
@end
# Add prompt category
@category
@end
# Add custom metadata
@metadata
@end
@end
完全な構文については、prompt.pml を参照してください。
通常のテキスト プロンプトは本質的に非常に抽象的です。自然言語は非常に柔軟性がありますが、信頼性は最も低くなります。 AI システムにコンテキストを提供して何かを尋ねるにはどうすればよいでしょうか?それを明示的に明記すべきではないでしょうか。 PromptML は、単純な言語を使用してプロンプトの内容を明示的にしようとする試みです。
以下は、PromptML がプロンプト エンジニアリング ドメインにもたらす特性です。
まず、XML、JSON、YAML は DSL 言語ではありません。これらは、あらゆる形式のデータを表現できるデータ形式です。第 2 に、生成 AI には、ドメインとともに進化する固定制約を備えた、厳格でありながら柔軟なデータ言語が必要です。
PromptML は、まさにこれら 2 つの問題を解決するために構築されています。
言語文法は XML と Ruby の影響を受けるため、これらのいずれかを知っていれば、PromptML でプロンプトを非常に快適に作成できるようになります。
pip install -r requirements.txt
from promptml . parser import PromptParser
promptml_code = '''
@prompt
@context
This is the context section.
@end
@objective
This is the objective section.
@end
@instructions
@step
Step 1
@end
@end
@examples
@example
@input
Input example 1
@end
@output
Output example 1
@end
@end
@end
@category
Prompt Management
@end
@constraints
@length min: 1 max: 10 @end
@end
@metadata
top_p: 0.9
n: 1
team: promptml
@end
@end
'''
parser = PromptParser ( promptml_code )
prompt = parser . parse ()
print ( prompt )
# Output: {
# 'context': 'This is the context section.',
# 'objective': 'This is the objective section.',
# 'category': 'Prompt Management',
# 'instructions': ['Step 1'],
# 'examples': [
# {'input': 'Input example 1', 'output': 'Output example 1'}
# ],
# 'constraints': {'length': {'min': 1, 'max': 10}},
# 'metadata': {'top_p': 0.9, 'n': 1, 'team': 'promptml'}
# }
プロンプトML ファイルで変数を定義し、それらをプロンプトのcontext
およびobjective
で使用できます。変数は@vars
セクションで定義され、 context
またはobjective
セクションで$var
構文を使用して参照されます。
@vars
name = "John Doe"
@end
@prompt
@context
You are a name changing expert.
@end
@objective
You have to change the name: $name to an ancient name.
@end
@end
PromptML ドキュメントは、次のような複数の形式にシリアル化できます。
XML プロンプトは LLM によってよく理解されており、promptML コードを使用して次のような XML プロンプトを生成できます。
この README ファイルの前の例から、 prompt
オブジェクトでto_xml()
メソッドを呼び出して XML プロンプトを生成できます。
# XML
serialized = prompt . to_xml ()
print ( serialized )
同様に、同じオブジェクトから YAML プロンプトまたは JSON プロンプトをそれぞれ生成できます。
# JSON
prompt . to_json ()
# YAML
prompt . to_yaml ()
現在、次のことに取り組んでいます。
VSCode
構文ハイライトのサポート