DEVELOPER.md
December 24, 2023 ยท View on GitHub
Developer Documentation
from WebChatGPT import ChatGPT
bot = ChatGPT(
"<path-to-openai-cookies.json>"
)
print(bot.chat('<Your Prompt>'))
#Ouput
"""
General Kenobi! How can I assist you today?
"""
A typical continuous implementation might look like :
import os, dotenv
from WebChatGPT import ChatGPT
dotenv.load_dotenv('.env')
from_env = lambda key: os.environ.get(key)
bot = ChatGPT(
from_env('openai_cookie_file')
)
while True:
print(bot.chat(input('>>>')))
#Output
"""
>>>hello there
General Kenobi! How can I assist you today?
>>>
"""
Furtherly, you can retrieve all the response returned in dict
from WebChatGPT import ChatGPT
bot = ChatGPT(
"<path-to-openai-cookies.json>"
)
response = bot.ask('<Your prompt>')
print(response)
Ouput :
{
"message": {
"id": "2c98d9ff-495c-4f08-af9e-affbd17xxxxx",
"author": {
"role": "assistant",
"name": null,
"metadata": {}
},
"create_time": 1702666802.823688,
"update_time": null,
"content": {
"content_type": "text",
"parts": [
"General Kenobi! How can I assist you today?"
]
},
"status": "finished_successfully",
"end_turn": true,
"weight": 1.0,
"metadata": {
"finish_details": {
"type": "stop",
"stop_tokens": [
100260
]
},
"inline_gizmo_id": null,
"is_complete": true,
"message_type": "next",
"model_slug": "text-davinci-002-render-sha",
"parent_id": "7bf27013-a47a-438c-ae17-0ee846b4xxxx",
"timestamp_": "absolute"
},
"recipient": "all"
},
"conversation_id": "affdda8c-588c-4342-9869-26c5bd7xxxxx",
"error": null
}
In order to extract only the text generated by chatgpt, pass the response to utils.get_message
As in :
response = bot.ask('<Your prompt'>)
from WebChatGPT import utils
message = utils.get_messsage(response)
print(message)
#Ouput
"""
"General Kenobi! How can I assist you today?"
"""
Streaming Responses
As of version v0.1.6 Onwards, streaming responses has been added.
Stream Text Only
from WebChatGPT import ChatGPT
bot = ChatGPT('<path-to-chat.openai.com.cookies.json>')
response = bot.chat('Okay I get you',stream=True)
for text in response:
print(text)
# Output
"""
Great
Great to
Great to hear
Great to hear!
Great to hear! If
Great to hear! If there
Great to hear! If there's
Great to hear! If there's anything
Great to hear! If there's anything else
Great to hear! If there's anything else I
Great to hear! If there's anything else I can
Great to hear! If there's anything else I can help
Great to hear! If there's anything else I can help you
Great to hear! If there's anything else I can help you with ...
Stream the whole body
from WebChatGPT import ChatGPT
bot = ChatGPT('<path-to-chat.openai.com.cookies.json>')
response = bot.ask('Okay I get you',stream=True)
for text in response:
print(text)
# Output
"""
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['Sounds']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['Sounds good']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['Sounds good!']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['Sounds good! If']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
{'message': {'id': '6ad41119-014b-4ef2-bbc2-c7efc53cxxxx', 'author': {'role': 'assistant', 'name': None, 'metadata': {}}, 'create_time': 1703362487.476225, 'update_time': None, 'content': {'content_type': 'text', 'parts': ['Sounds good! If you']}, 'status': 'in_progress', 'end_turn': None, 'weight': 1.0, 'metadata': {'inline_gizmo_id': None, 'message_type': 'next', 'model_slug': 'text-davinci-002-render-sha', 'parent_id': 'fd46e8a0-a088-46d7-acbd-038e2edxxxxx'}, 'recipient': 'all'}, 'conversation_id': 'fe42a288-6bfa-485d-9da1-ad9120xxxxxxx', 'error': None}
"""
Account Details
Check in detail
account_details = bot.user_details()
print(account_details)
Output :
{
"accounts": {
"b8a156d7-9a30-4de3-bf40-4d887xxxxxx": {
"account": {
"account_user_role": "account-owner",
"account_user_id": "user-IUW2uKHQ6bwv4bdiI8xxxxxx__b8a156d7-9a30-4de3-bf40-4d887xxxxx",
"processor": {
"a001": {
"has_customer_object": false
},
"b001": {
"has_transaction_history": false
},
"c001": {
"has_transaction_history": false
}
},
"account_id": "b8a156d7-xxxx-4de3-bf40-4d8878xxxxxx",
"organization_id": null,
"is_most_recent_expired_subscription_gratis": false,
"has_previously_paid_subscription": false,
"name": null,
"profile_picture_id": null,
"profile_picture_url": null,
"structure": "personal",
"plan_type": "free",
"is_deactivated": false,
"promo_data": {}
},
"features": [
"allow_url_thread_creation",
"arkose_enabled",
"arkose_gpt_35_experiment",
"bizmo_settings",
"breeze_available",
"chat_preferences_available",
"conversation_bot_arkose",
"disable_team_upgrade_ui",
"gizmo_live",
"gizmo_ui",
"invite_referral",
"new_plugin_oauth_endpoint",
"privacy_policy_nov_2023",
"shareable_links",
"starter_prompts",
"user_settings_announcements"
],
"entitlement": {
"subscription_id": null,
"has_active_subscription": false,
"subscription_plan": "chatgptfreeplan",
"expires_at": null
},
"last_active_subscription": {
"subscription_id": null,
"purchase_origin_platform": "chatgpt_not_purchased",
"will_renew": false
}
},
"default": {
"account": {
"account_user_role": "account-owner",
"account_user_id": "user-IUW2uKHQ6bwv4bdiI8IYtjqA__b8a156d7-9a30-4de3-bf40-xxxxxxxxxx",
"processor": {
"a001": {
"has_customer_object": false
},
"b001": {
"has_transaction_history": false
},
"c001": {
"has_transaction_history": false
}
},
"account_id": "b8a156d7-9a30-4de3-bf40-4d887829xxxx",
"organization_id": null,
"is_most_recent_expired_subscription_gratis": false,
"has_previously_paid_subscription": false,
"name": null,
"profile_picture_id": null,
"profile_picture_url": null,
"structure": "personal",
"plan_type": "free",
"is_deactivated": false,
"promo_data": {}
},
"features": [
"allow_url_thread_creation",
"arkose_enabled",
"arkose_gpt_35_experiment",
"bizmo_settings",
"breeze_available",
"chat_preferences_available",
"conversation_bot_arkose",
"disable_team_upgrade_ui",
"gizmo_live",
"gizmo_ui",
"invite_referral",
"new_plugin_oauth_endpoint",
"privacy_policy_nov_2023",
"shareable_links",
"starter_prompts",
"user_settings_announcements"
],
"entitlement": {
"subscription_id": null,
"has_active_subscription": false,
"subscription_plan": "chatgptfreeplan",
"expires_at": null
},
"last_active_subscription": {
"subscription_id": null,
"purchase_origin_platform": "chatgpt_not_purchased",
"will_renew": false
}
}
},
"account_ordering": [
"b8a156d7-9a30-4de3-bf40-4d88782xxxx"
]
}
Check in Summary
user_details = bot.user_details(in_details=False)
print(user_details)
Output :
{
"account_plan": {
"is_paid_subscription_active": false,
"subscription_plan": "chatgptfreeplan",
"account_user_role": "account-owner",
"was_paid_customer": false,
"has_customer_object": false,
"subscription_expires_at_timestamp": null
},
"user_country": "KE",
"features": [
"chat_preferences_available",
"allow_url_thread_creation",
"breeze_available",
"bizmo_settings",
"invite_referral",
"conversation_bot_arkose",
"starter_prompts",
"shareable_links",
"gizmo_ui",
"new_plugin_oauth_endpoint",
"privacy_policy_nov_2023",
"gizmo_live",
"arkose_enabled",
"user_settings_announcements",
"disable_team_upgrade_ui",
"arkose_gpt_35_experiment"
]
}
Generate Random Prompts
random_prompts = bot.prompt_library()
print(random_prompts)
Output :
{
"items": [
{
"id": "9575dxxx",
"title": "Plan a trip",
"description": "to explore the rock formations in Cappadocia, Turkey",
"prompt": "I'd like to see the rock formations in Cappadocia, Turkey. Can you plan a 3-day trip around that?"
},
{
"id": "d360exxx",
"title": "Explain airplane turbulence",
"description": "to someone who has never flown before",
"prompt": "Can you explain airplane turbulence to someone who has never flown before? Make it conversational and concise."
},
{
"id": "4284axxx",
"title": "Make up a story",
"description": "about Sharky, a tooth-brushing shark superhero",
"prompt": "Make up a 5-sentence story about \"Sharky\", a tooth-brushing shark superhero. Make each sentence a bullet point."
},
{
"id": "edb56xxx",
"title": "Design a database schema",
"description": "for an online merch store",
"prompt": "Design a database schema for an online merch store."
}
],
"total": 4,
"limit": 4,
"offset": 0
}
Previous Conversations
history = bot.previous_conversations()
print(history)
Ouput :
{
"items": [
{
"id": "86f73b54-0f51-47ba-84a3-07c1e25xxxx",
"title": "Urine Cleaning in Rome",
"create_time": "2023-12-15T13:39:24.683876+00:00",
"update_time": "2023-12-15T14:02:23.776574+00:00",
"mapping": null,
"current_node": null,
"conversation_template_id": null,
"gizmo_id": null,
"is_archived": false,
"workspace_id": null
},
{
"id": "b3779121-8767-4202-9527-3058f40xxxx",
"title": "Helpful User, Assistant",
"create_time": "2023-12-15T12:03:30.596706+00:00",
"update_time": "2023-12-15T13:29:05.286457+00:00",
"mapping": null,
"current_node": null,
"conversation_template_id": null,
"gizmo_id": null,
"is_archived": false,
"workspace_id": null
}
],
"total": 108,
"limit": 2,
"offset": 0,
"has_missing_conversations": false
}
Generate Conversation Title
title = bot.generate_title('<conversation_id>','<message_id>')
print(title)
Output :
{
"message": "Conversation 9e13dab6-df3a-4467-8918-40b1xxxxxxxx already has title 'Summarize To Four Words'"
}
Other attributes include:
- Chat History :
bot.chat_history(conversation_id : str)
- Rename conversation :
bot.rename_conversation(conversation_id :str, title:str)
- Share conversation :
bot.share_conversation(conversation_id : str )
- Delete conversation :
bot.delete_conversation(conversation_id: str)
- Retrieve shared conversations :
bot.shared_conversations()
- Stop sharing conversation :
bot.stop_sharing_conversation(share_id : str)
- Archive conversation :
bot.archive_conversation(conversation_id : str)
For further info, purpose to review the flow of operations.