From eabb4bc3fe12f57415c926417a2fbf9219366794 Mon Sep 17 00:00:00 2001 From: Simatwa Date: Sat, 23 Dec 2023 23:20:34 +0300 Subject: [PATCH] Document about streaming responses --- docs/CHANGELOG.md | 5 ++-- docs/DEVELOPER.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1390b22..fa37f78 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -75,5 +75,6 @@ More console chat manipulation features. ## v0.1.6 **What's new?** -- Support for streaming response -- Stream response at console - (*default*) \ No newline at end of file +- Support streaming response +- Stream response at console - (*default*) +- Specify stdout font color at console \ No newline at end of file diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index 34f51f0..080ed80 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -138,6 +138,63 @@ print(message) +## Streaming Responses + +As of version **v0.1.6** Onwards, streaming responses has been added. + +### Stream Text Only + +```python +from WebChatGPT import ChatGPT + +bot = ChatGPT('') + +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 + +```python +from WebChatGPT import ChatGPT + +bot = ChatGPT('') + +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 @@ -490,7 +547,9 @@ Other attributes include: For further info, purpose to review the [flow of operations.](operations_flow.md) +

CHANGELOG