langchoice
1.0.0
PYPI:https://pypi.org/project/langchoice
switch-case ,但用于自由形式的句子。 if-then-else是一个单线。
Langchoice库使您可以根据自然语言句子谓词或触发器来调节结构化程序。可以轻松定义用户输入的条件流,而无需一遍又一遍地实现句子匹配操作员。
pip install langchoice
假设我们要检测传入的用户消息是否属于以下(问候,政治)主题之一。使用langchoice在几行中进行此操作。
首先定义定义每个主题类别(消息组)的文本消息。
triggers =
'''
greeting:
- hello
- hi
- what's up?
politics:
- what are your political beliefs?
- thoughts on the president?
- left wing
- right wing
'''LangStore数据容器。 data = yaml . safe_load ( triggers )
S = LangStore ( data )user_msg时,只需与主题匹配! match S . match ( user_msg , threshold = 1.2 , debug = True ):
case 'greeting' , _ : #user_msg matches the greeting message cluster
say_hello ()
case 'politics' , _ : #user_msg matches the politics message cluster
change_topic ()
case x :
print ( x )
print ( f'No defined triggers detected. Ask an LLM for response.' )从每个主题中添加或删除句子或引入新主题。即时工作!
支持多种匹配模式:
S.match返回最近消息的主题。S.match_centroid取而代之的是最接近的主题质心。S.match返回None 。 debug=True和debug_k=5 touser_msg到不同主题的距离。即将推出!
Langchoice软件包使您能够进行受控的聊天机器人流,并很快构建护栏。
关键的动机是允许用户在设计机器人时具有最大控制:
在示例中查看销售潜在客户过滤和约会预订机器人。
NISHANT SINHA,创始人,咨询科学家,Off Note Labs。
有关生成AI进化和应用的见解,请关注LinkedIn,并阅读我们的替代文章。