FeelCoolOne / python-pi-chat

heypi, unofficial python client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pi chatbot client

This is an unofficial python client for Pi chatbot (from Inflection AI). It doesn't require authentication.

Installation

python setup.py

Demo

Run python examples/chat.py to test it.

Prompt Demo

Usage

from heypi.client import Client as PiChat
from heypi.prompt import Prompt

chatbot = PiChat()

conversation = chatbot.createConversation()

answer = conversation.ask(new Prompt("Hello World"))
Real-time / progressive answer

Pi tends to send the whole message in one shot so this can be useless.

You may pass a function as second argument to get real-time progression:

// current_answer - incomplete answer
// tokens - last tokens received
final_answer = conversation.ask(prompt, lambda current_answer, tokens: print(tokens))
Resume a conversation

If you want to resume a previous conversation, you can retrieve its identifiers:

// Get current identifiers
identifiers = conversation.getIdentifiers()

// ...
// Resume conversation with identifiers parameter
conversation = chatbot.resumeConversation(identifiers)
Error handling

The code throws exceptions when it receives an error from Pi. You can therefore use a try/catch block to handle errors.


Disclaimer

This code is for educational purpose only. Using Pi outside heypi.com may violate Inflection AI terms.

About

heypi, unofficial python client


Languages

Language:Python 100.0%