nix-gpt-client


Namenix-gpt-client JSON
Version 0.1.6 PyPI version JSON
download
home_pageNone
SummaryA Python library for easy interaction with the GPT API, featuring typed requests and responses.
upload_time2024-05-28 10:57:09
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/be/54/7101d40834c9337199b660f0a199886d71871dbadf92bae115a990a4a030/nix_gpt_client-0.1.6.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.6",
    "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": "f2e911f0e70d1c7ddede67b2b327bc5b02c6758becf600884d7531b6cc19089c",
                "md5": "e29f51a28ae8470a564efdd98ccdba9d",
                "sha256": "407025a892c157fdf84cfa765359375ed1e9bdeb44b5fea0145dee312d5f6b9a"
            },
            "downloads": -1,
            "filename": "nix_gpt_client-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e29f51a28ae8470a564efdd98ccdba9d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 5848,
            "upload_time": "2024-05-28T10:57:07",
            "upload_time_iso_8601": "2024-05-28T10:57:07.455484Z",
            "url": "https://files.pythonhosted.org/packages/f2/e9/11f0e70d1c7ddede67b2b327bc5b02c6758becf600884d7531b6cc19089c/nix_gpt_client-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be547101d40834c9337199b660f0a199886d71871dbadf92bae115a990a4a030",
                "md5": "28fc04e0dc551df38acb7c8a32e72135",
                "sha256": "a2d6c87dc4b8fc633579f3454289e73aae87b8c76647eeb9743f15e634cc78ee"
            },
            "downloads": -1,
            "filename": "nix_gpt_client-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "28fc04e0dc551df38acb7c8a32e72135",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 5315,
            "upload_time": "2024-05-28T10:57:09",
            "upload_time_iso_8601": "2024-05-28T10:57:09.060646Z",
            "url": "https://files.pythonhosted.org/packages/be/54/7101d40834c9337199b660f0a199886d71871dbadf92bae115a990a4a030/nix_gpt_client-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-28 10:57:09",
    "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: 3.35508s