# ChatAssist
An advanced Python library for handling ChatGPT interactions.
---
## **Features**
- **Save and Resume Conversations**: Save conversation history to a file and reload it later.
- **Proxy Support**: Send API requests through a user-defined proxy.
- **Configurable Parameters**: Customize settings like `temperature`, `top_p`, and `max_tokens`.
- **Stream Output**: Display responses incrementally as they are generated.
- **Command-Line Interface**: Quickly interact with ChatGPT from the terminal.
- **Graphical User Interface**: User-friendly GUI for non-technical users.
- **Markdown Rendering in GUI**: Display formatted text and code blocks in responses.
- **Built-in Logging**: Log all interactions for debugging or auditing purposes.
- **Dynamic Model Selection**: Switch between models like GPT-3.5-Turbo or GPT-4.
---
## **Installation**
### **From Source**
Install the library from the source code:
```bash
pip install .
```
For development mode:
```bash
pip install -e .
```
### **Verify Installation**
Run this command to verify:
```bash
python -c "import chatassist; print(chatassist.__version__)"
```
You should see the version number printed.
---
## **Usage**
### **Python API**
The `ChatAssist` library provides a simple API for interacting with ChatGPT.
```python
from chatassist.api import ChatGPTAPI
from chatassist.utils import load_api_key
# Load the API key
api_key = load_api_key("api_key.txt")
# Initialize the ChatGPT API client
api = ChatGPTAPI(api_key=api_key)
# Send a message
response = api.send_message("Hello, ChatGPT!")
print(response)
```
### **Saving and Resuming Conversations**
Use the `Conversation` class to manage chat histories:
```python
from chatassist.conversation import Conversation
conversation = Conversation()
conversation.add_message("user", "Hello!")
conversation.add_message("assistant", "Hi there! How can I assist you?")
# Save to a file
conversation.save_to_file("conversation.json")
# Reload the conversation
loaded_conversation = Conversation()
loaded_conversation.load_from_file("conversation.json")
print(loaded_conversation.get_history())
```
### **Using Proxies**
Pass a proxy configuration to route API requests through a proxy server:
```python
api = ChatGPTAPI(api_key=api_key, proxies={"http": "http://proxy.example.com:8080"})
response = api.send_message("What is Python?")
print(response)
```
---
## **Command-Line Interface**
The CLI allows you to interact with ChatGPT directly from the terminal.
### **Basic Usage**
```bash
chatassist-cli "What is the capital of France?" --api-key-path api_key.txt
```
### **Export Conversation**
Save the conversation to a file:
```bash
chatassist-cli "Tell me about Python." --export conversation.json
```
---
## **Graphical User Interface**
The GUI provides an intuitive way to interact with ChatGPT.
### **Launching the GUI**
Run the following command:
```bash
python -m chatassist.gui
```
### **Features**
1. **Type and Send Messages**:
- Enter your message in the input field and press "Send".
- Responses are displayed in the chat window.
2. **Save and Load Conversations**:
- Export the conversation to a file for later use.
- Reload previous conversations using the "Load Conversation" option.
---
## **Configuration Parameters**
The `ChatAssist` API allows you to fine-tune interactions with the following parameters:
- **`temperature`**: Controls the randomness of responses.
- **`top_p`**: Limits responses to the top tokens in cumulative probability.
- **`max_tokens`**: Restricts the number of tokens in the response.
- **`model`**: Allows you to switch between models, e.g., `gpt-3.5-turbo` or `gpt-4`.
```python
response = api.send_message(
"Tell me about AI.",
temperature=0.5,
top_p=0.8,
max_tokens=500
)
print(response)
```
---
## **Practical Examples**
### **1. Simple FAQ Bot**
```python
questions = ["What is Python?", "What is AI?", "Who created ChatGPT?"]
for question in questions:
response = api.send_message(question)
print(f"Q: {question}
A: {response}
")
```
### **2. Programming Assistant**
```python
prompt = "Explain the concept of recursion with a Python example."
response = api.send_message(prompt)
print(response)
```
### **3. Travel Guide**
```python
prompt = "What are the best tourist attractions in Paris?"
response = api.send_message(prompt)
print(response)
```
### **4. Math Solver**
```python
problem = "What is the result of 123 * 456?"
response = api.send_message(problem)
print(response)
```
### **5. Language Translator**
```python
prompt = "Translate 'Hello, how are you?' into Spanish."
response = api.send_message(prompt)
print(response)
```
---
## **Testing**
### **Run All Tests**
Navigate to the `tests/` directory and run:
```bash
python -m unittest discover tests
```
### **Verify Individual Tests**
To run a specific test file:
```bash
python tests/test_api.py
```
---
## Steps to Run Examples
1. Clone the repository:
```bash
git clone https://github.com/tirotir-ir/chatassist.git
cd chatassist
```
2. Create and fill the api_key.txt file with your OpenAI API key:
```bash
echo "your-openai-api-key" > api_key.txt
```
Replace your-openai-api-key with your actual API key.
This file is required for running the examples and communicating with the OpenAI API.
3. Navigate to the examples/ directory:
```bash
cd examples
```
4. Run an example script:
```bash
python 14_advanced_chatbot_gui.py
```
Replace 14_advanced_chatbot_gui.py with the desired example script from the examples/ directory.
---
## **Troubleshooting**
### **Common Issues**
- **API Key Not Found**:
- Ensure the `api_key.txt` file exists and contains a valid API key.
- **Module Not Found**:
- Verify the library is installed using `pip show chatassist`.
### **Debugging**
Enable detailed logging by adding:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```
---
## **License**
This project is licensed under the MIT License.
---
## **Contact and Support**
For questions or support, please raise an issue on the project repository or contact the maintainer.
Raw data
{
"_id": null,
"home_page": null,
"name": "chatassist",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "chatgpt, openai, api, assistant",
"author": "Daryoush Alipour",
"author_email": "Daryoush Alipour <ai.tirotir@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/77/c9/16815c2419e2bca099a0c624f3a02055087b1f3d6e490edcb29a5df24ac5/chatassist-0.1.0.tar.gz",
"platform": null,
"description": "\r\n# ChatAssist\r\n\r\nAn advanced Python library for handling ChatGPT interactions.\r\n\r\n---\r\n\r\n## **Features**\r\n\r\n- **Save and Resume Conversations**: Save conversation history to a file and reload it later.\r\n- **Proxy Support**: Send API requests through a user-defined proxy.\r\n- **Configurable Parameters**: Customize settings like `temperature`, `top_p`, and `max_tokens`.\r\n- **Stream Output**: Display responses incrementally as they are generated.\r\n- **Command-Line Interface**: Quickly interact with ChatGPT from the terminal.\r\n- **Graphical User Interface**: User-friendly GUI for non-technical users.\r\n- **Markdown Rendering in GUI**: Display formatted text and code blocks in responses.\r\n- **Built-in Logging**: Log all interactions for debugging or auditing purposes.\r\n- **Dynamic Model Selection**: Switch between models like GPT-3.5-Turbo or GPT-4.\r\n\r\n---\r\n\r\n## **Installation**\r\n\r\n### **From Source**\r\n\r\nInstall the library from the source code:\r\n\r\n```bash\r\npip install .\r\n```\r\n\r\nFor development mode:\r\n\r\n```bash\r\npip install -e .\r\n```\r\n\r\n### **Verify Installation**\r\n\r\nRun this command to verify:\r\n\r\n```bash\r\npython -c \"import chatassist; print(chatassist.__version__)\"\r\n```\r\n\r\nYou should see the version number printed.\r\n\r\n---\r\n\r\n## **Usage**\r\n\r\n### **Python API**\r\n\r\nThe `ChatAssist` library provides a simple API for interacting with ChatGPT.\r\n\r\n```python\r\nfrom chatassist.api import ChatGPTAPI\r\nfrom chatassist.utils import load_api_key\r\n\r\n# Load the API key\r\napi_key = load_api_key(\"api_key.txt\")\r\n\r\n# Initialize the ChatGPT API client\r\napi = ChatGPTAPI(api_key=api_key)\r\n\r\n# Send a message\r\nresponse = api.send_message(\"Hello, ChatGPT!\")\r\nprint(response)\r\n```\r\n\r\n### **Saving and Resuming Conversations**\r\n\r\nUse the `Conversation` class to manage chat histories:\r\n\r\n```python\r\nfrom chatassist.conversation import Conversation\r\n\r\nconversation = Conversation()\r\nconversation.add_message(\"user\", \"Hello!\")\r\nconversation.add_message(\"assistant\", \"Hi there! How can I assist you?\")\r\n\r\n# Save to a file\r\nconversation.save_to_file(\"conversation.json\")\r\n\r\n# Reload the conversation\r\nloaded_conversation = Conversation()\r\nloaded_conversation.load_from_file(\"conversation.json\")\r\nprint(loaded_conversation.get_history())\r\n```\r\n\r\n### **Using Proxies**\r\n\r\nPass a proxy configuration to route API requests through a proxy server:\r\n\r\n```python\r\napi = ChatGPTAPI(api_key=api_key, proxies={\"http\": \"http://proxy.example.com:8080\"})\r\nresponse = api.send_message(\"What is Python?\")\r\nprint(response)\r\n```\r\n\r\n---\r\n\r\n## **Command-Line Interface**\r\n\r\nThe CLI allows you to interact with ChatGPT directly from the terminal.\r\n\r\n### **Basic Usage**\r\n\r\n```bash\r\nchatassist-cli \"What is the capital of France?\" --api-key-path api_key.txt\r\n```\r\n\r\n### **Export Conversation**\r\n\r\nSave the conversation to a file:\r\n\r\n```bash\r\nchatassist-cli \"Tell me about Python.\" --export conversation.json\r\n```\r\n\r\n---\r\n\r\n## **Graphical User Interface**\r\n\r\nThe GUI provides an intuitive way to interact with ChatGPT.\r\n\r\n### **Launching the GUI**\r\n\r\nRun the following command:\r\n\r\n```bash\r\npython -m chatassist.gui\r\n```\r\n\r\n### **Features**\r\n\r\n1. **Type and Send Messages**:\r\n - Enter your message in the input field and press \"Send\".\r\n - Responses are displayed in the chat window.\r\n\r\n2. **Save and Load Conversations**:\r\n - Export the conversation to a file for later use.\r\n - Reload previous conversations using the \"Load Conversation\" option.\r\n\r\n---\r\n\r\n## **Configuration Parameters**\r\n\r\nThe `ChatAssist` API allows you to fine-tune interactions with the following parameters:\r\n\r\n- **`temperature`**: Controls the randomness of responses.\r\n- **`top_p`**: Limits responses to the top tokens in cumulative probability.\r\n- **`max_tokens`**: Restricts the number of tokens in the response.\r\n- **`model`**: Allows you to switch between models, e.g., `gpt-3.5-turbo` or `gpt-4`.\r\n\r\n```python\r\nresponse = api.send_message(\r\n \"Tell me about AI.\",\r\n temperature=0.5,\r\n top_p=0.8,\r\n max_tokens=500\r\n)\r\nprint(response)\r\n```\r\n\r\n---\r\n\r\n## **Practical Examples**\r\n\r\n### **1. Simple FAQ Bot**\r\n\r\n```python\r\nquestions = [\"What is Python?\", \"What is AI?\", \"Who created ChatGPT?\"]\r\nfor question in questions:\r\n response = api.send_message(question)\r\n print(f\"Q: {question}\r\nA: {response}\r\n\")\r\n```\r\n\r\n### **2. Programming Assistant**\r\n\r\n```python\r\nprompt = \"Explain the concept of recursion with a Python example.\"\r\nresponse = api.send_message(prompt)\r\nprint(response)\r\n```\r\n\r\n### **3. Travel Guide**\r\n\r\n```python\r\nprompt = \"What are the best tourist attractions in Paris?\"\r\nresponse = api.send_message(prompt)\r\nprint(response)\r\n```\r\n\r\n### **4. Math Solver**\r\n\r\n```python\r\nproblem = \"What is the result of 123 * 456?\"\r\nresponse = api.send_message(problem)\r\nprint(response)\r\n```\r\n\r\n### **5. Language Translator**\r\n\r\n```python\r\nprompt = \"Translate 'Hello, how are you?' into Spanish.\"\r\nresponse = api.send_message(prompt)\r\nprint(response)\r\n```\r\n\r\n---\r\n\r\n## **Testing**\r\n\r\n### **Run All Tests**\r\n\r\nNavigate to the `tests/` directory and run:\r\n\r\n```bash\r\npython -m unittest discover tests\r\n```\r\n\r\n### **Verify Individual Tests**\r\n\r\nTo run a specific test file:\r\n\r\n```bash\r\npython tests/test_api.py\r\n```\r\n\r\n---\r\n## Steps to Run Examples\r\n\r\n1. Clone the repository:\r\n```bash\r\ngit clone https://github.com/tirotir-ir/chatassist.git\r\ncd chatassist\r\n```\r\n2. Create and fill the api_key.txt file with your OpenAI API key:\r\n```bash\r\necho \"your-openai-api-key\" > api_key.txt\r\n```\r\nReplace your-openai-api-key with your actual API key. \r\nThis file is required for running the examples and communicating with the OpenAI API.\r\n\r\n3. Navigate to the examples/ directory:\r\n\r\n```bash\r\ncd examples\r\n```\r\n\u200d\u200d\u200d\u200d\u200d\u200d\u200d4. Run an example script:\r\n\u200d\u200d\u200d\r\n```bash\r\n python 14_advanced_chatbot_gui.py\r\n```\r\nReplace 14_advanced_chatbot_gui.py with the desired example script from the examples/ directory.\r\n---\r\n## **Troubleshooting**\r\n\r\n### **Common Issues**\r\n\r\n- **API Key Not Found**:\r\n - Ensure the `api_key.txt` file exists and contains a valid API key.\r\n- **Module Not Found**:\r\n - Verify the library is installed using `pip show chatassist`.\r\n\r\n### **Debugging**\r\n\r\nEnable detailed logging by adding:\r\n\r\n```python\r\nimport logging\r\nlogging.basicConfig(level=logging.DEBUG)\r\n```\r\n\r\n---\r\n\r\n## **License**\r\n\r\nThis project is licensed under the MIT License.\r\n\r\n---\r\n\r\n## **Contact and Support**\r\n\r\nFor questions or support, please raise an issue on the project repository or contact the maintainer.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library for interacting with OpenAI's ChatGPT API.",
"version": "0.1.0",
"project_urls": {
"BugTracker": "https://github.com/tirotir-ir/chatassist/issues",
"Documentation": "https://github.com/tirotir-ir/chatassist/wiki",
"Homepage": "https://github.com/tirotir-ir/chatassist",
"SourceCode": "https://github.com/tirotir-ir/chatassist"
},
"split_keywords": [
"chatgpt",
" openai",
" api",
" assistant"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "65fee9a9699e7916d0c504270191a228163fb1c3e011acbd4011f311a915b99f",
"md5": "e7208dad062e10d54a1507a59c0ae49d",
"sha256": "c58646542ca04a2616767ae09ffa5d23786b375d84af1e540cd0c5cf4e72c1d2"
},
"downloads": -1,
"filename": "chatassist-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e7208dad062e10d54a1507a59c0ae49d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9671,
"upload_time": "2024-12-27T15:44:20",
"upload_time_iso_8601": "2024-12-27T15:44:20.811621Z",
"url": "https://files.pythonhosted.org/packages/65/fe/e9a9699e7916d0c504270191a228163fb1c3e011acbd4011f311a915b99f/chatassist-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "77c916815c2419e2bca099a0c624f3a02055087b1f3d6e490edcb29a5df24ac5",
"md5": "0d14396c84a32d514c6265224e6ce7b0",
"sha256": "11e4b17c18884c8631f6688e5d13aa7b05acb9de28dcd56209e8e96398c1f744"
},
"downloads": -1,
"filename": "chatassist-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0d14396c84a32d514c6265224e6ce7b0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12280,
"upload_time": "2024-12-27T15:44:23",
"upload_time_iso_8601": "2024-12-27T15:44:23.650830Z",
"url": "https://files.pythonhosted.org/packages/77/c9/16815c2419e2bca099a0c624f3a02055087b1f3d6e490edcb29a5df24ac5/chatassist-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-27 15:44:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tirotir-ir",
"github_project": "chatassist",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": []
},
{
"name": "argparse",
"specs": []
},
{
"name": "tk",
"specs": []
},
{
"name": "openai",
"specs": []
}
],
"lcname": "chatassist"
}