Phound SDK
Project description
Installing
pip install phound
Usage
Create and fill in .env file within your project's directory with:
SBC=wss://ow-sbc.phound.app/ucp
UID=<uid>
TOKEN=<token>
Simple python chatbot could look like:
import os
import time
from phound import Phound
from phound.handlers import BaseChatHandler
class ChatHandler(BaseChatHandler):
def on_message(self, message):
print(f"Got new message: {message}")
self.show_typing()
time.sleep(1)
chat_history = self.get_history(depth=10)
reply_items = [f"Initial message: {message.text}",
f"response: {message.text[::-1]}",
f"also got chat history with last {len(chat_history)} messages"]
self.send_message(os.linesep.join(reply_items))
if __name__ == "__main__":
with Phound() as phound:
phound.register_chat_handler(ChatHandler)
phound.start_listen_events()
API Reference
Phound:
The Phound interface provides the following methods:
register_chat_handler(self, handler: BaseChatHandler, chat_types: Tuple[str, ...] = ("private",))- Registers specified chat handler,chat_typesaccepts tuple of chat types to handle, valid values are "private" and "group"start_listen_events()- Starts listen events
BaseChatHandler:
Each instance of BaseChatHandler provides the following interface:
Attributes:
persona_uid: str- The unique ID of the persona listening to the chat.chat_type: str- Either "private" or "group".
Methods:
on_message(self, message: Message)- Called when a new message is received in the chat.show_typing(self, timeout: int = 60)- Displays a typing indicator in the chat. The indicator is shown for the specifiedtimeoutor until the next message is sent by the handler.send_message(self, text: str)- Sends a message with the specified text to the chat.get_history(self, depth: int = 10, start_message_id: str = "0")- Retrieves the chat history as a list ofMessageobjects. Thedepthparameter determines the number of messages to retrieve, andstart_message_idcan be used to obtain history starting from a specific message ID. Using"0"as thestart_message_idstarts from the last message.
Message:
The Message interface provides the following attributes:
id: str- The ID of the message.text: str- The text content of the message.from_uid: str- The unique ID of the persona from which the message originated.tagged: bool- Indicates whether the persona listening to the chat was tagged in the message.
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 Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phound-0.1.0-py3-none-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: phound-0.1.0-py3-none-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 3.3 MB
- Tags: Python 3, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e98666609cc81a81314fb54544db4edbd246dffcca15f47a1638cff9c61e789
|
|
| MD5 |
833fb38d5cde6030b05d4956eadc63f4
|
|
| BLAKE2b-256 |
9b44eca65ea4d397a24145232e10877b6d337fbae0d307d09d2b9a09514a3198
|
File details
Details for the file phound-0.1.0-py3-none-macosx_14_0_arm64.whl.
File metadata
- Download URL: phound-0.1.0-py3-none-macosx_14_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f698dd830750001fd515206f0204cce3ee640e23f40b7b6069faf6abcb079c7d
|
|
| MD5 |
f659e63361a347af00e4ed88c5523de1
|
|
| BLAKE2b-256 |
1f0e08d2244b0988582de7a5d651e05f9596caf231601d0e165bf0da0698f707
|