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,並閱讀我們的替代文章。