A Chat encapsulation based on AccessToken, useful for data annotation.
pip install webchatter --upgrade
Set environment variables:
export OPENAI_ACCESS_TOKEN="your_access_token"
export API_REVERSE_PROXY="http://your_reverse_proxy"
export WEB_REVERSE_PROXY="http://your_reverse_proxy/backend-api"
Where OPENAI_ACCESS_TOKEN
can be obtained after logging in to the website /api/auth/session. For reverse proxy setup, you can refer to the ninja project.
Data annotation example, performing addition:
from webchatter import process_messages
from random import randint
msgs = [f"find the result of {randint(3, 100)} + {randint(4, 100)}" for _ in range(4)]
# Annotate some data and get interrupted
process_messages(msgs[:2], "test.jsonl", interval=5, max_tries=3)
# Continue annotation
process_messages(msgs, "test.jsonl")
General usage:
from webchatter import WebChat
# Create a conversation
chat = WebChat()
# Input a question | Return an answer
chat.ask("hello world!")
# Get conversation history
chat.print_log()
Other usage:
from webchatter import WebChat
from pprint import pprint
chat = WebChat()
# View the total number of web chats
pprint(chat.num_of_chats())
# Get recent chats
pprint(chat.chat_list(limit=3))
# Continue a specific chat
chat_id = "xxx" # Retrieved from above
newchat = chat.chat_by_id(chat_id)
newchat.ask("ok, let's continue")