shasta-python


Nameshasta-python JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://krugle.ai/shasta
SummaryThe official Python client for Krugle Shasta.
upload_time2024-12-18 14:09:44
maintainerNone
docs_urlNone
authorJason
requires_python<4.0,>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Shasta Python Library

The Shasta Python library provides the easiest way to integrate Python 3.8+ projects with [Shasta](https://github.com/krugle2/shasta).

## Prerequisites

- Install Shasta and init with KrugleAI models

## Install

```sh
pip install shasta-python
```

## Usage

```python
from shasta_python import chat
from shasta_python import ChatResponse

response: ChatResponse = chat(model='llama3.2', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
print(response['message']['content'])
# or access fields directly from the response object
print(response.message.content)
```

See [_types.py](shasta/_types.py) for more information on the response types.

## Streaming responses

Response streaming can be enabled by setting `stream=True`.

```python
from shasta_python import chat

stream = chat(
    model='llama3.2',
    messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],
    stream=True,
)

for chunk in stream:
  print(chunk['message']['content'], end='', flush=True)
```

## Custom client
A custom client can be created by instantiating `Client` or `AsyncClient` from `shasta`.

All extra keyword arguments are passed into the [`httpx.Client`](https://www.python-httpx.org/api/#client).

```python
from shasta_python import Client
client = Client(
  host='http://localhost:5668',
  headers={'x-some-header': 'some-value'}
)
response = client.chat(model='llama3.2', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
```

## Async client

The `AsyncClient` class is used to make asynchronous requests. It can be configured with the same fields as the `Client` class.

```python
import asyncio
from shasta_python import AsyncClient

async def chat():
  message = {'role': 'user', 'content': 'Why is the sky blue?'}
  response = await AsyncClient().chat(model='llama3.2', messages=[message])

asyncio.run(chat())
```

Setting `stream=True` modifies functions to return a Python asynchronous generator:

```python
import asyncio
from shasta_python import AsyncClient

async def chat():
  message = {'role': 'user', 'content': 'Why is the sky blue?'}
  async for part in await AsyncClient().chat(model='llama3.2', messages=[message], stream=True):
    print(part['message']['content'], end='', flush=True)

asyncio.run(chat())
```

## API

The Shasta Python library's API is designed around the [Shasta REST API](https://github.com/krugle2/shasta/blob/main/docs/api.md)

### Chat

```python
shasta.chat(model='llama3.2', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])
```

### Generate

```python
shasta.generate(model='llama3.2', prompt='Why is the sky blue?')
```

### List

```python
shasta.list()
```

### Show

```python
shasta.show('llama3.2')
```

### Create

```python
modelfile='''
FROM llama3.2
SYSTEM You are mario from super mario bros.
'''

shasta.create(model='example', modelfile=modelfile)
```

### Copy

```python
shasta.copy('llama3.2', 'user/llama3.2')
```

### Delete

```python
shasta.delete('llama3.2')
```

### Embed

```python
shasta.embed(model='llama3.2', input='The sky is blue because of rayleigh scattering')
```

### Embed (batch)

```python
shasta.embed(model='llama3.2', input=['The sky is blue because of rayleigh scattering', 'Grass is green because of chlorophyll'])
```

### Ps

```python
shasta.ps()
```


## Errors

Errors are raised if requests return an error status or if an error is detected while streaming.

```python
model = 'does-not-yet-exist'

try:
  shasta.chat(model)
except shasta.ResponseError as e:
  print('Error:', e.error)
  if e.status_code == 404:
    shasta.pull(model)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://krugle.ai/shasta",
    "name": "shasta-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jason",
    "author_email": "jason@aragoncg.com",
    "download_url": "https://files.pythonhosted.org/packages/8d/f5/9adff5f87bb7539073ea3ac357081c7e9f34a91b87ff218688eb83510c52/shasta_python-0.0.2.tar.gz",
    "platform": null,
    "description": "# Shasta Python Library\n\nThe Shasta Python library provides the easiest way to integrate Python 3.8+ projects with [Shasta](https://github.com/krugle2/shasta).\n\n## Prerequisites\n\n- Install Shasta and init with KrugleAI models\n\n## Install\n\n```sh\npip install shasta-python\n```\n\n## Usage\n\n```python\nfrom shasta_python import chat\nfrom shasta_python import ChatResponse\n\nresponse: ChatResponse = chat(model='llama3.2', messages=[\n  {\n    'role': 'user',\n    'content': 'Why is the sky blue?',\n  },\n])\nprint(response['message']['content'])\n# or access fields directly from the response object\nprint(response.message.content)\n```\n\nSee [_types.py](shasta/_types.py) for more information on the response types.\n\n## Streaming responses\n\nResponse streaming can be enabled by setting `stream=True`.\n\n```python\nfrom shasta_python import chat\n\nstream = chat(\n    model='llama3.2',\n    messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],\n    stream=True,\n)\n\nfor chunk in stream:\n  print(chunk['message']['content'], end='', flush=True)\n```\n\n## Custom client\nA custom client can be created by instantiating `Client` or `AsyncClient` from `shasta`.\n\nAll extra keyword arguments are passed into the [`httpx.Client`](https://www.python-httpx.org/api/#client).\n\n```python\nfrom shasta_python import Client\nclient = Client(\n  host='http://localhost:5668',\n  headers={'x-some-header': 'some-value'}\n)\nresponse = client.chat(model='llama3.2', messages=[\n  {\n    'role': 'user',\n    'content': 'Why is the sky blue?',\n  },\n])\n```\n\n## Async client\n\nThe `AsyncClient` class is used to make asynchronous requests. It can be configured with the same fields as the `Client` class.\n\n```python\nimport asyncio\nfrom shasta_python import AsyncClient\n\nasync def chat():\n  message = {'role': 'user', 'content': 'Why is the sky blue?'}\n  response = await AsyncClient().chat(model='llama3.2', messages=[message])\n\nasyncio.run(chat())\n```\n\nSetting `stream=True` modifies functions to return a Python asynchronous generator:\n\n```python\nimport asyncio\nfrom shasta_python import AsyncClient\n\nasync def chat():\n  message = {'role': 'user', 'content': 'Why is the sky blue?'}\n  async for part in await AsyncClient().chat(model='llama3.2', messages=[message], stream=True):\n    print(part['message']['content'], end='', flush=True)\n\nasyncio.run(chat())\n```\n\n## API\n\nThe Shasta Python library's API is designed around the [Shasta REST API](https://github.com/krugle2/shasta/blob/main/docs/api.md)\n\n### Chat\n\n```python\nshasta.chat(model='llama3.2', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])\n```\n\n### Generate\n\n```python\nshasta.generate(model='llama3.2', prompt='Why is the sky blue?')\n```\n\n### List\n\n```python\nshasta.list()\n```\n\n### Show\n\n```python\nshasta.show('llama3.2')\n```\n\n### Create\n\n```python\nmodelfile='''\nFROM llama3.2\nSYSTEM You are mario from super mario bros.\n'''\n\nshasta.create(model='example', modelfile=modelfile)\n```\n\n### Copy\n\n```python\nshasta.copy('llama3.2', 'user/llama3.2')\n```\n\n### Delete\n\n```python\nshasta.delete('llama3.2')\n```\n\n### Embed\n\n```python\nshasta.embed(model='llama3.2', input='The sky is blue because of rayleigh scattering')\n```\n\n### Embed (batch)\n\n```python\nshasta.embed(model='llama3.2', input=['The sky is blue because of rayleigh scattering', 'Grass is green because of chlorophyll'])\n```\n\n### Ps\n\n```python\nshasta.ps()\n```\n\n\n## Errors\n\nErrors are raised if requests return an error status or if an error is detected while streaming.\n\n```python\nmodel = 'does-not-yet-exist'\n\ntry:\n  shasta.chat(model)\nexcept shasta.ResponseError as e:\n  print('Error:', e.error)\n  if e.status_code == 404:\n    shasta.pull(model)\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "The official Python client for Krugle Shasta.",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://krugle.ai/shasta",
        "Repository": "https://github.com/krugle2/shasta-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c498ae553dc8a5b61d39096476c1dc3917de025a102886bd0a2b5e5e5f9ee2aa",
                "md5": "5687c71c6fdfa1d84d938d8dbcfb7b76",
                "sha256": "283f83621aa7dd0a00ff31604e6cc6b53486e8edf8b7e1ab01675d90c422c8b7"
            },
            "downloads": -1,
            "filename": "shasta_python-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5687c71c6fdfa1d84d938d8dbcfb7b76",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 12696,
            "upload_time": "2024-12-18T14:09:42",
            "upload_time_iso_8601": "2024-12-18T14:09:42.064684Z",
            "url": "https://files.pythonhosted.org/packages/c4/98/ae553dc8a5b61d39096476c1dc3917de025a102886bd0a2b5e5e5f9ee2aa/shasta_python-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8df59adff5f87bb7539073ea3ac357081c7e9f34a91b87ff218688eb83510c52",
                "md5": "baf642b3873124a84c4a60aca521c594",
                "sha256": "ea22e2d1a513c18d630415ab988fa520c417d3e5a0e6d707513d477c3b211b6c"
            },
            "downloads": -1,
            "filename": "shasta_python-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "baf642b3873124a84c4a60aca521c594",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 12510,
            "upload_time": "2024-12-18T14:09:44",
            "upload_time_iso_8601": "2024-12-18T14:09:44.695407Z",
            "url": "https://files.pythonhosted.org/packages/8d/f5/9adff5f87bb7539073ea3ac357081c7e9f34a91b87ff218688eb83510c52/shasta_python-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 14:09:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "krugle2",
    "github_project": "shasta-python",
    "github_not_found": true,
    "lcname": "shasta-python"
}
        
Elapsed time: 1.44220s