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 .