nix-gpt-client


Namenix-gpt-client JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryA Python library for easy interaction with the GPT API, featuring typed requests and responses.
upload_time2024-05-17 12:43:58
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords openai gpt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # nix-gpt-client

nix-gpt-client is a simple Python library for working with the GPT API. It uses Pydantic to add input and output
schemas, allowing you to manage data structures with ease.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Installation

To install `nix-gpt-client`, you can use `pip`. Python 3.11 or higher is required.

```bash
pip install nix-gpt-client
```

## Usage

1. If you want to use typing, create Pydantic schemas for input and output data structures:

```python
from datetime import datetime
from pydantic import BaseModel, Field


class GPTInput(BaseModel):
    time: datetime = Field(description="The current time")
    timezone: str = Field(description="The timezone of the current time")
    target_timezone: str = Field(description="The target timezone")


class GPTOutput(BaseModel):
    target_time: datetime = Field(description="The target time")
```

2. Then create GPTClient object, set schemas, and add system message:

```python
from nix.gptclient import GPTClient, GPTModel, GPTMessageRole, GPTSchemaType

gpt_client = GPTClient(
    model=GPTModel.GPT_3_5_TURBO,
    top_p=0.5,
    presence_penalty=0,
    frequency_penalty=0,
    temperature=0)

gpt_client.set_schema(GPTInput, GPTSchemaType.input)
gpt_client.set_schema(GPTOutput, GPTSchemaType.output)

gpt_client.add_message(GPTMessageRole.system, """
Take from \'Input JSON schema\' the fields 'time', 'timezone', and 'target_timezone'.
Then generate an Output JSON schema with the field 'target_time', which represents the given 'time' converted 
from 'timezone' to 'target_timezone'.
""")
```

3. Add data like user message and call `run` method to get the response:

```python
input_data = {
    "time": datetime.now().__str__(),
    "timezone": "UTC",
    "target_timezone": "America/New_York"
}

gpt_client.add_message(GPTMessageRole.user, input_data)

response = json.loads(gpt_client.run())
```

4. The response will be:

```json
{
  "target_time": "2024-05-06T13:04:38.621713-04:00"
}
```

Full example:

```python
import json
from datetime import datetime
from dotenv import load_dotenv
from pydantic import BaseModel, Field
from src import GPTClient, GPTModel, GPTMessageRole, GPTSchemaType

load_dotenv()


class GPTInput(BaseModel):
    time: datetime = Field(description="The current time")
    timezone: str = Field(description="The timezone of the current time")
    target_timezone: str = Field(description="The target timezone")


class GPTOutput(BaseModel):
    target_time: datetime = Field(description="The target time")


gpt_client = GPTClient(
    model=GPTModel.GPT_3_5_TURBO,
    top_p=0.5,
    presence_penalty=0,
    frequency_penalty=0,
    temperature=0)

gpt_client.set_schema(GPTInput, GPTSchemaType.input)
gpt_client.set_schema(GPTOutput, GPTSchemaType.output)

gpt_client.add_message(GPTMessageRole.system, """
Take from \'Input JSON schema\' the fields 'time', 'timezone', and 'target_timezone'.
Then generate an Output JSON schema with the field 'target_time', which represents the given 'time' converted 
from 'timezone' to 'target_timezone'.
""")

input_data = {
    "time": datetime.now().__str__(),
    "timezone": "UTC",
    "target_timezone": "America/New_York"
}

gpt_client.add_message(GPTMessageRole.user, input_data)

response = json.loads(gpt_client.run())

print(response)
```

## License

