switch-case over free-form sentences.
Project description
PyPI: https://pypi.org/project/langchoice
🤖 About LangChoice
switch-case
, but for free-form sentences. A one-liner for `if-then-else`` over similar sentences.
The LangChoice library allows you to condition your structured programs over natural language sentence predicates or triggers. Makes it easy to define conditional flows over user inputs without implementing the sentence match operator over and over again.
📦 Installation
pip install langchoice
🧪 Getting Started
Suppose you want to detect if the user mentioned one of the following (greeting, politics) triggers:
triggers =\
'''
greeting:
- hello
- hi
- what's up?
politics:
- what are your political beliefs?
- thoughts on the president?
- left wing
- right wing
'''
- Set up a
LangStore
data container.
data = yaml.safe_load(triggers)
S = LangStore(data)
- On receiving a user message
user_msg
, simply match!
match S.match(user_msg):
case 'greeting', _ : #user_msg matches any of the greeting message cluster
say_hello()
case 'politics', _ : #user_msg matches any of the politics message cluster
change_topic()
case x :
print(x)
print(f'No defined triggers detected. Ask an LLM for response.')
Do More!
Implement a graph-based Conversation Flow
Debug
-
Get match scores for each group to debug what went wrong.
-
In built assertions, which fail if the execution fails to match the expected topic / group.
Roadmap
[] allow switching under-the-hood sentence encoders
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for langchoice-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bdc93960c1911f728b58a594d4ec5602643cc970c6d3d57a245bccbd3d9efe7 |
|
MD5 | 552412b3bdb1028e25145834fa30ebfd |
|
BLAKE2b-256 | d212c457848d6e572ffa493b760eaa31dc7bd30d168604fe9931c17596dec8d6 |