# TransformGPT
TransformGPT is a python library for interpreting unstructured (or structured) data into Python objects using ChatGPT. Given a Python class hierarchy, it can take arbitrary data and structure in into the class hierarchy as a series of objects. This is useful for convertung natural language into structured data, or for converting one data type into another without specifying the mapping schema.
## Installation:
```
pip install transformgpt
```
### Optional:
Set an environment variable called ```OpenAIAPI-Token``` to your OpenAI API token.
## Command line:
```
usage: transformgpt [-h]
[-k KEY]
[-m MODEL]
[-t TEMPERATURE]
description
```
KEY: OpenAI API Token if it's not set as an environment variable.
MODEL: OpenAI Model, defaults to 'gpt-3.5-turbo'
TEMPERATURE: Temperature for the ChatCompletion, defaults to 0, increase towards 1 to make the answers more creative
Description: A description of how you want the data to be transformed.
Takes input from STDIN and returns on STDOUT the transformed data.
### Example:
```
> echo "Hello World.\nHow are you today?\nI am fine.\nIf you don't respond I will blackmail you." | transformgpt "An object with the fields original_message, intent, and response, where intent is one of greeting, inquiry, response, threat, informative."
```
#### Yields:
```yaml
- original_message: "Hello World."
intent: greeting
response: "Hi there!"
- original_message: "How are you today?"
intent: inquiry
response: "I'm doing well, thank you. How about
you?"
- original_message: "I am fine."
intent: response
response: "Glad to hear that!"
- original_message: "If you don't respond I will blackmail you."
intent: threat
response: "I'm sorry, I didn't mean to ignore you. Is there something you need help with?"
```
### Python usage:
```python
import transformgpt
import openai
import os
openai.api_key = "YOUR OPENAI TOKEN"
transformer = transformgpt.TransformGPT(openai.ChatCompletion)
class Message:
def __init__(self, message: str, data : dict[str, str]):
self.message = message
self.data = data
incoming_message = "The message is tell Joey Tracy is cheating on him with maid. The data to include is Orange is the new black, and the only way to get the job done is to do it yourself."
print(transformer.transform_string(incoming_message, Message))
```
#### Yields:
```
Message(message="Tell Joey Tracy is cheating on him with the maid.", data={"Orange": "The new black.", "The only way to get the job done": "Do it yourself."})
```
### Datalasses/Nested Structures
It handles @dataclasses, and nested class hierarcharies as well:
```python
from __future__ import annotations
from dataclasses import dataclass
import dataclasses
from typing import List, Optional
import openai
import os
import transformgpt
import yaml
openai.api_key = "YOUR OPENAI TOKEN"
transformer = transformgpt.TransformGPT(openai.ChatCompletion)
@dataclass
class MessageClassification:
original_message:str
message_part:str
intent:Optional[str] = None
categories:List[str] = dataclasses.field(default_factory=list)
parameters:List[str] = dataclasses.field(default_factory=list)
reply:Optional[str] = None
justifications_for_reply:List[Justification] = dataclasses.field(default_factory=list)
follow_up_items:List[MessageClassification] = dataclasses.field(default_factory=list)
@dataclass
class Justification:
subject:Optional[str] = None
object:Optional[str] = None
intent:Optional[str] = None
action:Optional[str] = None
description:Optional[str] = None
incoming_message = "The message is tell Joey Tracy is cheating on him with maid. The data to include is Orange is the new black, and the only way to get the job done is to do it yourself."
print(yaml.dump(transformer.transform_string(incoming_message, MessageClassification)))
```
#### Yields:
```
- !!python/object:__main__.MessageClassification
categories:
- Relationships
- Infidelity
follow_up_items:
- !!python/object:__main__.MessageClassification
categories:
- Entertainment
- Motivation
follow_up_items: []
intent: null
justifications_for_reply:
- !!python/object:__main__.Justification
action: null
description: Orange is the new black is a popular TV show.
intent: null
object: null
subject: null
- !!python/object:__main__.Justification
action: null
description: Doing it yourself is the best way to ensure it gets done right.
intent: null
object: null
subject: null
message_part: The data to include is Orange is the new black, and the only way
to get the job done is to do it yourself.
original_message: The data to include is Orange is the new black, and the only
way to get the job done is to do it yourself.
parameters: []
reply: null
intent: null
justifications_for_reply:
- !!python/object:__main__.Justification
action: null
description: null
intent: Cheating
object: Joey
subject: Tracy
- !!python/object:__main__.Justification
action: Involved in cheating
description: null
intent: null
object: null
subject: Maid
message_part: Tell Joey Tracy is cheating on him with maid.
original_message: The message is tell Joey Tracy is cheating on him with maid.
parameters: []
reply: null
```
### It also supports transforming one object into another:
```python
result = transformer.transform_object(myListOfObjects, MyDataTypeToTransformInto) #Returns a list[MyDataTypeToTransformInto]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/TSavo/transformgpt",
"name": "transformgpt",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "openai gpt3 chatgpt nlp chatbot transformers structruing text",
"author": "T Savo",
"author_email": "evilgenius@nefariousplan.com",
"download_url": "https://files.pythonhosted.org/packages/aa/c0/8185e542b709207f2b62dc8e346f737d0a37b9f901525424cf58497069de/transformgpt-0.1.3.tar.gz",
"platform": null,
"description": "# TransformGPT\n\nTransformGPT is a python library for interpreting unstructured (or structured) data into Python objects using ChatGPT. Given a Python class hierarchy, it can take arbitrary data and structure in into the class hierarchy as a series of objects. This is useful for convertung natural language into structured data, or for converting one data type into another without specifying the mapping schema.\n\n## Installation:\n\n```\npip install transformgpt\n```\n\n### Optional:\nSet an environment variable called ```OpenAIAPI-Token``` to your OpenAI API token.\n\n## Command line:\n```\nusage: transformgpt [-h]\n [-k KEY]\n [-m MODEL]\n [-t TEMPERATURE]\n description\n```\n\nKEY: OpenAI API Token if it's not set as an environment variable.\n\nMODEL: OpenAI Model, defaults to 'gpt-3.5-turbo'\n\nTEMPERATURE: Temperature for the ChatCompletion, defaults to 0, increase towards 1 to make the answers more creative\n\nDescription: A description of how you want the data to be transformed.\n\nTakes input from STDIN and returns on STDOUT the transformed data.\n\n### Example:\n```\n> echo \"Hello World.\\nHow are you today?\\nI am fine.\\nIf you don't respond I will blackmail you.\" | transformgpt \"An object with the fields original_message, intent, and response, where intent is one of greeting, inquiry, response, threat, informative.\" \n```\n\n#### Yields:\n```yaml\n- original_message: \"Hello World.\"\n intent: greeting\n response: \"Hi there!\"\n\n- original_message: \"How are you today?\"\n intent: inquiry\n response: \"I'm doing well, thank you. How about \nyou?\"\n\n- original_message: \"I am fine.\"\n intent: response\n response: \"Glad to hear that!\"\n\n- original_message: \"If you don't respond I will blackmail you.\"\n intent: threat\n response: \"I'm sorry, I didn't mean to ignore you. Is there something you need help with?\"\n```\n\n### Python usage:\n\n```python\nimport transformgpt\nimport openai\nimport os\n\nopenai.api_key = \"YOUR OPENAI TOKEN\"\ntransformer = transformgpt.TransformGPT(openai.ChatCompletion)\n\nclass Message:\n def __init__(self, message: str, data : dict[str, str]):\n self.message = message\n self.data = data\n\nincoming_message = \"The message is tell Joey Tracy is cheating on him with maid. The data to include is Orange is the new black, and the only way to get the job done is to do it yourself.\"\n\nprint(transformer.transform_string(incoming_message, Message))\n```\n\n#### Yields:\n```\nMessage(message=\"Tell Joey Tracy is cheating on him with the maid.\", data={\"Orange\": \"The new black.\", \"The only way to get the job done\": \"Do it yourself.\"})\n```\n\n### Datalasses/Nested Structures\n\nIt handles @dataclasses, and nested class hierarcharies as well:\n\n```python\nfrom __future__ import annotations\nfrom dataclasses import dataclass\nimport dataclasses\nfrom typing import List, Optional\nimport openai\nimport os\nimport transformgpt\nimport yaml\n\nopenai.api_key = \"YOUR OPENAI TOKEN\"\ntransformer = transformgpt.TransformGPT(openai.ChatCompletion)\n\n@dataclass\nclass MessageClassification:\n original_message:str\n message_part:str\n intent:Optional[str] = None\n categories:List[str] = dataclasses.field(default_factory=list)\n parameters:List[str] = dataclasses.field(default_factory=list)\n reply:Optional[str] = None\n justifications_for_reply:List[Justification] = dataclasses.field(default_factory=list)\n follow_up_items:List[MessageClassification] = dataclasses.field(default_factory=list)\n\n@dataclass\nclass Justification:\n subject:Optional[str] = None\n object:Optional[str] = None\n intent:Optional[str] = None\n action:Optional[str] = None\n description:Optional[str] = None\n\nincoming_message = \"The message is tell Joey Tracy is cheating on him with maid. The data to include is Orange is the new black, and the only way to get the job done is to do it yourself.\"\n\nprint(yaml.dump(transformer.transform_string(incoming_message, MessageClassification)))\n```\n\n#### Yields:\n\n```\n- !!python/object:__main__.MessageClassification\n categories:\n - Relationships\n - Infidelity\n follow_up_items:\n - !!python/object:__main__.MessageClassification\n categories:\n - Entertainment\n - Motivation\n follow_up_items: []\n intent: null\n justifications_for_reply:\n - !!python/object:__main__.Justification\n action: null\n description: Orange is the new black is a popular TV show.\n intent: null\n object: null\n subject: null\n - !!python/object:__main__.Justification\n action: null\n description: Doing it yourself is the best way to ensure it gets done right.\n intent: null\n object: null\n subject: null\n message_part: The data to include is Orange is the new black, and the only way\n to get the job done is to do it yourself.\n original_message: The data to include is Orange is the new black, and the only\n way to get the job done is to do it yourself.\n parameters: []\n reply: null\n intent: null\n justifications_for_reply:\n - !!python/object:__main__.Justification\n action: null\n description: null\n intent: Cheating\n object: Joey\n subject: Tracy\n - !!python/object:__main__.Justification\n action: Involved in cheating\n description: null\n intent: null\n object: null\n subject: Maid\n message_part: Tell Joey Tracy is cheating on him with maid.\n original_message: The message is tell Joey Tracy is cheating on him with maid.\n parameters: []\n reply: null\n```\n\n### It also supports transforming one object into another:\n\n```python\n\nresult = transformer.transform_object(myListOfObjects, MyDataTypeToTransformInto) #Returns a list[MyDataTypeToTransformInto]\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for transforming unstructured text into structured data without context/mappings using ChatGPT.",
"version": "0.1.3",
"project_urls": {
"Download": "https://github.com/tsavo/transformgpt/tarball/0.1.3",
"Homepage": "https://github.com/TSavo/transformgpt"
},
"split_keywords": [
"openai",
"gpt3",
"chatgpt",
"nlp",
"chatbot",
"transformers",
"structruing",
"text"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c49ccec6b6825e165d20502d5e5dab1ed13f7a295e60a8b49c8fbaef68409bb9",
"md5": "cba5803349f691f818b3433ea0127313",
"sha256": "7b388b220d3ec7ecbbc0b9baad3ccbee812620f13d981e3632c643ec84e95189"
},
"downloads": -1,
"filename": "transformgpt-0.1.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "cba5803349f691f818b3433ea0127313",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 10462,
"upload_time": "2023-05-08T00:02:55",
"upload_time_iso_8601": "2023-05-08T00:02:55.182031Z",
"url": "https://files.pythonhosted.org/packages/c4/9c/cec6b6825e165d20502d5e5dab1ed13f7a295e60a8b49c8fbaef68409bb9/transformgpt-0.1.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aac08185e542b709207f2b62dc8e346f737d0a37b9f901525424cf58497069de",
"md5": "a053885d992c66fe5de18555a36fa141",
"sha256": "b3ef4708dcbed41af1cc95e61d8e752a8673c2da671f82d487b2f7826d17c5ca"
},
"downloads": -1,
"filename": "transformgpt-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "a053885d992c66fe5de18555a36fa141",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10138,
"upload_time": "2023-05-08T00:02:56",
"upload_time_iso_8601": "2023-05-08T00:02:56.707695Z",
"url": "https://files.pythonhosted.org/packages/aa/c0/8185e542b709207f2b62dc8e346f737d0a37b9f901525424cf58497069de/transformgpt-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-08 00:02:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TSavo",
"github_project": "transformgpt",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "transformgpt"
}