Skip to main content

A Python client to interact with Phantasm's receiver server.

Project description

GitHub Discord License

Phantasm

This client library allows you to interact with Phantasm's receiver server from your Python codebase. It provides a simple and easy-to-use interface complete with type hints and documentation. Here's a quick example to get you started adding an approval workflow to your function:

from phantasmpy import Phantasm
phantasm = Phantasm()

# Replace with your own function.
@phantasm.require_approval()
def schedule_meeting(...):
    pass

schedule_meeting(...)

Advanced Usage With LangChain

In real-world applications, you may want to use Phantasm with LangChain to utilize the full power of LangChain's features. For the sake of simplicity, we will be using OpenAI's GPT model as our language model. Here's how you can build a tool-powered AI agent with human-in-the-loop capabilities:

Requirements:

pip install langchain langchain-openai phantasmpy
import os
from langchain_core.tools import tool
from langchain_core.messages import AIMessage
from langchain_openai import ChatOpenAI
from phantasmpy import Phantasm

os.environ["OPENAI_API_KEY"] = "xxx"
llm = ChatOpenAI(model="gpt-4o-mini")

@tool
def publish_blog(topic: str):
    # Add code to draft and publish the blog post.
    print(f"A blog post ({topic}) is published.")

@tool
def send_email(to: str, subject: str, body: str):
    # Add code to send an email using an email API.
    print(f"An email is sent to {to}.")

tools = [publish_blog, send_email]
llm_with_tools = llm.bind_tools(tools)
phantasm = Phantasm()

def call_tools(message: AIMessage):
    tool_map = {tool.name: tool for tool in tools}
    for tool_call in message.tool_calls:
        name, args = tool_call["name"], tool_call["args"]
        response = phantasm.get_approval(name=name, parameters=args)

        if response.approved:
            tool_map[name].invoke(response.parameters)
        else:
            print(f"Tool call {name} is rejected.")

chain = llm_with_tools | call_tools
chain.invoke("Remind elon@x.com about the Monday meeting at 9AM")

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

phantasmpy-0.1.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

phantasmpy-0.1.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file phantasmpy-0.1.3.tar.gz.

File metadata

  • Download URL: phantasmpy-0.1.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for phantasmpy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0d7c0fde0270931fba482e416c8fe9244276c0b2e49a17bc7cc9b6cc116515cd
MD5 6b71d6f27529c4603da55e992a84aa42
BLAKE2b-256 f2de9c85fd75c9fbdcb2275c3a7a9440688c589cba083f8ed20514e0c0980dda

See more details on using hashes here.

File details

Details for the file phantasmpy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: phantasmpy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for phantasmpy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 571403d8f5cf366ad408a45fd63acfaa7896864352ec09fdf163b20adf45c923
MD5 c84e91e5f886dbc19cd8456f30a21535
BLAKE2b-256 e755de0890668d07a4ac86d1806f63af65dcbfadd3387fe3fbb0e28112586975

See more details on using hashes here.

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