Name | gradient-chat-client JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Unofficial Python client for Gradient Chat (supports gpt-oss-120b and qwen3-235b) |
upload_time | 2025-08-15 17:23:23 |
maintainer | None |
docs_url | None |
author | abswn |
requires_python | >=3.9 |
license | MIT License
Copyright (c) 2025 abswn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
gradient
gradient-api
gpt
qwen3
gpt-oss-120b
qwen3-235b
|
VCS |
 |
bugtrack_url |
|
requirements |
requests
fake-useragent
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# gradient-chat-python
Unofficial Python client for Gradient Chat which utilizes the decentralized inference network called **Parallax**. When using Gradient Chat (i.e Parallax), the inference load is distributed among multiple P2P devices.
*Note: Currently Parallax is in testing phase and has limited number of participating devices.*
## Features
* Maintain conversation context between requests.
* Optionally choose model, cluster mode and context size per request.
* GPT OSS 120B
* Qwen3 235B
* Support for reasoning output (`enableThinking`).
* Logging of all requests and responses (JSON + plain text).
## Installation
```bash
python3 -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
pip install gradient-chat-client
```
Or if you want to install the latest development version:
```bash
pip install git+https://github.com/abswn/gradient-chat-python.git
```
## Usage
```python
from gradient_chat import GradientChatClient, GradientChatError
# Create client
client = GradientChatClient()
# Show available models
print("Available Models:", client.available_models)
# Send a message
try:
response = client.generate(
user_message="Hi, Good morning!",
enableThinking=True
)
print("Model:", response["model"])
print("Reasoning:", response["reasoning"])
print("Reply:", response["reply"])
except GradientChatError as e:
print("Request failed:", e)
```
## API Reference
`GradientChatClient`
```python
GradientChatClient(
model="GPT OSS 120B", # GPT OSS 120B (default) or Qwen3 235B
cluster_mode="nvidia", # nvidia (default) or hybrid, Qwen3 supports only hyrbid
log_dir="logs",
timeout=None # default is 60 seconds
)
```
These parameters can also be set per request in the `generate` method.
`client.generate()`
```python
response = gradient_client.generate(
user_message, # required
context_size=5, # default is 15 and capped at a max of 50
model="GPT OSS 120B",
cluster_mode="nvidia",
enableThinking=True, # enables reasoning, False by default
timeout=100, # default timeout is 60 seconds
)
```
**OUTPUT:**
```python
{
"reply": str, # response to the user message
"reasoning": str, # reasoning used by the model
"model": str # model name
}
```
All parameters except `user_message` are optional. There is also a parameter called `conversation` of type `GradientConversation` which can be used to send custom conversation history as context.
```python
from gradient_chat import GradientConversation
custom_convo = GradientConversation(max_history=500)
custom_convo.add_user_message("Hi")
custom_convo.add_assistant_message("Hello!") # can also add reasoning text
custom_convo.add_user_message("How are you?")
custom_convo.add_assistant_message("I'm fine.")
client.generate("Hello", conversation=custom_convo)
```
Custom convo object can also be created directly as follows:
```python
custom_convo = [
{"role": "user", "content": "How are you?"},
{"role": "assistant", "content": "I'm fine.", "reasoningContent": "Responded with a polite, conventional reply to a common greeting to keep the conversation natural."},
# add more
]
client.generate(user_message, custom_convo)
```
`client.get_model_info()`
*(can also use client.available_models)*
```python
['GPT OSS 120B', 'Qwen3 235B']
```
`client.get_conversation()`
```python
[
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi there! How can I help you?", "reasoningContent": "Greeted the user."},
{"role": "user", "content": "Can you tell me a joke?"},
{"role": "assistant", "content": "Why don’t scientists trust atoms? Because they make up everything!"},
{"role": "user", "content": "Thanks! What's the weather like today?"},
{"role": "assistant", "content": "I cannot access real-time weather, but I recommend checking a local weather site.", "reasoningContent": "Explained limitations."}
]
```
## Error Handling
All fatal errors raise `GradientChatError`.
Catch this single exception to handle any request failure.
```python
from gradient_chat import GradientChatClient, GradientChatError
client = GradientChatClient()
try:
response = client.generate("Status update?")
print(response)
except GradientChatError as e:
msg = str(e)
if "Timeout" in msg:
print("Retrying with a higher timeout...")
client.generate("Status update?", timeout=120)
elif "Job Failed" in msg:
print("Switching to another model...")
client.generate("Status update?", model="Qwen3 235B")
else:
raise # Let other errors (such as HTTP error, Network error) propagate
```
| Failure Type | Cause | Suggested Action |
| -------------- | --------------------------------------------------------- | ----------------------------------------------- |
| Request Timeout | API took longer than timeout seconds. | Retry or increase timeout. |
| HTTP Error | API returned non-2xx status. | Retry or investigate payload. |
| Network Error | Connection issues, DNS failure, SSL errors, etc. | Check connection / proxy. |
| Job Failed | API responded but never sent `status == "completed"`. | Retry or switch to another model/cluster. |
Non fatal errors are logged via `warnings.warn()` and do not stop execution.
## Disclaimer
This project is a personal undertaking and is not an official Gradient product. It is not affiliated with Gradient in any way and should not be mistaken as such.
## License
MIT License
Raw data
{
"_id": null,
"home_page": null,
"name": "gradient-chat-client",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "gradient, gradient-api, gpt, qwen3, gpt-oss-120b, qwen3-235b",
"author": "abswn",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/fe/37/82fea3b1556f48aa2894223bbca0acee3fe7934b1c4e3296927ddc744584/gradient_chat_client-0.1.0.tar.gz",
"platform": null,
"description": "# gradient-chat-python\r\nUnofficial Python client for Gradient Chat which utilizes the decentralized inference network called **Parallax**. When using Gradient Chat (i.e Parallax), the inference load is distributed among multiple P2P devices.\r\n\r\n*Note: Currently Parallax is in testing phase and has limited number of participating devices.*\r\n\r\n## Features\r\n* Maintain conversation context between requests.\r\n* Optionally choose model, cluster mode and context size per request.\r\n * GPT OSS 120B\r\n * Qwen3 235B\r\n* Support for reasoning output (`enableThinking`).\r\n* Logging of all requests and responses (JSON + plain text).\r\n\r\n## Installation\r\n```bash\r\npython3 -m venv venv\r\nsource venv/bin/activate # Linux/macOS\r\nvenv\\Scripts\\activate # Windows\r\n\r\npip install gradient-chat-client\r\n```\r\nOr if you want to install the latest development version:\r\n```bash\r\npip install git+https://github.com/abswn/gradient-chat-python.git\r\n```\r\n\r\n## Usage\r\n```python\r\nfrom gradient_chat import GradientChatClient, GradientChatError\r\n\r\n# Create client\r\nclient = GradientChatClient()\r\n\r\n# Show available models\r\nprint(\"Available Models:\", client.available_models)\r\n\r\n# Send a message\r\ntry:\r\n response = client.generate(\r\n user_message=\"Hi, Good morning!\",\r\n enableThinking=True\r\n )\r\n print(\"Model:\", response[\"model\"])\r\n print(\"Reasoning:\", response[\"reasoning\"])\r\n print(\"Reply:\", response[\"reply\"])\r\n\r\nexcept GradientChatError as e:\r\n print(\"Request failed:\", e)\r\n```\r\n\r\n## API Reference\r\n`GradientChatClient`\r\n```python\r\nGradientChatClient(\r\n model=\"GPT OSS 120B\", # GPT OSS 120B (default) or Qwen3 235B\r\n cluster_mode=\"nvidia\", # nvidia (default) or hybrid, Qwen3 supports only hyrbid\r\n log_dir=\"logs\",\r\n timeout=None # default is 60 seconds\r\n)\r\n```\r\nThese parameters can also be set per request in the `generate` method.\r\n\r\n`client.generate()`\r\n```python\r\nresponse = gradient_client.generate(\r\n user_message, # required\r\n context_size=5, # default is 15 and capped at a max of 50\r\n model=\"GPT OSS 120B\",\r\n cluster_mode=\"nvidia\",\r\n enableThinking=True, # enables reasoning, False by default\r\n timeout=100, # default timeout is 60 seconds\r\n)\r\n```\r\n\r\n\r\n**OUTPUT:**\r\n```python\r\n{\r\n \"reply\": str, # response to the user message\r\n \"reasoning\": str, # reasoning used by the model\r\n \"model\": str # model name\r\n}\r\n```\r\n\r\nAll parameters except `user_message` are optional. There is also a parameter called `conversation` of type `GradientConversation` which can be used to send custom conversation history as context.\r\n```python\r\nfrom gradient_chat import GradientConversation\r\n\r\ncustom_convo = GradientConversation(max_history=500)\r\ncustom_convo.add_user_message(\"Hi\")\r\ncustom_convo.add_assistant_message(\"Hello!\") # can also add reasoning text\r\ncustom_convo.add_user_message(\"How are you?\")\r\ncustom_convo.add_assistant_message(\"I'm fine.\")\r\nclient.generate(\"Hello\", conversation=custom_convo)\r\n```\r\nCustom convo object can also be created directly as follows:\r\n```python\r\ncustom_convo = [\r\n {\"role\": \"user\", \"content\": \"How are you?\"},\r\n {\"role\": \"assistant\", \"content\": \"I'm fine.\", \"reasoningContent\": \"Responded with a polite, conventional reply to a common greeting to keep the conversation natural.\"},\r\n # add more\r\n]\r\nclient.generate(user_message, custom_convo)\r\n```\r\n\r\n`client.get_model_info()`\r\n*(can also use client.available_models)*\r\n```python\r\n['GPT OSS 120B', 'Qwen3 235B']\r\n```\r\n\r\n`client.get_conversation()`\r\n```python\r\n[\r\n {\"role\": \"user\", \"content\": \"Hello\"},\r\n {\"role\": \"assistant\", \"content\": \"Hi there! How can I help you?\", \"reasoningContent\": \"Greeted the user.\"},\r\n {\"role\": \"user\", \"content\": \"Can you tell me a joke?\"},\r\n {\"role\": \"assistant\", \"content\": \"Why don\u2019t scientists trust atoms? Because they make up everything!\"},\r\n {\"role\": \"user\", \"content\": \"Thanks! What's the weather like today?\"},\r\n {\"role\": \"assistant\", \"content\": \"I cannot access real-time weather, but I recommend checking a local weather site.\", \"reasoningContent\": \"Explained limitations.\"}\r\n]\r\n\r\n```\r\n## Error Handling\r\nAll fatal errors raise `GradientChatError`. \r\nCatch this single exception to handle any request failure.\r\n```python\r\nfrom gradient_chat import GradientChatClient, GradientChatError\r\n\r\nclient = GradientChatClient()\r\n\r\ntry:\r\n response = client.generate(\"Status update?\")\r\n print(response)\r\nexcept GradientChatError as e:\r\n msg = str(e)\r\n if \"Timeout\" in msg:\r\n print(\"Retrying with a higher timeout...\")\r\n client.generate(\"Status update?\", timeout=120)\r\n elif \"Job Failed\" in msg:\r\n print(\"Switching to another model...\")\r\n client.generate(\"Status update?\", model=\"Qwen3 235B\")\r\n else:\r\n raise # Let other errors (such as HTTP error, Network error) propagate\r\n```\r\n| Failure Type | Cause | Suggested Action |\r\n| -------------- | --------------------------------------------------------- | ----------------------------------------------- |\r\n| Request Timeout | API took longer than timeout seconds. | Retry or increase timeout. |\r\n| HTTP Error | API returned non-2xx status. | Retry or investigate payload. |\r\n| Network Error | Connection issues, DNS failure, SSL errors, etc. | Check connection / proxy. |\r\n| Job Failed | API responded but never sent `status == \"completed\"`. | Retry or switch to another model/cluster. |\r\n\r\nNon fatal errors are logged via `warnings.warn()` and do not stop execution.\r\n\r\n## Disclaimer\r\nThis project is a personal undertaking and is not an official Gradient product. It is not affiliated with Gradient in any way and should not be mistaken as such.\r\n\r\n## License\r\nMIT License\r\n",
"bugtrack_url": null,
"license": "MIT License\r\n \r\n Copyright (c) 2025 abswn\r\n \r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n \r\n The above copyright notice and this permission notice shall be included in all\r\n copies or substantial portions of the Software.\r\n \r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n SOFTWARE.\r\n ",
"summary": "Unofficial Python client for Gradient Chat (supports gpt-oss-120b and qwen3-235b)",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/abswn/gradient-chat-python"
},
"split_keywords": [
"gradient",
" gradient-api",
" gpt",
" qwen3",
" gpt-oss-120b",
" qwen3-235b"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "01b157daa96324c0abecaf78b97608a831af65097c18581d50ea8c7709dc37f2",
"md5": "f1234fbe6894d0c3db505e6521f52483",
"sha256": "7b0ce21d1f6691139d9737d24f7cf14fefe595c9697ed0658afc0d7fb5cfd638"
},
"downloads": -1,
"filename": "gradient_chat_client-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f1234fbe6894d0c3db505e6521f52483",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 9933,
"upload_time": "2025-08-15T17:23:22",
"upload_time_iso_8601": "2025-08-15T17:23:22.294696Z",
"url": "https://files.pythonhosted.org/packages/01/b1/57daa96324c0abecaf78b97608a831af65097c18581d50ea8c7709dc37f2/gradient_chat_client-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "fe3782fea3b1556f48aa2894223bbca0acee3fe7934b1c4e3296927ddc744584",
"md5": "58769ed6dfa0c8a5322d07c88239884e",
"sha256": "74d45afcb263b1d298e45f2e835810414a6e5da151087cd7843258e610d196bf"
},
"downloads": -1,
"filename": "gradient_chat_client-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "58769ed6dfa0c8a5322d07c88239884e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 14884,
"upload_time": "2025-08-15T17:23:23",
"upload_time_iso_8601": "2025-08-15T17:23:23.418407Z",
"url": "https://files.pythonhosted.org/packages/fe/37/82fea3b1556f48aa2894223bbca0acee3fe7934b1c4e3296927ddc744584/gradient_chat_client-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-15 17:23:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "abswn",
"github_project": "gradient-chat-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": []
},
{
"name": "fake-useragent",
"specs": []
}
],
"lcname": "gradient-chat-client"
}