# Xinference Restful Client
Xinference provides a restful client for managing and accessing models programmatically.
## Install
```shell
pip install xinference-client
```
## Usage
```python
from xinference_client import RESTfulClient as Client
client = Client("http://localhost:9997")
model_uid = client.launch_model(model_name="chatglm2")
model = client.get_model(model_uid)
chat_history = []
prompt = "What is the largest animal?"
model.chat(
prompt,
chat_history=chat_history,
generate_config={"max_tokens": 1024}
)
```
Result:
```json
{
"id": "chatcmpl-8d76b65a-bad0-42ef-912d-4a0533d90d61",
"model": "56f69622-1e73-11ee-a3bd-9af9f16816c6",
"object": "chat.completion",
"created": 1688919187,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The largest animal that has been scientifically measured is the blue whale, which has a maximum length of around 23 meters (75 feet) for adult animals and can weigh up to 150,000 pounds (68,000 kg). However, it is important to note that this is just an estimate and that the largest animal known to science may be larger still. Some scientists believe that the largest animals may not have a clear \"size\" in the same way that humans do, as their size can vary depending on the environment and the stage of their life."
},
"finish_reason": "None"
}
],
"usage": {
"prompt_tokens": -1,
"completion_tokens": -1,
"total_tokens": -1
}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/xorbitsai/inference-client",
"name": "xinference-client",
"maintainer": "Qin Xuye",
"docs_url": null,
"requires_python": null,
"maintainer_email": "qinxuye@xprobe.io",
"keywords": null,
"author": "Qin Xuye",
"author_email": "qinxuye@xprobe.io",
"download_url": "https://files.pythonhosted.org/packages/24/c8/0bbe1050422103290392f0b02be681febdbf7799a88dc940471f8de3a8cb/xinference-client-1.0.1.tar.gz",
"platform": null,
"description": "# Xinference Restful Client\nXinference provides a restful client for managing and accessing models programmatically.\n\n## Install\n```shell\npip install xinference-client\n```\n\n## Usage\n```python\nfrom xinference_client import RESTfulClient as Client\n\nclient = Client(\"http://localhost:9997\")\nmodel_uid = client.launch_model(model_name=\"chatglm2\")\nmodel = client.get_model(model_uid)\n\nchat_history = []\nprompt = \"What is the largest animal?\"\nmodel.chat(\n prompt,\n chat_history=chat_history,\n generate_config={\"max_tokens\": 1024}\n)\n```\nResult:\n```json\n{\n \"id\": \"chatcmpl-8d76b65a-bad0-42ef-912d-4a0533d90d61\",\n \"model\": \"56f69622-1e73-11ee-a3bd-9af9f16816c6\",\n \"object\": \"chat.completion\",\n \"created\": 1688919187,\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"The largest animal that has been scientifically measured is the blue whale, which has a maximum length of around 23 meters (75 feet) for adult animals and can weigh up to 150,000 pounds (68,000 kg). However, it is important to note that this is just an estimate and that the largest animal known to science may be larger still. Some scientists believe that the largest animals may not have a clear \\\"size\\\" in the same way that humans do, as their size can vary depending on the environment and the stage of their life.\"\n },\n \"finish_reason\": \"None\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": -1,\n \"completion_tokens\": -1,\n \"total_tokens\": -1\n }\n}\n```\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Client for Xinference",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/xorbitsai/inference-client"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a1cd4be23a82847a41734c550d947ba406ccff45eb5e1a89ec76ddd535b44119",
"md5": "3365bb52dac4974cda4de1fb51fd67b1",
"sha256": "5ccfcc9df1f3c8e612572cb9f3a83f2157517ef1811cc7eedd7847e98c030479"
},
"downloads": -1,
"filename": "xinference_client-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3365bb52dac4974cda4de1fb51fd67b1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 25552,
"upload_time": "2024-11-29T09:11:12",
"upload_time_iso_8601": "2024-11-29T09:11:12.952323Z",
"url": "https://files.pythonhosted.org/packages/a1/cd/4be23a82847a41734c550d947ba406ccff45eb5e1a89ec76ddd535b44119/xinference_client-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "24c80bbe1050422103290392f0b02be681febdbf7799a88dc940471f8de3a8cb",
"md5": "b1e0d29c055173008c305b019afc610f",
"sha256": "5d19922e66287b1b945eeb5b604c8c48c7134d106c7e592fd02034433c10d673"
},
"downloads": -1,
"filename": "xinference-client-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b1e0d29c055173008c305b019afc610f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 44650,
"upload_time": "2024-11-29T09:11:19",
"upload_time_iso_8601": "2024-11-29T09:11:19.929992Z",
"url": "https://files.pythonhosted.org/packages/24/c8/0bbe1050422103290392f0b02be681febdbf7799a88dc940471f8de3a8cb/xinference-client-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-29 09:11:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xorbitsai",
"github_project": "inference-client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "xinference-client"
}