This project is licensed under the MIT License. See the LICENSE file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nix-gpt-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "nks_nix <nikusunix@gmail.com>",
    "keywords": "openai, gpt",
    "author": null,
    "author_email": "nks_nix <nikusunix@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/db/67/eed85fb6203a6c6bf0a1c68daecc4c1ea319d0a377c4047562231718812c/nix_gpt_client-0.1.2.tar.gz",
    "platform": null,
    "description": "# nix-gpt-client\n\nnix-gpt-client is a simple Python library for working with the GPT API. It uses Pydantic to add input and output\nschemas, allowing you to manage data structures with ease.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [License](#license)\n\n## Installation\n\nTo install `nix-gpt-client`, you can use `pip`. Python 3.11 or higher is required.\n\n```bash\npip install nix-gpt-client\n```\n\n## Usage\n\n1. If you want to use typing, create Pydantic schemas for input and output data structures:\n\n```python\nfrom datetime import datetime\nfrom pydantic import BaseModel, Field\n\n\nclass GPTInput(BaseModel):\n    time: datetime = Field(description=\"The current time\")\n    timezone: str = Field(description=\"The timezone of the current time\")\n    target_timezone: str = Field(description=\"The target timezone\")\n\n\nclass GPTOutput(BaseModel):\n    target_time: datetime = Field(description=\"The target time\")\n```\n\n2. Then create GPTClient object, set schemas, and add system message:\n\n```python\nfrom nix.gptclient import GPTClient, GPTModel, GPTMessageRole, GPTSchemaType\n\ngpt_client = GPTClient(\n    model=GPTModel.GPT_3_5_TURBO,\n    top_p=0.5,\n    presence_penalty=0,\n    frequency_penalty=0,\n    temperature=0)\n\ngpt_client.set_schema(GPTInput, GPTSchemaType.input)\ngpt_client.set_schema(GPTOutput, GPTSchemaType.output)\n\ngpt_client.add_message(GPTMessageRole.system, \"\"\"\nTake from \\'Input JSON schema\\' the fields 'time', 'timezone', and 'target_timezone'.\nThen generate an Output JSON schema with the field 'target_time', which represents the given 'time' converted \nfrom 'timezone' to 'target_timezone'.\n\"\"\")\n```\n\n3. Add data like user message and call `run` method to get the response:\n\n```python\ninput_data = {\n    \"time\": datetime.now().__str__(),\n    \"timezone\": \"UTC\",\n    \"target_timezone\": \"America/New_York\"\n}\n\ngpt_client.add_message(GPTMessageRole.user, input_data)\n\nresponse = json.loads(gpt_client.run())\n```\n\n4. The response will be:\n\n```json\n{\n  \"target_time\": \"2024-05-06T13:04:38.621713-04:00\"\n}\n```\n\nFull example:\n\n```python\nimport json\nfrom datetime import datetime\nfrom dotenv import load_dotenv\nfrom pydantic import BaseModel, Field\nfrom src import GPTClient, GPTModel, GPTMessageRole, GPTSchemaType\n\nload_dotenv()\n\n\nclass GPTInput(BaseModel):\n    time: datetime = Field(description=\"The current time\")\n    timezone: str = Field(description=\"The timezone of the current time\")\n    target_timezone: str = Field(description=\"The target timezone\")\n\n\nclass GPTOutput(BaseModel):\n    target_time: datetime = Field(description=\"The target time\")\n\n\ngpt_client = GPTClient(\n    model=GPTModel.GPT_3_5_TURBO,\n    top_p=0.5,\n    presence_penalty=0,\n    frequency_penalty=0,\n    temperature=0)\n\ngpt_client.set_schema(GPTInput, GPTSchemaType.input)\ngpt_client.set_schema(GPTOutput, GPTSchemaType.output)\n\ngpt_client.add_message(GPTMessageRole.system, \"\"\"\nTake from \\'Input JSON schema\\' the fields 'time', 'timezone', and 'target_timezone'.\nThen generate an Output JSON schema with the field 'target_time', which represents the given 'time' converted \nfrom 'timezone' to 'target_timezone'.\n\"\"\")\n\ninput_data = {\n    \"time\": datetime.now().__str__(),\n    \"timezone\": \"UTC\",\n    \"target_timezone\": \"America/New_York\"\n}\n\ngpt_client.add_message(GPTMessageRole.user, input_data)\n\nresponse = json.loads(gpt_client.run())\n\nprint(response)\n```\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for more details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library for easy interaction with the GPT API, featuring typed requests and responses.",
    "version": "0.1.2",
    "project_urls": {
        "Changelog": "https://github.com/nixnks/nix-gpt-client/CHANGELOG.md",
        "Documentation": "https://readthedocs.org",
        "Homepage": "https://github.com/nixnks/nix-gpt-client",
        "Repository": "https://github.com/nixnks/nix-gpt-client.git"
    },
    "split_keywords": [
        "openai",
        " gpt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6c31e7e6fe6fdd95e30576ab69f0cd01ef1d21a247dfd554db939e24875baac",
                "md5": "6451e1a52fdbca781649a540c68c5e25",
                "sha256": "e3f228fac7e069a8da398ca54e8a3586dae50f5fd3db4b34b883ff8dcc9c6f77"
            },
            "downloads": -1,
            "filename": "nix_gpt_client-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6451e1a52fdbca781649a540c68c5e25",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 5295,
            "upload_time": "2024-05-17T12:43:55",
            "upload_time_iso_8601": "2024-05-17T12:43:55.761843Z",
            "url": "https://files.pythonhosted.org/packages/a6/c3/1e7e6fe6fdd95e30576ab69f0cd01ef1d21a247dfd554db939e24875baac/nix_gpt_client-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db67eed85fb6203a6c6bf0a1c68daecc4c1ea319d0a377c4047562231718812c",
                "md5": "94dfb2d05b73c6a797ca494d433ca7dd",
                "sha256": "fb478b1209ff63d080ba013c05f81f3e589d79ea9e34ea2448d6919f7cb30405"
            },
            "downloads": -1,
            "filename": "nix_gpt_client-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "94dfb2d05b73c6a797ca494d433ca7dd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 4530,
            "upload_time": "2024-05-17T12:43:58",
            "upload_time_iso_8601": "2024-05-17T12:43:58.220646Z",
            "url": "https://files.pythonhosted.org/packages/db/67/eed85fb6203a6c6bf0a1c68daecc4c1ea319d0a377c4047562231718812c/nix_gpt_client-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 12:43:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nixnks",
    "github_project": "nix-gpt-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nix-gpt-client"
}
        
Elapsed time: 0.26726s