Skip to main content

🔖 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


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)

Uploaded Source

Built Distribution

funcchain-0.0.11-py3-none-any.whl (11.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page