promptu
v1.0.0
動的な LLM プロンプトを自然言語として作成する
Promptu は、プロンプト エンジニア向けに、切り捨て、複数形化、自然言語リストの書式設定などの自然言語生成ユーティリティ スイートを提供します。
pip install promptu
from promptu import join
def find_matching_color ( existing_colors ):
return f'What color goes well with { join ( items = existing_colors , conjunction = "and" ) } ?'
# Prints "What color goes well with blue, purple and white?"
print ( find_matching_color ([ 'blue' , 'purple' , 'white' ]))
runnable = (
{ 'prompt' : RunnableLambda ( find_matching_color )}
| PromptTemplate . from_template ( '{prompt}' )
| model
)
runnable . invoke ([ 'blue' , 'purple' , 'white' ])
join()
項目のリストを自然言語リストとしてフォーマットします。
構文:
join ( items : Sequence , conjunction : str ) - > str
pluralize()
項目の数に基づいて単語の単数形または複数形を選択します。
構文:
pluralize ( singular : str , plural : str , items : Sized ) - > str
truncate()
文字列を最大長まで切り詰めます。テキストが最大長より長い場合は、最大長を超えたすべての文字が接尾辞に置き換えられます。
構文:
truncate (
text : str , max_length : int , mode = TruncateMode . CHARACTER , suffix = "..."
) - > str
PRの方も大歓迎です!関連する単体テストを追加または更新し、プロジェクトをblack .