🔖 write prompts as python functions
Project description
funcchain
> pip install funcchain
Introduction
funcchain
is the most pythonic way of writing cognitive systems. Leveraging pydantic models as output schemas combined with langchain in the backend allows for a seamless integration of llms into your apps.
It works perfect with OpenAI Functions and soon with other models using JSONFormer.
Demo
from typing import Union, List
from langchain.pydantic_v1 import BaseModel, Field
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.todos:
print(f"{item.name}: {item.description}")
print(f"Urgency: {lst.urgency}")
Features
- increased productivity
- prompts as Python functions
- pydantic models as output schemas
- langchain schemas in the backend
- fstrings or jinja templates for prompts
- fully utilises OpenAI Functions
- minimalistic and easy to use
- langsmith support
- async support
Documentation
Coming soon and feel free to contribute
Contribution
You want to contribute? That's great! Please run the dev setup to get started:
> git clone https://github.com/shroominic/funcchain.git && cd funcchain
> ./dev_setup.sh
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.1.3.tar.gz
(12.0 kB
view hashes)
Built Distribution
funcchain-0.1.3-py3-none-any.whl
(14.8 kB
view hashes)
Close
Hashes for funcchain-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf7b2acead0f84335e1c482e02039ead66c19859576bdd470ea45be7c36ed0b |
|
MD5 | 6f3f424f4465915d3c8c7c85d2e372c6 |
|
BLAKE2b-256 | f10a79f6994cf72c572c3afe7fa7375ce93ffcce0a6231cd17860cd0b9787756 |