🔖 write langchain prompts as python functions
Project description
funcchain
🔖 write langchain prompts as python functions
Demo
from langchain.pydantic_v1 import BaseModel, Field
from typing import Union, List
from funcchain import chain
class Item(BaseModel):
name: str = Field(..., description="Name of the item")
description: str = Field(..., description="Description of the item")
keywords: List[str] = Field(..., description="Keywords for the item")
class ShoppingList(BaseModel):
""" List of items to buy """
items: List[Item]
store: str = Field(..., description="The store to buy the items from")
class TodoList(BaseModel):
todos: List[Item]
urgency: int = Field(..., description="The urgency of all tasks (1-10)")
def extract_list(user_input: str) -> Union[TodoList, ShoppingList]:
"""
USER_INPUT:
{user_input}
The user input is either a shopping List or a todo list.
"""
return chain()
user_input = input("Enter your list: ")
lst = extract_list(user_input)
if isinstance(lst, ShoppingList):
print("Here is your Shopping List: ")
for item in lst.items:
print(f"{item.name}: {item.description}")
print(f"You need to go to: {lst.store}")
if isinstance(lst, TodoList):
print("Here is your Todo List: ")
for item in lst.items:
print(f"{item.name}: {item.description}")
print(f"Urgency: {lst.urgency}")
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
funcchain-0.0.11.tar.gz
(9.4 kB
view hashes)
Built Distribution
funcchain-0.0.11-py3-none-any.whl
(11.8 kB
view hashes)
Close
Hashes for funcchain-0.0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40c2de3d3c453796d25c63672e7d47892f57621c65b5681e8ef950e815304b42 |
|
MD5 | 4b7f6c1884a8444d156158a4f1862271 |
|
BLAKE2b-256 | e2a3223feb612a479a4c17b26e1d04ebd80ab72ef91c1074ca8f72c07601bcc7 |